Python pygame的崩溃事件

Python pygame的崩溃事件,python,pygame,pygame-surface,Python,Pygame,Pygame Surface,我正在做一个简单的pygame项目,它目前有从屏幕顶部到屏幕底部的坠落炸弹。如果玩家击中炸弹,他们就会死亡。到目前为止,一切正常。问题是当炸弹经过玩家但还没有离开屏幕时,它仍然会杀死玩家。也就是说,炸弹会穿过玩家的下半部,但是如果你穿过,在它穿过屏幕的下半部之前,你会死。他是我的密码: if player.rect.y < thing_starty + thing_height: if player.rect.x > thing_startx and playe

我正在做一个简单的pygame项目,它目前有从屏幕顶部到屏幕底部的坠落炸弹。如果玩家击中炸弹,他们就会死亡。到目前为止,一切正常。问题是当炸弹经过玩家但还没有离开屏幕时,它仍然会杀死玩家。也就是说,炸弹会穿过玩家的下半部,但是如果你穿过,在它穿过屏幕的下半部之前,你会死。他是我的密码:

   if player.rect.y < thing_starty + thing_height:
        if player.rect.x > thing_startx and player.rect.x < thing_startx + thing_width or player.rect.x  + 28 > thing_startx and player.rect.x  + 28 < thing_startx + thing_width: 
            gameOver = True
player.rect.x的值范围为120到500,具体取决于播放器在屏幕上的位置。(移动时屏幕也会从左向右滚动。)28来自字符图像的宽度

坠落物体的代码如下所示:

if thing_starty > S_HEIGHT:
        pygame.mixer.Sound.play(bomb_sound)
        thing_starty = 0 - thing_height
        thing_startx = random.randrange(0, S_WIDTH)
        dodged += 1
        thing_speed += .5

我已经为此工作了大约一个星期,没有取得任何进展。谢谢你的帮助

我不懂python,但很明显,您用来测试冲突的条件语句只是检查y值是否大于播放器的y值,当然,即使在它通过屏幕底部后,y值也将为真。所以你需要一个AND操作数

伪代码(因为我不懂python…或者你正在使用的任何东西)

if(bomb.y>=player.y和bomb.y=player.y){

如果(bomb.y如Neal所说,您只需检查y值是否大于玩家的y值

但我的建议是,停止使用这样的代码:

 if player.rect.y < thing_starty + thing_height:
    if player.rect.x > thing_startx and player.rect.x < thing_startx + thing_width or player.rect.x  + 28 > thing_startx and player.rect.x  + 28 < thing_startx + thing_width: 
        gameOver = True
if player.rect.colliderect(thing.rect):
    gameOVer = True

*它应该有自己的类,继承自
Sprite
,但这是另一个主题,pygame必须保持对象的位置和大小,并检查碰撞。
if (bomb.y >= player.y){
    if (bomb.y <= player.y + player.height){
        run bomb collision logic
    }
 }
 if player.rect.y < thing_starty + thing_height:
    if player.rect.x > thing_startx and player.rect.x < thing_startx + thing_width or player.rect.x  + 28 > thing_startx and player.rect.x  + 28 < thing_startx + thing_width: 
        gameOver = True
if player.rect.colliderect(thing.rect):
    gameOVer = True