flappy bird:飞翔的小鸟,扑腾的小鸟
一位来自越南河内的独立游戏开发者阮哈东开发,是一款简易却难度极高的休闲游戏
需要两个自定义类:
class Bird()与class PipeLine()
示例程序如下【未完待续】:
FlappyBirdSnake.py
import sys
import pygame
'''
flappy bird:飞翔的小鸟,扑腾的小鸟
一位来自越南河内的独立游戏开发者阮哈东开发, 备份代码
class Bird(pygame.sprite.Sprite):def __init__(self, screen, x, y):pygame.sprite.Sprite.__init__(self)self.screen = screendef birdUpdate(self):pass
'''
class Bird():def __init__(self):self.birdRect = pygame.Rect(65, 50, 50, 50)#鸟的三种状态 绿色、红色、灰色【死亡】self.birdStatus=[pygame.image.load("FlappyBirdResource/backup/bird.png"),pygame.image.load("FlappyBirdResource/backup/red.png"),pygame.image.load("FlappyBirdResource/backup/dead.png")]self.status=0 #默认飞行状态self.x=120 #左右方向是X轴,左上角的坐标为(0,0)self.y=350 #上下方向是Y轴self.jump=False #默认小鸟自动降落self.jumpSpeed=10 #跳跃速度self.gravity=5 #重力self.dead=False #小鸟是否死亡def birdUpdate(self):if self.jump: #小鸟跳跃self.jumpSpeed -= 1 #速度递减,上升越来越慢self.y -= self.jumpSpeed #鸟Y坐标
class PipeLine():def __init__(self):passdef updatePipeline(self):pass
def createMap():screen.fill((255,255,255)) #注意RGB是个元组screen.blit(background, (0,0))pygame.display.update()
if __name__ == '__main__':pygame.init()size=width, height = 800, 600screen = pygame.display.set_mode(size)clock=pygame.time.Clock()pipe = PipeLine()bird = Bird()while True:clock.tick(60)for event in pygame.event.get():if event.type == pygame.QUIT:sys.exit()background = pygame.image.load("FlappyBirdResource/backup/background.png")createMap()pygame.quit()sys.exit()
运行如图:
