WDI-SEA / game-project-issues

0 stars 0 forks source link

random spawning issue #28

Closed kellylarrea closed 3 years ago

kellylarrea commented 3 years ago

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

trying to spawn my food items randomly.

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

const foodSpawn = () => {
    for(i = 0; i < 4; i++) {
        allFoods[i].x = Math.random(Math.floor() * 10)
        allFoods[i].y = Math.random(Math.floor() * 10)
        i++
    }
}

let newFoodSpawn = setInterval(foodSpawn, 5)

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

no error messages. the items are not spawning just moving in different directions

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

I probably don't have the logic correct on this.

What things have you already tried to solve the problem?

I tried changing the code around.

DoireannJane commented 3 years ago

What do you see in console when you console.logging allFoods[i]?

kellylarrea commented 3 years ago

nothing is showing up when I console log it

DoireannJane commented 3 years ago

Would you mind showing me your array with allFoods?

kellylarrea commented 3 years ago

Food {x: 0.5930871299184475, y: 0.6071007373572399, color: '#C36A2D', width: 20, height: 20, …}

I forgot to invoke it in my game loop. This is the console log I see.

let allFoods = [watermelon, spinach, potatoChip, twinkie] this is the food array

TaylorDarneille commented 3 years ago

This is resolved! Kelly will update :)

kellylarrea commented 3 years ago

Was able to spawn my foods instead of <5 it was changed to < allFoods.length