用户:
急躁的乌力力wXiI查看:0 回复:0 评论:0 创建时间:2023-01-17T13:27:57
【作品展示】

【作品介绍】
这是一款弹球模拟器(含bug),小球会反弹到结界下方,我们需要通过鼠标移动来控制挡板不让小球掉出结界,当小球碰到挡板时就会反弹分数就会+1。分时越高速度越快,速度分为5个阶段,慢, 慢偏中,中速,中偏快,快。在封皮的着3张图片要存在一个名为images的文件里。
【作品源代码】
import pgzrun
WIDTH = 800
HEIGHT = 600
TITLE = '球'
score = 0
status = True
ball = Actor('魔法球', (100, 100))
boundary = Actor('结界', (WIDTH/2, HEIGHT/2))
baffle = Actor('能量挡板', (WIDTH/2, HEIGHT*4/5))
def draw():
screen.fill('midnightblue')
boundary.draw()
if status == True:
ball.draw()
baffle.draw()
else:
screen.draw.text("GAME OVER", (200, 250), color='white', fontsize=100)
screen.draw.text(str(score), (30, 30), color='white', fontsize=50)
x_step = 6
y_step = 6
def update():
global x_step, y_step, score, status
if score == 10:
x_step += 2
y_step += 2
if score == 20:
x_step += 2
y_step += 2
if score == 30:
x_step += 2
y_step += 2
if score == 40:
x_step += 2
y_step += 2
if score == 50:
x_step += 2
y_step += 2
if ball.right > WIDTH - 30 or ball.left < 30:
x_step = -x_step
if ball.top < 30:
y_step = -y_step
ball.x += x_step
ball.y += y_step
if baffle.colliderect(ball):
y_step = -y_step
score = score+1
if ball.bottom > HEIGHT-30:
status = False
def on_mouse_move(pos):
baffle.x = pos[0]
pgzrun.go()
【提示】
部分含有Python第三方库相关内容的作品,在海龟编辑器网页端无法运行哦!如遇到这种情况,可以打开下面的链接,下载海龟编辑器客户端:
https://python.codemao.cn