问题描述
我是python的新手,最近开始使用pygame开发游戏。我想知道为什么我的游戏只是死机并且出现退出代码-805306369(0xCFFFFFFF)。我的程序中是否有错误?看起来像这样:
import pygame
import random
import math
pygame.init()
window = pygame.display.set_mode((1000,600))
caption = pygame.display.set_caption(
'Test your reaction speed. Shoot the target game!') # sets a caption for the window
run = True
PlayerImg = pygame.image.load('F:\PythonPortable\oscn.png')
PlayerX = 370
PlayerY = 420
PlayerX_change = 0
PlayerY_change = 0
def player():
window.blit(PlayerImg,(PlayerX,PlayerY))
aim_sight = pygame.image.load('F:\PythonPortable\ktarget.png')
aim_sightX = 460
aim_sightY = 300
aim_sight_changeX = 0
aim_sight_changeY = 0
def aim_sight_function(x,y):
window.blit(aim_sight,(x,y))
targetedImg = pygame.image.load('F:\PythonPortable\ktargetedperson.png')
targetedX = random.randint(0,872)
targetedY = random.randint(0,200)
def random_target():
window.blit(targetedImg,(targetedX,targetedY))
def iscollision(targetedX,targetedY,aim_sightX,aim_sightY):
distance = math.sqrt((math.pow(targetedX - aim_sightX,2)) + (math.pow(targetedY - aim_sightY,2)))
if distance < 70:
return True
else:
return False
while run:
window.fill((255,255,255))
random_target()
for event in pygame.event.get():
if event.type == pygame.QUIT:
run = False
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_LEFT:
aim_sight_changeX = -2
PlayerX_change = -2
elif event.key == pygame.K_RIGHT:
aim_sight_changeX = 2
PlayerX_change = 2
elif event.key == pygame.K_UP:
aim_sight_changeY = -2
PlayerY_change = -2
elif event.key == pygame.K_DOWN:
aim_sight_changeY = 2
PlayerY_change = 2
score = 0
while score < 10:
collision = iscollision(targetedX,aim_sightY)
if collision and event.key == pygame.K_SPACE:
print("HIT") # Just for me to acknowledge that collision is true and space bar was pressed in the right spot
score = score + 1
elif event.type == pygame.KEYUP:
if event.key == pygame.K_LEFT or event.key == pygame.K_RIGHT:
aim_sight_changeX = 0
PlayerX_change = 0
elif event.key == pygame.K_UP or event.key == pygame.K_DOWN:
aim_sight_changeY = 0
PlayerY_change = 0
aim_sightX += aim_sight_changeX
if aim_sightX <= 46.5:
aim_sight_changeX = 0
elif aim_sightX >= 936:
aim_sight_changeX = 0
aim_sightY += aim_sight_changeY
if aim_sightY <= 0:
aim_sight_changeY = 0
elif aim_sightY >= 400:
aim_sight_changeY = 0
PlayerX += PlayerX_change
if PlayerX <= -50:
PlayerX_change = 0
elif PlayerX >= 850:
PlayerX_change = 0
player()
aim_sight_function(aim_sightX,aim_sightY)
pygame.display.update()
我认为这是一个错误,因为如果没有它,我的程序将运行良好。
while score < 10:
collision = iscollision(targetedX,aim_sightY)
if collision and event.key == pygame.K_SPACE:
print("HIT") # Just for me to acknowledge that collision is true and space bar was pressed in the right spot
score = score + 1
我检查了其他问题,但是它们主要用于Java和其他语言。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)