Don't know what is missing for to code to work (flappy bird)

Hi it’s me again. Right now I am dealing with another game - flappy bird. I am making the function of counting is player losing. I use if-else statement to determine whether the player’s losing. The coding flow seems to be right but it does not work at all. Would like to ask is there something missing for it to work? Thanks!

https://editor.p5js.org/JustinChan/sketches/tdVFtoxIB

I assume this is the code you have added:

  if (this.x < 50) {
  if (y < this.top) {
    gameOver = true;
  } else if (y > this.bottom) {
    gameOver = true;
  } else {
    gameOver = false;
  }
  }

What is the value of this.x?
Try to debug your code - print this value out to console.log!

Is that value ever less than 50?
Try printing this.x < 50 to console.log!

Given that result, is the above block of code ever executed?!?


Also:

  for (let i = 0; i < pipes.length; i++) {
    pipes[i].show();
    pipes[i].update();
    
    if(gameOver == true) {
    background(0);
  }
  } 

Does that look right to you?
Why are you doing a game over check inside a for loop?
Will the value of gameOver change becaause a pipe is updated?

2 Likes

Ahhh I get it. Thank you for the remind! Will check everything after asking in the future! Thanks!

1 Like