各位大佬,为什么我的地板不动
代码:import sys
import pygame
import random,os
# Constants 常量
W,H = 288,512
FPS = 30
# Setup 设置
pygame.init()
SCREEN = pygame.display.set_mode((W,H))
pygame.display.set_caption(' flappy bird ')
CLOCK = pygame.time.Clock()
# Haterials 素材
IMAGES = {}
for image in os.listdir('999'):
name,extension = os.path.splitext(image)
path = os.path.join('999',image)
IMAGES[name] = pygame.image.load(path)
FLOOR_Y = H - IMAGES['floor'].get_height()
start = pygame.mixer.Sound('999')
die = pygame.mixer.Sound('999')
flap = pygame.mixer.Sound('999')
hit = pygame.mixer.Sound('999')
score = pygame.mixer.Sound('999')
def main():
while True:
start.play()
IMAGES['bgpic'] = IMAGES[random.choice(['day','night'])]
color = random.choice(['red','yellow','blue'])
IMAGES['birds'] = [IMAGES[color+'-up'],IMAGES[color+'-mid'],IMAGES[color+'-down']]
pipe = IMAGES[random.choice(['green-pipe','red-pipe'])]
IMAGES['pipes'] = [pipe,pygame.transform.flip(pipe,False,True)]
menv_window()
game_window()
end_window()
def menv_window():
floor_gap = IMAGES['floor'].get_width() - W
floor_x = 0
guide_x = (W - IMAGES['guide'].get_width())/2
guide_y = (FLOOR_Y - IMAGES['guide'].get_height())/2
bird_x = W * 0.2
bird_y = (H - IMAGES['red-up'].get_height())/2
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
sys.exit()
if event.type == pygame.KEYDOWN and event.key == pygame.K_SPACE:
return
floor_x -= 4
if floor_x <= - floor_gap:
floor_x = 0
SCREEN.blit(IMAGES['bgpic'],(0,0))
SCREEN.blit(IMAGES['floor'],(0,FLOOR_Y))
SCREEN.blit(IMAGES['guide'],(guide_x,guide_y))
SCREEN.blit(IMAGES['birds'][0],(bird_x,bird_y))
pygame.display.update()
CLOCK.tick(FPS)
def game_window():
floor_gap = IMAGES['floor'].get_width() - W
floor_x = 0
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
sys.exit()
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_SPACE:
return
floor_x -= 4
if floor_x <= - floor_gap:
floor_x = 0
SCREEN.blit(IMAGES['bgpic'],(0,0))
SCREEN.blit(IMAGES['pipes'][0],(W/2,H/2))
SCREEN.blit(IMAGES['floor'],(0,FLOOR_Y))
SCREEN.blit(IMAGES['birds'][0],(W/2,H*0.3))
pygame.display.update()
CLOCK.tick(FPS)
def end_window():
floor_gap = IMAGES['floor'].get_width() - W
floor_x = 0
gameover_x = (W - IMAGES['gameover'].get_width())/2
gameover_y = (FLOOR_Y - IMAGES['gameover'].get_height())/2
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
sys.exit()
if event.type == pygame.KEYDOWN and event.key == pygame.K_SPACE:
return
floor_x -= 4
if floor_x <= - floor_gap:
floor_x = 0
SCREEN.blit(IMAGES['bgpic'],(0,0))
SCREEN.blit(IMAGES['floor'],(0,FLOOR_Y))
SCREEN.blit(IMAGES['gameover'],(gameover_x,gameover_y))
SCREEN.blit(IMAGES['birds'][0],(W / 2,H * 0.3))
pygame.display.update()
CLOCK.tick(FPS)
main()
图片请各位大佬自行寻找
要添加地址的地方为999