Christopher Franklin
Nov 19, 2021, 7:33 PST
My student just recreated Lesson 23 activity 2 Flyer game. In his code (below) the left arrow key does not control the sprite’s movement. When he takes out the right arrow key’s code, it works. How could this be?
// GAME SETUP
// create player, target, and obstacles
var fly_bot = createSprite(200, 100);
fly_bot.setAnimation(“fly_bot”);
fly_bot.scale = 0.8;
var coin = createSprite(300,350);
coin.setAnimation(“coin”);
var rock = createSprite(10,50);
rock.setAnimation(“rock”);
var rock = createSprite(300,25);
rock.setAnimation(“rock”);
//baclground
function draw() {
background(“lightblue”);
// LOOPING
// PLAYER CONTROLS
// change the y velocity when the user clicks “up”
if (keyDown(“up”)) {
fly_bot.velocityY= -10;
}
// decrease the x velocity when user clicks “left”
if (keyWentDown(“left”)) {
fly_bot.velocityX= -10;
}
// increase the x velocity when the user clicks “right”
if (keyDown(“right”)) {
fly_bot.velocityX= 10;
}
// FALLING
else {
fly_bot.velocityY = fly_bot.velocityY + 0.4;
fly_bot.velocityX=0;
}
// SPRITE INTERACTIONS
// reset the coin when the player touches it
// make the obstacles push the player
// DRAW SPRITES
drawSprites();
// GAME OVER
if (fly_bot.x < -50 fly_bot.x > 450 fly_bot.y < -50 fly_bot.y > 450) {
background(“black”);
textSize(50);
fill(“green”);
text(“Game Over!”, 50, 200);
}
}