import pgzrun
WIDTH = 800
HEIGHT = 600
TITLE = '封印魔法球'
ball = Actor('魔法球', (100, 100))
boundary = Actor('结界', (WIDTH/2, HEIGHT/2))
# 创建Actor对象作为能量挡板,传入图片'能量挡板'和坐标(WIDTH/2, HEIGHT*4/5)
baffle = Actor('能量挡板', (WIDTH/2, HEIGHT*4/5))
# 定义变量score,用来存放游戏得分,初始值为0
score = 0
# 定义变量status,用来存放游戏状态,初始值为True
status = True
def draw():
# screen.clear()
screen.fill('midnightblue')
boundary.draw()
# 在窗口中坐标为(30, 30)的位置显示分数,文字颜色为红色,字号为50
screen.draw.text(str(score), (30, 30), color=(255, 0, 0), fontsize=50)
# 如果status为True
if status:
# 调用魔法球的draw()方法
ball.draw()
# 调用能量挡板的draw()方法
baffle.draw()
# 否则
else:
# 在窗口中坐标为(200, 250)的位置显示'Game Over',文字颜色为白色,字号为100
screen.draw.text('Game Over', (200, 250), color=(255, 255, 255), fontsize=100)
x_step = 6
y_step = 6
def update():
# 声明score、status为全局变量
global score, status, x_step, y_step
if ball.right > WIDTH - 30 or ball.left < 30:
x_step = -x_step
if ball.top < 30:
y_step = -y_step
# 如果魔法球和能量挡板发生碰撞
if ball.colliderect(baffle):
# 将y_step取反
y_step = -y_step
# 将score增加1
score += 1
# 如果魔法球的bottom属性大于HEIGHT-30
if ball.bottom > HEIGHT - 30:
# 给status赋值False
status = False
ball.x += x_step
ball.y += y_step
# 自定义事件(当鼠标移动)函数
def on_mouse_move(pos):
# 将鼠标的横坐标赋值给能量挡板的x属性
baffle.x = pos[0]
pgzrun.go()
python封印魔法球小游戏
191 浏览量
2023-09-10
12:47:51
上传
评论
收藏 59KB ZIP 举报
- 粉丝: 514
- 资源: 13
最新资源
- 过客软件园_1.1.apk
- boboav_night.apk
- 235486247769308自带键盘安卓海贼.apk
- 672536945416276wap.stuzn.com_1000_1137350andme_signed.apk
- 737836185360652wap.stuzn.com_1000_1642030hzw_n73d.apk
- JavaWeb阶段综合项目的接口文档
- 003 登录rsa+token 登录rsa+token(需改善 私钥不应该硬编码在类中、密码应该存储为哈希值)
- 992475461755466幼稚园春游功能版.apk
- spark编程基础实验三数据
- windows之mysql8+的配置文件my.ini
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈