我很新,我似乎找不到任何有关如何执行此操作的教程。我想这将非常简单。我正在创建Oregon Trail类型的游戏,当您按E时我需要它进入下一张图片,或者在按Q时退出程序。
这是我的代码:
# 1 - Import library
import pygame
from pygame.locals import *
# 2 - Initialize the game
pygame.init()
width, height = 1000, 800
screen=pygame.display.set_mode((width, height))
# 3 - Load images
background = pygame.image.load("start.png")
# 4 - keep looping through
while 1:
# 5 - clear the screen before drawing it again
screen.fill(0)
# 6 - draw the screen elements
screen.blit(background, (0,0))
# 7 - update the screen
pygame.display.flip()
# 8 - loop through the events
for event in pygame.event.get():
# check if the event is the X button
if event.type==pygame.QUIT:
# if it is quit the game
pygame.quit()
exit(0)
我认为您正在寻找这样的东西:
# 1 - Import library
import pygame
from pygame.locals import *
# 2 - Initialize the game
pygame.init()
width, height = 1000, 800
screen=pygame.display.set_mode((width, height))
# 3 - Load images
background = pygame.image.load("start.png")
# 4 - keep looping through
while 1:
# 5 - clear the screen before drawing it again
screen.fill(0)
# 6 - draw the screen elements
screen.blit(background, (0,0))
# 7 - update the screen
pygame.display.flip()
# 8 - loop through the events
for event in pygame.event.get():
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_e:
background = pygame.image.load("stage2.png")
# check if the event is the X button
if event.type==pygame.QUIT:
# if it is quit the game
pygame.quit()
exit(0)
当然,这仅适用于2张背景为“ start.png”和stage2.png”的图像。但是您可以通过它创建一个列表和cicle。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句