WDI-SEA / game-project-issues

0 stars 0 forks source link

Level logic not checking out #40

Closed jyang1003 closed 3 years ago

jyang1003 commented 3 years ago

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

I'm not sure how to implement my level logic and need someone to talk it out with

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

const level = (levelNumber) => {
    // every other lane switches direction for level 2
    //switch movement from += to -= for other direction 
    levelNumber = gameState
    let spawnOne = setInterval(() => carSpawn(xPosition[levelNumber - 1][0], 0, carLane[0]), carSpawnTime())
    let spawnTwo = setInterval(() => carSpawn(xPosition[levelNumber - 1][1], 50, carLane[1]), carSpawnTime())
    let spawnThree = setInterval(() => carSpawn(xPosition[levelNumber - 1][2], 100, carLane[2]), carSpawnTime())
    let spawnFour = setInterval(() => carSpawn(xPosition[levelNumber - 1][3], 150, carLane[3]), carSpawnTime())
    let spawnFive = setInterval(() => carSpawn(xPosition[levelNumber - 1][4], 200, carLane[4]), carSpawnTime())
    let spawnSix = setInterval(() => carSpawn(xPosition[levelNumber - 1][5], 250, carLane[5]), carSpawnTime())
    let spawnSeven = setInterval(() => carSpawn(xPosition[levelNumber - 1][6], 300, carLane[6]), carSpawnTime())
}

level(gameState)

//function that makes the game run, setInterval
const gameLoop = () => {
    // window.requestAnimationFrame(gameLoop);
    // clear the canvas
    ctx.clearRect(0, 0, game.width, game.height)
    player.render()
    player.movePlayer()

    //game only runs if player alive
    if (player.alive && playerLives > 0) {
        carMovement()
        if (player.y <= 0) {
            player.y = 410
            player.x = 580
            ctx.clearRect(0, 0, game.width, game.height)
            gameState++
            console.log(gameState)
        }
    }
    else{
        //stop game
    }
}

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

no error message

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

either level function is not placed correctly or the logic is not working out

What things have you already tried to solve the problem?

Tried placing level function in game loop but it makes the cars into solid white blocks