|

楼主 |
发表于 2018-12-3 11:16:35
|
显示全部楼层
import pygame
from pygame.locals import *
import sys ,random
screen_width=400
screen_height=500
FPS=30
Image,Sound={},{}
Brid_List = (
(
'img/redbird-downflap.png',
'img/redbird-midflap.png',
'img/redbird-downflap.png',
),
(
'img/bluebird-upflap.png',
'img/bluebird-midflap.png',
'img/bluebird-downflap.png',
),
(
'img/yellowbird-upflap.png',
'img/yellowbird-midflap.png',
'img/yellowbird-downflap.png',
),
)
Background_List = (
'img/background-day.png',
'img/background-night.png',
)
# list of pipes
Pip_List = (
'img/pipe-green.png',
'img/pipe-red.png',
)
# 主循环 事件监听 关闭窗口
def main():
#全局变量
global surface, FpsClock
pygame.init()
FpsClock = pygame.time.Clock()
surface = pygame.display.set_mode((screen_width, screen_height))
pygame.display.set_caption('Flappy Bird')
Image['number'] = (
pygame.image.load('img/0.png').convert_alpha(),
pygame.image.load('img/1.png').convert_alpha(),
pygame.image.load('img/2.png').convert_alpha(),
pygame.image.load('img/3.png').convert_alpha(),
pygame.image.load('img/4.png').convert_alpha(),
pygame.image.load('img/5.png').convert_alpha(),
pygame.image.load('img/6.png').convert_alpha(),
pygame.image.load('img/7.png').convert_alpha(),
pygame.image.load('img/8.png').convert_alpha(),
pygame.image.load('img/9.png').convert_alpha()
)
Image['gameover'] = pygame.image.load('img/gameover.png').convert_alpha()
Image['message'] = pygame.image.load('img/message.png').convert_alpha()
Image['base'] = pygame.image.load('img/base.png').convert_alpha()
if 'win' in sys.platform:
Suffix = '.wav'
else:
Suffix= '.ogg'
Sound['die'] = pygame.mixer.Sound('music/die'+Suffix)
Sound['hit'] = pygame.mixer.Sound('music/hit' + Suffix)
Sound['point'] = pygame.mixer.Sound('music/point' + Suffix)
Sound['swoosh'] = pygame.mixer.Sound('music/swoosh' + Suffix)
Sound['wing'] = pygame.mixer.Sound('music/wing' + Suffix)
while True:
for event in pygame.event.get():
if event.type == QUIT:
pygame.quit()
sys.exit()
# 投影实现
surface.blit(Image)
# 绘制图形
pygame.display.update()
# 设置帧率
FpsClock.tick(500)
if __name__ == '__main__':
main() |
|