半夜撸 flap bird

       半夜无眠。起身,写了个flap bird  demo 。幻想一下下。几年前我写出来,现在应该大红大紫了吧大笑大笑。以后的小作品都会发布到这里,welcome everyone。APK下载链接迟点贴上。


  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
好的,以下是一个简单的飞扬的小鸟游戏的代码,使用了pgzero库: ```python import pgzrun import random WIDTH = 400 HEIGHT = 708 bird = Actor('bird1', (75, 350)) bird.dead = False bird.score = 0 bird.vy = 0 bird.gravity = 0.25 bird.flap = -4.6 pipe_gap = 140 pipe_frequency = 1200 last_pipe = pipe_frequency pipes = [] def update_pipes(): global pipes, last_pipe for pipe in pipes: pipe.centerx -= 2 if pipe.right < 0: pipes.remove(pipe) if last_pipe > pipe_frequency: size = random.randint(50, 220) bottom_pipe = Actor('bottom', (WIDTH, size + pipe_gap + 80)) top_pipe = Actor('top', (WIDTH, size - 80)) pipes.append(bottom_pipe) pipes.append(top_pipe) last_pipe = 0 last_pipe += 1 def update_bird(): global bird bird.vy += bird.gravity bird.y += bird.vy if bird.y > HEIGHT: bird.dead = True bird.y = HEIGHT def update(): global bird if not bird.dead: update_pipes() update_bird() def on_key_down(): global bird if not bird.dead: bird.vy = bird.flap def draw(): screen.blit('background', (0,0)) for pipe in pipes: if pipe.image == 'bottom': pipe.draw() else: pipe.draw() bird.draw() screen.draw.text( str(bird.score), color='white', midtop=(WIDTH//2, 10), fontsize=70 ) if bird.dead: screen.draw.text( 'Game Over', color='white', center=(WIDTH//2, HEIGHT//2), fontsize=50 ) def check_collisions(): global bird if not bird.dead: for pipe in pipes: if pipe.colliderect(bird): bird.dead = True return if bird.y > HEIGHT: bird.dead = True return if bird.top < 0: bird.top = 0 elif bird.bottom > HEIGHT: bird.bottom = HEIGHT bird.score = len([p for p in pipes if p.right < bird.x]) def game_loop(): while True: check_collisions() draw() if keyboard.RETURN: reset() def reset(): global bird, pipes, last_pipe bird = Actor('bird1', (75, 350)) bird.dead = False bird.score = 0 bird.vy = 0 bird.gravity = 0.25 bird.flap = -4.6 pipes = [] last_pipe = pipe_frequency game_loop() ``` 运行以上代码,即可开始游戏。玩家需要控制小鸟跳过障碍物,并在屏幕上方积累分数。当小鸟碰到障碍物或触底时,游戏结束。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值