WDI-SEA / game-project-issues

0 stars 0 forks source link

Collison detection #35

Closed DagemBefikadu closed 3 years ago

DagemBefikadu commented 3 years ago

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

Ive gotten my objects to appear randomly but i can get just one object to disappear at a time. Spent time in office hours yesterday and we couldn't find a solution .

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

//   createMoreCourtObjects()
//   courtObjects.forEach((object) => {
//     object.render();
//     if (
//         player.x > object.x && player.y > object.y 

//     ) {
//         console.log(player.x)
//         console.log(object.x)
//         console.log(player.y)
//         console.log(object.y)
//         object.alive = false
//         courtObjects.splice(object,1)
//         // console.log(courtObjects)
//         console.log(object.color)
//         console.log(object.alive)
//     }
//   });

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 grab my information out of my array because thats where its stored but every method i have tried hasnt worked

What things have you already tried to solve the problem?

Moving my if condition in different location, trying a for loop instead of intervals.

TaylorDarneille commented 3 years ago

1: add to your if-condition so you are getting a console.log every time there is a hit

2: add more objects to the board and make sure your console.log is showing that you only hit the thing you intended to hit, and no more

3: unalive the hit object and remove it from the array (check the splice documentation)

DagemBefikadu commented 3 years ago

Momma we made it!!!

After learning from Taylor that spice() only works with integers everything else made sense, instead of using the whole array we used courtObjects[i] which is a integer. We took a forEach and broke it down to a forLoop made it much easier to understand.

I courtObjects[i] and passed it into a If statement to check my collision, with the help of Tom we switched some values around to make the hit more precise.