不确定为什么If Statement不起作用。 (pygame的)

时间:2015-05-02 22:46:23

标签: python python-2.7 if-statement pygame

好的,现在当我在" start.png"它会跳到" cele.png"当我希望它去" new.png"。我希望它开始于" start.png"然后当你按E时它应该改为" new.png"如果再次按E,背景为" new.png"然后它应该改为" cele.png"谢谢!



#import library
import pygame
from pygame.locals import *
 
#initialize the game
pygame.init()
width, height = 1000, 800
screen=pygame.display.set_mode((width, height))
pygame.display.set_caption("Pygame Window")
 
#load images
bg_filename = "start.png"
background = pygame.image.load(bg_filename)

#keep looping through
while 1:

    #clear the screen before drawing it again
    screen.fill(0)
    #draw the screen elements
    screen.blit(background, (0,0))
    #update the screen
    pygame.display.flip()
    #loop through the events
    for event in pygame.event.get():

        #start to new
        if event.type == pygame.KEYDOWN:
            if event.key == pygame.K_e:
                if bg_filename == "start.png":
                    bg_filename = "new.png"
                    background = pygame.image.load(bg_filename)

        #new to cele 
        if event.type == pygame.KEYDOWN:
            if event.key == pygame.K_e:
                if bg_filename == "new.png":
                    bg_filename = "cele.png"
                    background = pygame.image.load(bg_filename)

        #check if the event is the X button 
        if event.type==pygame.QUIT:
            #if it is quit the game
            pygame.quit() 
            exit(0)




0 个答案:

没有答案