用户:
司乘查看:0 回复:0 评论:0 创建时间:2022-10-01T21:54:21
【作品展示】

【作品介绍】
这个还有许多不完美的地方,请朋友们来修改一下吧!
【作品源代码】
import pgzrun
WIDTH = 400
HEIGHT = 600
score = 0
ball_x, ball_y = 220, 300
x_speed, y_speed = 6,-6
pannel = Rect(200, 500, 80, 10)
def draw():
screen.fill('lightblue')
screen.draw.filled_circle((ball_x, ball_y), 17, 'green')
screen.draw.filled_rect(pannel,'brown')
screen.draw.text('score :' + str(score),(300, 10),
color='orange', fontsize=30)
def update():
global ball_x, ball_y, x_speed, y_speed, score
ball_x += x_speed
ball_y += y_speed
if ball_x < 16 or ball_x > 384:
x_speed = -x_speed
if ball_y < 16 or ball_y > 584:
y_speed = -y_speed
# 按键A、D控制平板左右移动
if keyboard.a: #若按键A按下
pannel.x -= 5 #平板x坐标减少5
elif keyboard.d:
pannel.x += 5
# 平板和弹球碰撞检测,如果一行代码太长,可用斜线分割
if ball_x - pannel.x >= 0 and ball_x -pannel.x <= 80 \
and pannel.y - ball_y <= 16 and pannel.y - ball_y >= 0:
y_speed = -y_speed
pgzrun.go()
【提示】
部分含有Python第三方库相关内容的作品,在海龟编辑器网页端无法运行哦!如遇到这种情况,可以打开下面的链接,下载海龟编辑器客户端:
https://python.codemao.cn