[Game Lab - Code.org]
[Link to the project or level: [replace with link to the curriculum or get the “Share” link to a project]]
What I expect to happen: I want the sprite on line 107-124 to continuously move in a square pattern.
**What actually happens:**The sprite makes one loop in a square pattern and then continues to go straight down.
What I’ve tried: Tried reordering code. Tried changing the numbers.
your issue lies with how your checking for positions
function flybotControl() {
if (flybot.y > 124) {
flybot.y = 124;
flybot.velocityX = 4;
flybot.velocityY = 0;
}
if (flybot.x > 124) {
flybot.x = 124;
flybot.velocityY = -4;
flybot.velocityX = 0;
}
if (24 > flybot.y) {
flybot.y = 24;
flybot.velocityX = -4;
flybot.velocityY = 0;
}
if (24 > flybot.x) {
flybot.x = 24;
flybot.velocityX = 0;
flybot.velocityY = 4;
}
}
checking the current coordinates does not automatically put that sprite in bounds, by manually setting the position to the capped one you aviod the edge case here which is the x position always being less than 24