Closed emilybarwinczak closed 3 years ago
are you still working on this issue?
Create a global "direction" variable that keeps track of which direction the cat is going. When the cat hits a wall, change the variable value. Add an if-statement in the game loop that checks the direction var to decide whether to + or -.
PRAISE THE LORD THIS ISSUE IS CLOSED!!!!!
function catbrownMoveX () { console.log(catsbrown.x) if (catsbrown.x > 1087){ catDirection = false } else if (catsbrown.x < 0) { catDirection = true } console.log('Cat Direction' + catDirection) if (catDirection === true){ catsbrown.x += 4 console.log('+') } else { catsbrown.x -= 4 console.log('-') } }
was using === instead of < and moving at 4 was skipping over 1087
What's the problem you're trying to solve?
i've gotten the cats to spawn at random spots and move in different directions but once they reach the edges of the canvas, they are gone forever.
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?
What is your best guess as to the source of the problem?
that i am doing something wrong
What things have you already tried to solve the problem?
have tried if else statements, += and -=, and functions but i can't figure out what will keep these crazy cats on canvas