Окно Pygame отображается, но оно полностью черноеPython

Программы на Python
Anonymous
Окно Pygame отображается, но оно полностью черное

Сообщение Anonymous »

Когда я запускаю код, окно Pygame отображается, но оно полностью черное. Ошибки не возвращаются.
import pygame
import sys
import random
from time import sleep

padWidth = 480
padHeight = 640
rockImage = ['C:/Users/yount/Downloads/PyShooting/rock01.png', 'C:/Users/yount/Downloads/PyShooting/rock02.png', 'C:/Users/yount/Downloads/PyShooting/rock03.png', 'C:/Users/yount/Downloads/PyShooting/rock04.png', 'C:/Users/yount/Downloads/PyShooting/rock05.png',]

def drawObject(obj, x, y):
global gamePad
gamePad.blit(obj, (x, y))

def initGame():
global gamePad, clock, background, fighter, missile, explosion
pygame.init()
gamePad = pygame.display.set_mode((padWidth, padHeight))
pygame.display.set_caption('PyShooting')
background = pygame.image.load("C:/Users/yount/Downloads/PyShooting/background.png")
fighter = pygame.image.load("C:/Users/yount/Downloads/PyShooting/fighter.png")
missile = pygame.image.load("C:/Users/yount/Downloads/PyShooting/missile.png")
explosion = pygame.image.load("C:/Users/yount/Downloads/PyShooting/explosion.png")
clock = pygame.time.Clock()

def runGame():
global gamePad, clock, background, fighter, explosion

fighterSize = fighter.get_rect().size
fighterWidth = fighterSize[0]
fighterHeight = fighterSize[1]

x = padWidth * 0.45
y = padHeight * 0.9
fighterX = 0

missileXY = []

rock = pygame.image.load(random.choice(rockImage))
rockSize = rock.get_rect().size
rockWidth = rockSize[0]
rockHeight = rockSize[1]

rockX = random.randrange(0, padWidth - rockWidth)
rockY = 0
rockSpeed = 2

isShot = False
shotCount = 0
rockPassed = 0

onGame = False
while not onGame:

rockX = random.randrange(0, padWidth - rockWidth)
rockY = 0
rockSpeed = 2

fighterSize = fighter.get_rect().size
fighterWidth = fighterSize[0]
fighterHeight = fighterSize[1]

x = padWidth * 0.45
y = padHeight * 0.9
fighterX = 0

onGame = False
while not onGame:
for event in pygame.event.get():
if event.type in [pygame.QUIT]:
pygame.quit()
sys.exit()

if event.type in [pygame.KEYDOWN]:
if event.key == pygame.K_LEFT:
fighterX -= 5

elif event.key == pygame.K_RIGHT:
fighterX += 5

elif event.key == pygame.K_SPACE:
missileX = x + fighterWidth/2
missileY = y - fighterHeight
missileXY.append([missileX, missileY])

if event.type in [pygame.KEYUP]:
if event.key == pygame.K_LEFT or event.key == pygame.K_RIGHT:
fighterX = 0

drawObject(background, 0, 0)

x += fighterX
if x < 0:
x = 0
elif x > padWidth - fighterWidth:
x = padWidth - fighterWidth

drawObject(fighter, x, y)

if len(missileXY) != 0:
for i, bxy in enumerate(missileXY):
bxy[1] -= 10
missileXY[1] = bxy[1]

if bxy[1] < rockY:
if bxy[0] > rockX and bxy[0] < rockX + rockWidth:
missileXY.remove(bxy)
isShot = True
shoutCount += 1

if bxy[1] padHeight:
rock = pygame.image.load(random.choice(rockImage))
rockSize = rock.get_rect().size
rockWidth = rockSize[0]
rockHeight = rockSize[1]
rockX = random.randrange(0, padWidth - rockWidth)
rockY = 0

if isShot:
drawObject(explosion, rockX, rockY)
rock = pygame.image.load(random.choice(rockImage))
rockSize = rock.get_rect().size
rockWidth = rockSize[0]
rockHeight = rockSize[1]
rockX = random.randrange(0, padWidth - rockWidth)
rockY = 0
isShot = False

drawObject(rock, rockX, rockY)

pygame.display.flip()

clock.tick(60)

pygame.quit()

initGame()
runGame()

Вернуться в «Python»