from Walimaker import *
setup(1024, 512)
bgmusic('./snd/绿色回忆.mp3')
bg_far1 = Character('./Background/scroll_bg_far.png')
bg_far2 = Character('./Background/scroll_bg_far.png')
bg_far2.x = 2048
hills1 = Character('./Background/hills-scroll.png')
hills1.y = -50
hills2 = Character('./Background/hills-scroll.png')
hills2.y = -50
hills2.x = 2048
bg_grass1 = Character('./Background/bg_grass.png')
bg_grass2 = Character('./Background/bg_grass.png')
bg_grass2.x = 2048
horse_run_img = ['./Sprite/Horse/horse-run-00.png','./Sprite/Horse/horse-run-01.png','./Sprite/Horse/horse-run-02.png','./Sprite/Horse/horse-run-03.png','./Sprite/Horse/horse-run-04.png','./Sprite/Horse/horse-run-05.png','./Sprite/Horse/horse-run-06.png']
horse_jump_img = ['./Sprite/Horse/horse-jump-00.png','./Sprite/Horse/horse-jump-01.png','./Sprite/Horse/horse-jump-02.png','./Sprite/Horse/horse-jump-03.png','./Sprite/Horse/horse-jump-04.png','./Sprite/Horse/horse-jump-05.png','./Sprite/Horse/horse-jump-06.png']
horse_img = {'run':horse_run_img,'jump':horse_jump_img}
horse = Character(horse_img)
horse.state = 'run' # state 状态
horse.play_anim() # play播放 animation动画
# horse.dt = 0.08 # time时间 delta极小的
horse.set_dt('run', 0.05) # set 设置
horse.set_dt('jump', 0.15)
# horse.set_next_state('jump', 'run')
horse.goto(-400, -100)
horse.vy = 0
horse.ay = -0.9# 金币
# spritesheet sprite动画精灵 sheet清单
coin_img = SpriteSheet('./Sprite/coin_gold.png', 8, 1)
coin1 = Character(coin_img)
coin1.scale(3)
coin1.play_anim()
coin1.x = 1500
coin1.y = -100
coin2 = Character(coin_img)
coin2.scale(3)
coin2.play_anim()
coin2.x = 3000# 蝙蝠
bat_img = SpriteSheet('./Sprite/bat.png', 4, 4)
bat1 = Character(bat_img[13:])
bat1.play_anim()
bat1.scale(2.5)
bat1.x = 1800
bat1.y = -120
bat2 = Character(bat_img[13:])
bat2.play_anim()
bat2.scale(2.5)
bat2.x = 3800
v = 5text = TextBox(100)
text.print('分数:0')
text.goto(0, 150)
score = 0 # 分数
while True:v += 0.3bg_far1.backward(v)bg_far2.backward(v)hills1.backward(v * 2)hills2.backward(v * 2)bg_grass1.backward(v * 3)bg_grass2.backward(v * 3)if bg_far1.x < -2048:bg_far1.x = bg_far2.x + 2048if bg_far2.x < -2048:bg_far2.x = bg_far1.x + 2048if hills1.x < -2048:hills1.x = hills2.x + 2048if hills2.x < -2048:hills2.x = hills1.x + 2048if bg_grass1.x < -2048:bg_grass1.x = bg_grass2.x + 2048if bg_grass2.x < -2048:bg_grass2.x = bg_grass1.x + 2048# 马的运动horse.vy += horse.ayif horse.collide(bg_grass1) or horse.collide(bg_grass2):horse.state = 'run'horse.vy = max(0, horse.vy) # max 最大 if key_pressed(K_SPACE):horse.state = 'jump'horse.vy = 15 horse.y += horse.vy# 金币coin1.backward(v * 2)coin2.backward(v * 2)if coin1.x < -1500:coin1.x = 1500if coin2.x < -1500:coin2.x = 1500if coin1.collide(horse):coin1.play_snd('./snd/金币.wav')coin1.x = 1500score += 1text.print(f'分数:{score}')if coin2.collide(horse):coin2.play_snd('./snd/金币.wav')coin2.x = 1500score += 1text.print(f'分数:{score}')# 蝙蝠bat1.backward(v * 3)bat2.backward(v * 3)if bat1.x < -1500:bat1.x = 1500if bat2.x < -1500:bat2.x = 1500if horse.collide(bat1) or horse.collide(bat2):text.print("Game Over")while True:if key_pressed(K_p):bat1.x = 1800bat2.x = 3800score = 0text.print(f'分数:{score}') breakupdate()update()
本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!