WDI-SEA / game-project-issues

0 stars 0 forks source link

Not sure how to end game when lives hit 0 #41

Closed DG-98 closed 3 years ago

DG-98 commented 3 years ago

What's the problem you're trying to solve?

I want the game to end when lives hit 0

Post any code you think might be relevant (one fenced block per file)

let gamePlay = () => {
  ctx.clearRect(0, 0, gameArea.width, gameArea.height)
  bob.render()
  // green.render()
  // bomb.render()

  // green.y += descent
  bomb.y += descent

  itemSpawned.forEach((items) => {
    items.render()
    items.y += descent
  })

  bombSpawned.forEach((bomb) => {
    bomb.render()
    bomb.y += descent
  })

  hitbox()
  bombHit()
  scoreTracker()
  lifeTracker()
  // if (lives = 0) {
  //   cancelAnimationFrame(gamePlay)
  // }
  requestAnimationFrame(gamePlay)
}

If you see an error message, post it here. If you don't, what unexpected behavior are you seeing?

What is your best guess as to the source of the problem?

I need a way to end requestAnimationFrame

What things have you already tried to solve the problem?

I've tried using if (lives =0) {cancelAnimationFrame} but that only sets the lives variable to 0 and it doesn't end the game when hit.

TaylorDarneille commented 3 years ago

look up how you can manipulate size with things like .fillText and .style

TaylorDarneille commented 3 years ago

figure out how to manually end game since cancelAnimationFrame isn't working (or ask a classmate who has used it)