A student wants his “You win” background to appear when the score reaches 25. However, it is not appearing. The game simply continues on. When the student’s Lives gets to 0, the “You Lose” background appears, which is correct. I have included his game.
Thank you,
Jenny Stearns
// Create your variables here
var score = 25;
var lives = 3;
// Create your sprites here
var player = createSprite(100, 100);
player.scale = 0.75;
player.setAnimation(“player”);
var platform = createSprite(150, randomNumber(200, 400));
platform.scale = 1.5;
platform.velocityX = -3;
platform.setAnimation(“platform”);
var platform2 = createSprite(350, randomNumber(200, 400));
platform2.scale = 1.5;
platform2.velocityX = -3;
platform2.setAnimation(“platform”);
var livescoin = createSprite(1000, 200);
livescoin.setAnimation(“livescoin”);
livescoin.velocityX = -3;
var coin = createSprite(randomNumber(410, 600), 200);
coin.scale = 0.5;
coin.setAnimation(“coin”);
coin.velocityX = -3;
var barrier = createSprite(-245, 200);
barrier.scale = 5;
barrier.setAnimation(“barrier”);
var barrier2 = createSprite(645, 200);
barrier2.scale = 5;
barrier2.setAnimation(“barrier”);
var barrier3 = createSprite(200, -245);
barrier3.scale = 5;
barrier3.setAnimation(“barrier”);
var barrier4 = createSprite(200, 645);
barrier4.scale = 5;
barrier4.setAnimation(“barrier”);
function draw() {
// draw background
if (score >= 25) {
winBackground();
player.visible = false;
platform.visible = false;
platform2.visible = false;
coin.visible = false;
livescoin.visible = false;
barrier.visible = false;
barrier2.visible = false;
barrier3.visible = false;
barrier4.visible = false;
} else {
drawbackground();
player.visible = true;
platform.visible = true;
platform2.visible = true;
coin.visible = true;
livescoin.visible = true;
barrier.visible = true;
barrier2.visible = true;
barrier3.visible = true;
barrier4.visible = true;
}
if (lives <= 0) {
losebackground();
player.visible = false;
platform.visible = false;
platform2.visible = false;
coin.visible = false;
livescoin.visible = false;
barrier.visible = false;
barrier2.visible = false;
barrier3.visible = false;
barrier4.visible = false;
} else {
drawbackground();
player.visible = true;
platform.visible = true;
platform2.visible = true;
coin.visible = true;
livescoin.visible = true;
barrier.visible = true;
barrier2.visible = true;
barrier3.visible = true;
barrier4.visible = true;
}
playerColectCoins();
// update sprites
platformsMove();
moveCoinsback();
playerGravity();
movePlayer();
playerland();
barriers();
drawSprites();
}
// Create your functions here
function drawbackground() {
noStroke();
background(“skyblue”);
fill(“yellow”);
ellipse(350, 50, 50, 50);
textSize(20);
fill(“black”);
text(“Score :”, 10, 25);
text(score, 75, 27);
text(“Lives :”, 10, 45);
text(lives, 70, 47);
}
function winBackground() {
background(“purple”);
fill(“black”);
noStroke();
textSize(100);
text(“YOU”, 100, 100);
text(“WIN”, 120, 200);
}
function losebackground() {
background(“purple”);
fill(“black”);
noStroke();
textSize(100);
text(“YOU”, 100, 100);
text(“lose”, 120, 200);
}
function platformsMove() {
if ((platform.x) <= -40) {
platform.x = 440;
platform.y = randomNumber(200, 400);
}
if ((platform2.x) <= -40) {
platform2.x = 440;
platform2.y = randomNumber(200, 400);
}
}
function moveCoinsback() {
if ((coin.x) <= -20) {
coin.x = randomNumber(410, 600);
coin.y = 200;
}
if ((livescoin.x) <= -20) {
livescoin.x = 1000;
livescoin.y = 200;
}
}
function playerGravity() {
player.velocityY = player.velocityY + 0.25;
}
function movePlayer() {
if (keyDown(“up”)) {
player.velocityY = -5;
}
if (keyDown(“left”)) {
player.x = player.x - 4;
}
if (keyDown(“right”)) {
player.x = player.x + 4;
}
}
function playerland() {
player.collide(platform);
player.collide(platform2);
}
function playerColectCoins() {
if (player.isTouching(coin)) {
coin.x = randomNumber(410, 600);
coin.y = 200;
score = score + 1;
}
if (player.isTouching(livescoin)) {
livescoin.x = 1000;
livescoin.y = 200;
lives = lives + 1;
}
}
function barriers() {
if (player.isTouching(barrier)) {
player.x = 100;
player.y = 100;
lives = lives - 1;
}
if (player.isTouching(barrier2)) {
player.x = 100;
player.y = 100;
lives = lives - 1;
}
if (player.isTouching(barrier3)) {
player.x = 100;
player.y = 100;
lives = lives - 1;
}
if (player.isTouching(barrier4)) {
player.x = 100;
player.y = 100;
lives = lives - 1;
}
}