我想将开始屏幕切换到游戏。当我按下回车时,它应该会发生。但是当我按下回车时发生的事情实际上是退出游戏。
这是代码:
import random
from time import sleep
import pygame
screen = pygame.display.set_mode([800,600], 0 , 32)
startscreen = pygame.image.load(".\\img\\startscreen.png")
while True:
for event in pygame.event.get():
if (event.type == pygame.QUIT):
pygame.quit()
quit()
sys.exit()
if (event.type == pygame.KEYDOWN):
if (event.key == pygame.K_RETURN):
self.initialize()
screen.blit(startscreen,(0,0))
pygame.display.update()
class CarRacing:
def __init__(self):
pygame.init()
self.display_width = 800
self.display_height = 600
self.black = (0, 0, 0)
self.white = (255, 255, 255)
self.clock = pygame.time.Clock()
self.gameDisplay = None
def initialize(self):
self.crashed = False
self.carImg = pygame.image.load('.\\img\\police.png')
self.car_x_coordinate = (self.display_width * 0.45)
self.car_y_coordinate = (self.display_height * 0.8)
self.car_width = 49
# enemy_car
self.enemy_car = pygame.image.load('.\\img\\enemy_car_1.png')
self.enemy_car_startx = random.randrange(200, 600)
self.enemy_car_starty = -600
self.enemy_car_speed = 5
self.enemy_car_width = 49
self.enemy_car_height = 100
# Background
self.bgImg = pygame.image.load('.\\img\\newroad.jpg')
self.bg_x1 = (self.display_width / 4) - (360 / 4)
self.bg_x2 = (self.display_width / 4) - (360 / 4)
self.bg_y1 = 0
self.bg_y2 = -600
self.bg_speed = 3
self.count = 0
我希望你们能帮助我。顺便说一下,这是我测试的一个项目。我已经尝试了很多改变,但没有任何改变。
元芳怎么了
相关分类