Python 碰撞检测问题(pygame),“;“检测到碰撞”;isn';t打印一次两个表面悬停在彼此上方

Python 碰撞检测问题(pygame),“;“检测到碰撞”;isn';t打印一次两个表面悬停在彼此上方,python,pygame,2d,sprite,platform,Python,Pygame,2d,Sprite,Platform,[从POST中删除内存问题] 嘿,伙计们,我是pygame的新手,我有一些小问题。在点击鼠标按钮之前,一旦jetfighter rect与狼蛛的rect发生碰撞,Python shell不会打印检测到的碰撞,但是表面会彼此悬停,没有给出错误信息。第54行的if语句按预期工作,所以我有点困惑,为什么第61行的语句不能按预期工作。如果有人能对我的问题有所了解,我将不胜感激 代码: 你至少在这里问了两个问题。在StackOverflow上,您希望将您的帖子限制为一个问题 第二个问题是重复的。好的,明白

[从POST中删除内存问题]

嘿,伙计们,我是pygame的新手,我有一些小问题。在点击鼠标按钮之前,一旦jetfighter rect与狼蛛的rect发生碰撞,Python shell不会打印检测到的碰撞,但是表面会彼此悬停,没有给出错误信息。第54行的if语句按预期工作,所以我有点困惑,为什么第61行的语句不能按预期工作。如果有人能对我的问题有所了解,我将不胜感激

代码:


你至少在这里问了两个问题。在StackOverflow上,您希望将您的帖子限制为一个问题


第二个问题是重复的。

好的,明白了,你至少知道我应该如何处理我的第一个问题吗?我在这里没有遇到任何类似的问题…顺便说一句,我已经编辑了我的原始帖子。如果你用正确的标题再次提问,你可能会获得更好的可视性。
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()