通过碰撞检测增量的游戏得分

Game score via collision detection increment

所以我有一个游戏,如果我的用户与图像发生碰撞,它会将分数增加 1。但是因为我使用这种碰撞检测方法和 if 语句来增加我的分数,在碰撞期间当碰撞方法检测到它在彼此经过时多次碰撞,分数将上升约 30。我如何阻止它每次递增超过 1。 这是我的代码:

void draw () {  
  if (gameMode == Active) {
    if(crash() == false) {
      drawBackground();
      textSize(32);
      fill(22,100,8);
      text("Score: " + score ,20,40); //calls the drawBackground method
      alien1.update();
      alien2.update();  //constantly calls the move and render method for the alien and defender
      alien3.update();
      user1.render();
      Burger.update();
      if(Bcrash() == true) {
        if(Bcrash() == false) {
          score = score + 1; 
        }
      }
    } else {
      gameMode = End;
      textSize(32);
      fill(22,100,8);
      text("Game Over, press 'r' to restart",150,200);
    }  
  }
}

boolean Bcrash() {
  return user1.crash(Burger));
}

// Burger.class (Editor's note: I guess it's User.class)
public class User {
  boolean crash(Burger A) {   
    return(abs(x-A.x)<=30) && abs(y-A.y)<=30;
  }
}

在允许它添加另一个数字之前检查碰撞是否为假。

类似于:

Boolean collisionInProgress = false;

if(collision == true && collisionInProgress == false){
  score = score+1;
  collisionInProgess = true;
}

…loop…

if(collision == false){
  collisionInProgess = false;
}