Pygame _来回弹跳的小球

 

----------------------------------------------------------------------

import pgzrun

WIDTH = 600
HEIGHT = 400

speed_x = 2
speed_y = 2

ball_r =30

x=ball_r
y=HEIGHT/2


bounce_height= HEIGHT-ball_r
bounce_width = WIDTH - ball_r


def draw():
screen.fill((0,125,125))
screen.draw.filled_circle((x,y),ball_r,(220,100,100))

def update():
global x,y,speed_x,speed_y, ball_r,bounce_height,bounce_width

x = x + speed_x
y = y + speed_y

if x>= bounce_width or x<ball_r:
speed_x = -speed_x
sounds.crash.play()
if y >= bounce_height or y<= ball_r:
speed_y = -speed_y
sounds.crash.play()
pgzrun.go()

--------------------------------------------------------------------------

Pygame _来回弹跳的小球

 

上一篇:Unity实现打飞碟小游戏


下一篇:【平衡小车制作】(八)蓝牙遥控及平衡成果展示(超详解)