Here's a function that uses a for-loop to
step through all the pipes and use the
ImagesTouching function we created in an
earlier topic.
Remember what we're actually storing in the pipe array are pipe halves, but that's ok -- we don't care whether the bird collides with a top-half or bottom-half. The same thing will happen.
function check_for_end_game() {
for (var i=0; i < pipes.length; i++)
if (ImagesTouching(bird, pipes[i])) game_mode = "over";
}
If we find
any of the pipes are touching the bird, we'll set the
game_mode variable to
"over". You may recall we're also doing that if the falling bird reaches the
bottom of the canvas.
We'll call check_for_end_game every time we render a frame.
function Do_a_Frame () {
ctx.clearRect(0, 0, myCanvas.width, myCanvas.height);
bird.Do_Frame_Things();
show_the_pipes();
make_bird_tilt_appropriately();
make_bird_slow_and_fall();
check_for_end_game();
}