用户:
Chengxuyee_已退查看:0 回复:0 评论:0 创建时间:2020-03-25T20:29:56
【作品展示】

【作品介绍】
点击任意按键开始。鼠标点击跳跃,让猫仔避开障碍物!
【作品源代码】
import pgzrun
from random import randint
WIDTH = 喵0
HEIGHT = 360
score = 0
game_state = 'start'
move_speed = 5
count = 0
jump = False
jump_state = 'up'
cat = Actor("mao_walk1", (100, HEIGHT - 110))
box = Rect(WIDTH + 200, HEIGHT - 110, 40, 50)
def draw():
if game_state == 'start':
screen.blit('round', (-30, -50))
cat.draw()
screen.draw.text('Hurdle',color="dodgerblue",
center=(WIDTH / 2, 150), fontsize=70)
screen.draw.text("Press any key to start",
color="darkblue",
center=(WIDTH / 2, 210), fontsize=40)
else:
screen.blit('round',(-30, -50))
screen.draw.filled_rect(box, 'orange')
cat.draw()
screen.draw.text("Score:" + str(score),
color="blue",
topleft=(10, 10),fontsize=40)
if game_state == 'game over':
screen.draw.text("Game Over", color="dodgerblue",
center=(WIDTH / 2, HEIGHT / 2),
fontsize=100)
def on_key_down():
global game_state
if game_state == 'start':
game_state = 'play'
def on_mouse_down():
global jump
if game_state == 'play':
jump = True
def cat_walk():
global count
if count == 9:
screen.draw.text
count = 0
if cat.image == "mao_walk1":
cat.image = "mao_walk2"
else:
cat.image = "mao_walk1"
else:
count += 1
def cat_jump():
global jump, jump_state
cat.image = "mao_jump"
if jump_state == 'up':
cat.y -= 5
if cat.y <= HEIGHT / 2 - 50:
jump_state = 'down'
elif jump_state == 'down':
cat.y += 5
if cat.y == HEIGHT - 110:
jump = False
jump_state = 'up'
def update():
global score, game_state, move_speed
if game_state == 'play':
if jump:
cat_jump()
else:
cat_walk()
box.x -= move_speed
if box.x < - 30:
score += 1
box.x = randint(700, 1000)
box.y = 250
move_speed += 0.2
pgzrun.go()
【提示】
部分含有Python第三方库相关内容的作品,在海龟编辑器网页端无法运行哦!如遇到这种情况,可以打开下面的链接,下载海龟编辑器客户端:
https://python.codemao.cn