其他分享
首页 > 其他分享> > Pygame _来回弹跳的小球

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()

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

 

标签:pgzrun,ball,小球,bounce,height,width,Pygame,弹跳,speed
来源: https://www.cnblogs.com/jane5946/p/15361892.html