用户:苍炎刃鬼查看:0 回复:0 评论:0 创建时间:2022-08-29T13:17:33
【作品展示】

【作品介绍】
平板弹球重磅上线!!!在智能纪元2046年,游戏AI得以大规模普及,游戏中的角色逐渐有了简单的意识。
W和S操作上下,
A和D操作左右,
碰到蓝币可以加分,
蓝币被碰到会随机移动,
快来玩吧!
#此游戏是用海龟模拟器的Python代码制成,可能会幼稚一点,敬请谅解。
【作品源代码】
import pgzrun
import random
WIDTH = 450
HEIGHT = 650
score = 0
x_speed, y_speed = 5, -5
move_speed = 10
game_state = 'start'
count = 0
ball = Actor('ball', (300, 300))
coin = Actor('coin', (225, 150))
panel = Actor('panel', (225, 500))
def draw():
global game_state
if game_state == 'start':
screen.fill('gold')
screen.draw.text('Bounce Ball', (136, 260), fontsize=50)
screen.draw.text('Prss SPACE to start', (132, 310),
fontsize=30)
if keyboard.space:
game_state = 'play'
elif game_state == 'play':
screen.fill('gold')
screen.draw.text('score:' + str(score), (10, 10),
fontsize=30)
panel.draw()
ball.draw()
coin.draw()
else:
screen.fill('gold')
panel.draw()
ball.draw()
coin.draw()
screen.draw.text('Game Over', (136, 260),
color='red', fontsize=50)
screen.draw.text('Your Score:' + str(score),
(140, 310), fontsize=40)
def update():
global game_state, score, x_speed, y_speed, count
if game_state =='play':
ball.x += x_speed
ball.y += y_speed
if ball.x < 25 or ball.x > WIDTH -25:
x_speed = - x_speed
ball.x +=x_speed
if ball.y < 25:
y_speed = - y_speed
ball.y += y_speed
elif ball.y > HEIGHT - 30:
game_state = 'game over'
if ball.x < 25 or ball.x > WIDTH - 25:
x_speed = - x_speed
ball.x += x_speed
if ball.y < 25 or ball.y > HEIGHT - 25:
y_speed = - y_speed
ball.y += y_speed
if keyboard.a:
panel.x -= move_speed
elif keyboard.d:
panel.x += move_speed
elif keyboard.w:
panel.y -= move_speed
elif keyboard.s:
panel.y += move_speed
if count == 0:
if panel.colliderect(ball):
y_speed = -y_speed
sounds.bounce.play()
count = 1
else:
count += 1
if count > 60:
count = 0
if panel.colliderect(ball):
y_speed = - y_speed
if coin.collidepoint(ball.pos):
score += 1
coin.x = random.randint(30, WIDTH - 30)
coin.y = random.randint(30, HEIGHT / 2)
pgzrun.go()
【提示】
部分含有Python第三方库相关内容的作品,在海龟编辑器网页端无法运行哦!如遇到这种情况,可以打开下面的链接,下载海龟编辑器客户端:
https://python.codemao.cn