WDI-SEA / game-project-issues

0 stars 0 forks source link

My hit detection only works once #61

Closed kellylarrea closed 3 years ago

kellylarrea commented 3 years ago

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

My hit detection works on the first hit but doesnt work after that.

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

let watermelonDetectHit = () => {
    if(
        player.x < allFoods[0].x + allFoods[0].width &&
        player.x + player.width > allFoods[0].x &&
        player.y < allFoods[0].y + allFoods[0].height &&
        player.y + player.height > allFoods[0].y)
        {
            allFoods[0].alive = false
            document.querySelector('#top-right> h2').innerText="+12"
            gameScore += gamePoints
        }
    }

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

25script.js:104 Uncaught TypeError: Cannot read properties of undefined (reading 'x') at watermelonDetectHit (script.js:104) at gameLoop (script.js:183)

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

I believe its because I set my x property on random.

What things have you already tried to solve the problem?

Im not really sure how to fix that.

TaylorDarneille commented 3 years ago

What line is 104?

kellylarrea commented 3 years ago

Timm helped me with my hit detection function. Had to adjust it to a new array.