-1
[POST에서 삭제 된 메모리 이슈 문제]충돌 감지 문제 (파이 게임은), "충돌 감지"2 표면이 서로
이봐, 난이 새로 온 사람이 파이 게임하기 위에 마우스를 올려 나는 몇 가지를 한 번에 인쇄되지 않습니다 작은 문제. 마우스 버튼을 클릭하기 전에 jetfighter rect가 타란툴라의 충돌과 충돌하지만 Python 쉘이 print collision을 발견하지 못한다. 54 행의 if 문은 의도 한대로 작동하므로, 61 행의 명령문이 예상대로 작동하지 않는 이유에 대해 약간 혼란스러워합니다. 누군가가 내 문제에 대해 밝힐 수 있다면, 나는 크게 감사 할 것이다.
코드 :
import pygame, sys, pygame.mixer
from pygame.locals import *
import random
pygame.init()
bif="space.jpg"
jf="spacefightersprite.png"
enemy="TarantulaSpaceFighter.png"
laser=pygame.mixer.Sound("LaserBlast.wav")
explosionsound=pygame.mixer.Sound("Explosion.wav")
screen=pygame.display.set_mode((1000,800),0,32)
caption=pygame.display.set_caption("Jet Fighter X")
background=pygame.image.load(bif).convert()
jetfighterx=pygame.image.load(jf)
jetfighterx=pygame.transform.scale(jetfighterx, (400,400))
tarantula=pygame.image.load(enemy)
tarantula=pygame.transform.scale(tarantula, (100,100))
laserblast=pygame.image.load("C:\Python27\laser.png")
explosion=pygame.image.load("C:\Python27\explosion.png")
explosion=pygame.transform.scale(explosion, (150,150))
ex,ey=450,0
movex,movey=0,0
clock=pygame.time.Clock()
speed=300
shoot_y=0
collision=False
loop=True
while True:
pygame.mouse.set_visible(False)
mx,my=pygame.mouse.get_pos()
for event in pygame.event.get():
if event.type==QUIT:
pygame.quit()
sys.exit()
if event.type==KEYDOWN:
if event.key==K_ESCAPE or event.key==K_q:
sys.exit()
if event.type==MOUSEBUTTONDOWN:
laserblast=pygame.image.load("C:\Python27\laser.png")
laser.play()
shoot_y=my-200
shoot_x=mx-16
if loop==True:
if shoot_y>0:
screen.blit(laserblast, (shoot_x, shoot_y))
shoot_y-=10
laserblast_rect=laserblast.get_rect(center=(shoot_x, shoot_y))
tarantula_rect=tarantula.get_rect(center=(ex, ey))
jetfighterx_rect=jetfighterx.get_rect(center=(mx, my))
if laserblast_rect.colliderect(tarantula_rect):
laserblast=pygame.transform.scale(laserblast,(0,0))
screen.blit(explosion, (ex, ey-50))
explosionsound.play()
collision=True
elif jetfighterx_rect.colliderect(tarantula_rect):
print "Collision detected"
pygame.display.update()
screen.blit(background, (0,0))
screen.blit(jetfighterx,(mx-200,my-200))
if collision==False:
screen.blit(tarantula, (ex, ey))
milli=clock.tick()
seconds=milli/1000.
dmy=seconds*speed
ey+=dmy
if ey>800:
collision=False
ey=0
ex=random.randint(50,800)
pygame.display.update()
이해가 되셨습니까? 적어도 첫 번째 문제를 어떻게 처리해야하는지 알고 계십니까? 나는 그것과 비슷한 질문을 여기에 오지 않았다 ... 나는 원래의 글을 편집했다. – thebaldhen
올바른 제목으로 다시 질문하는 것이 더 나은 가시성을 얻을 수 있습니다. – jgritty