用户:AngelaPeffiro查看:0 回复:0 评论:0 创建时间:2021-01-02T19:35:35
【作品展示】

【作品介绍】
aaaaaaaaaaaaaaaaaaaaaa
【作品源代码】
import pgzrun
import random
WIDTH = 450
HEIGHT = 650
score =
# 设置皮球在 x、y 方向的移动速度
x_speed, y_speed = 5, -5
# 设置平板移动速度
move_speed = 6
# 设置游戏状态
game_state = 'start'
# 创建角色,设置初始位置
ball =
coin =
panel =
def draw():
global game_state
# 设置游戏开始画面
if game_state == :
screen.fill()
screen.draw.text(, (136, 260), fontsize=50)
screen.draw.text(, (132, 310),
fontsize=30)
# 按空格键切换游戏状态
if keyboard.space:
game_state =
# 游戏进行中,显示得分和角色
elif game_state == :
screen.fill()
screen.draw.text(, (10, 10),
fontsize=30)
panel.draw()
ball.draw()
coin.draw()
# 游戏结束,显示结束画面
else:
screen.fill()
c
screen.draw.text(, (136, 260),
color=, fontsize=50)
screen.draw.text( ,
(140, 310), fontsize=40)
def update():
global game_state, score, x_speed, y_speed
if game_state == 'play':
# 皮球移动
ball.x
ball.y
# 皮球碰到左边缘或右边缘反弹
if ball.x < 25 or ball.x > WIDTH - 25:
x_speed = - x_speed
ball.x += x_speed
if ball.y < 25:
y_speed
ball.y
# 皮球碰到下边缘,游戏结束
elif ball.y > HEIGHT - 30:
game_state =
# WSAD 键控制平板上下左右移动
if keyboard.a:
panel.x -= move_speed
elif
elif
elif
# 皮球碰到平板反弹
if
y_speed =
# 皮球碰到金币,得分 +1,金币移到随机位置
if coin.:
score
coin.x = random.randint(30, WIDTH - 30)
coin.y = random.randint(30, HEIGHT / 2)
pgzrun.go()
【提示】
部分含有Python第三方库相关内容的作品,在海龟编辑器网页端无法运行哦!如遇到这种情况,可以打开下面的链接,下载海龟编辑器客户端:
https://python.codemao.cn