Closed kellylarrea closed 3 years ago
My hit detection works on the first hit but doesnt work after that.
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 } }
25script.js:104 Uncaught TypeError: Cannot read properties of undefined (reading 'x') at watermelonDetectHit (script.js:104) at gameLoop (script.js:183)
I believe its because I set my x property on random.
Im not really sure how to fix that.
What line is 104?
Timm helped me with my hit detection function. Had to adjust it to a new array.
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)
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.