【发布时间】:2019-12-01 16:56:50
【问题描述】:
所有图片都在游戏文件夹中。 (使用麦克) 我没有错误,但图像只是不加载。只是一个纯白的屏幕。
我已经尝试了一切,我可能会在这一点上放弃。我求你了,求求你,请帮助我!
我的程序超长,我知道我的要求很疯狂,但我已经尝试解决这个问题超过 2 周了!
我希望我犯了一个小错误,这不是一个更大的问题!
对不起!
import pygame
pygame.init()
display_width = 800
display_height = 600
black = (0,0,0)
white = (255,255,255)
red = (255,0,0)
green = (0,255,0)
gameDisplay = pygame.display.set_mode((display_width,display_height))
pygame.display.set_caption('Hack Attack')
clock = pygame.time.Clock()
charUp = pygame.image.load('StandUp.png') #Can also be used for down
charDown = pygame.image.load('StandUp.png')
charLeft = pygame.image.load('StandLeft.png') #Can also be used for right
charRight = pygame.image.load('StandLeft.png')
UpFor1 = pygame.image.load('Upfor1.png') #Can also be used for Down Forward 2
DownFor2 = pygame.image.load('Upfor1.png')
UpFor2 = pygame.image.load('UpFor2.png')
DownFor1 = pygame.image.load('UpFor2.png')
LeftFor1 = pygame.image.load('LeftFor1.png')
RightFor2 = pygame.image.load('LeftFor1.png')
RightFor1 = pygame.image.load('LeftFor2.png')
LeftFor2 = pygame.image.load('LeftFor2.png')
UpCount = 0
LeftCount = 0
RightCount = 0
DownCount = 0
character = pygame.image.load('StandUp.png')
x = (display_width * 0.5)
y = (display_height * 0.5)
def gameLoop():
global character
global UpCount
global DownCount
global LeftCount
global RightCount
global y
global x
global x_change
global y_change
x_change = 0
y_change = 0
crashed = False
while not crashed:
for event in pygame.event.get():
if event.type == pygame.QUIT:
crashed = True
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_a:
LeftCount += 1
x_change = -5
character = charLeft
if LeftCount % 2 == 0:
x = LeftCount/4
try:
x = int(x)
except ValueError:
character = LeftFor1
else:
character = LeftFor2
else:
character = charLeft
if event.key == pygame.K_s:
y_change = -5
character = charRight
DownCount += 1
character = charDown
if DownCount % 2 == 0:
x = DownCount/4
try:
x = int(x)
except ValueError:
character = DownFor1
else:
character = DownFor2
pass
else:
character = charDown
if event.key == pygame.K_w:
y_change = 5
character = charRight
UpCount += 1
character = charUp
x = UpCount
if DownCount % 2 == 0:
x = UpCount/4
try:
x = int(x)
except ValueError:
character = UpFor1
else:
character = UpFor2
else:
character = charUp
if event.key == pygame.K_d:
x_change = 5
character = charRight
RightCount += 1
character = charRight
x = RightCount/4
if DownCount % 2 == 0:
x = RightCount/4
try:
x = int(x)
except ValueError:
character = UpFor1
else:
character = UpFor2
else:
character = charUp
if event.type == pygame.KEYUP:
if event.key == pygame.K_a or event.key == pygame.K_d:
x_change = 0
y_change = 0
x = x + x_change
y = y + y_change
white = [255, 255, 255]
gameDisplay.fill(white)
gameDisplay.blit(character,(x,y))
print('x ' + str(x) + ' y ' + str(y))
pygame.display.flip()
clock.tick(20)
gameLoop()
pygame.quit()
quit()
提前谢谢你!
【问题讨论】:
-
您可以将其中一张图片附加到问题中吗?也许 .PNG 中有一些奇怪的东西?
标签: python-3.x pygame