Score and lives Debugging

Can you help this student please?
1- She wants to remove the lives and score from the start screen.
2-She wants the score to go up by 1, when the rabbit is touching the carrot, yet she wants the carrot to continue following the rabbit to the basket.

Thank you.

// Create your variables here
var SCORE = 0;
var background = createSprite(200, 200);
background.visible = false;
;
var pressenter = createSprite(200, 200);
pressenter.setAnimation(“press enter.png_1”);
pressenter.visible = true;
pressenter.scale = 1.45;
;
var collect = createSprite(200, 300);
collect.setAnimation(“collect”);
collect.visible = true;
collect.scale = 0.6;
;
var ledge = createSprite(230, 289);
ledge.setAnimation(“ledge”);
ledge.scale = 0.1;
ledge.visible = false;
;;
var basket = createSprite(345, 45);
basket.setAnimation(“basket”);
basket.scale = 0.15;
basket.visible = false;
;
var bunny = createSprite(30, 350);
bunny.setAnimation(“bunny1_1”);
bunny.scale = 0.45;
bunny.visible = false;
;
var carrot = createSprite(20, 180);
carrot.setAnimation(“carrot”);
carrot.scale = 0.45;
carrot.visible = false;
;
var carrot2 = createSprite(380, 140);
carrot2.setAnimation(“carrot2”);
carrot2.scale = 0.45;
carrot2.visible = false;
;
var carrot3 = createSprite(275, 200);
carrot3.setAnimation(“carrot3”);
carrot3.scale = 0.45;
carrot3.visible = false;
;
var carrot4 = createSprite(120, 290);
carrot4.setAnimation(“carrot4”);
carrot4.scale = 0.45;
carrot4.visible = false;
;
var carrot5 = createSprite(165, 170);
carrot5.setAnimation(“carrot5”);
carrot5.scale = 0.45;
carrot5.visible = false;
;
var carrot6 = createSprite(100, 95);
carrot6.setAnimation(“carrot6”);
carrot6.scale = 0.45;
carrot6.visible = false;
;
var carrot7 = createSprite(240, 365);
carrot7.setAnimation(“carrot7”);
carrot7.scale = 0.45;
carrot7.visible = false;
;
var carrot8 = createSprite(235, 90);
carrot8.setAnimation(“carrot8”);
carrot8.scale = 0.45;
carrot8.visible = false;
;
var carrot9 = createSprite(375, 290);
carrot9.setAnimation(“carrot9”);
carrot9.scale = 0.45;
carrot9.visible = false;
// Create your sprites here
function keys() {
if (keyDown(“enter”)) {
carrot.visible = true;
background.visible = true;
bunny.visible = true;
pressenter.visible = false;
collect.visible = false;
basket.visible = true;
carrot2.visible = true;
carrot3.visible = true;
carrot4.visible = true;
carrot5.visible = true;
carrot6.visible = true;
carrot7.visible = true;
carrot8.visible = true;
carrot9.visible = true;
ledge.visible = true;
}
}
function draw() {
// draw background
background.setAnimation(“carrots.jpg_1”);
background.scale = 1.2;

collection();
movingcharacters();
keys();
// update sprites

drawSprites();
textSize(20);
fill(“black”);
fill(“black”);
fill(“black”);
fill(“black”);
text(Math.round(-0.05 *World.frameCount+30), 90, 30);
;
text(“TIME:”, 30, 30);
;
text(SCORE, 109, 46);
text(“SCORE:”,30,30,225,100);
}

function movingcharacters() {
if (keyDown(“up”)) {
bunny.y = bunny.y - 1.5;
}
if (keyDown(“right”)) {
bunny.x = bunny.x + 1.5;
}
if (keyDown(“left”)) {
bunny.x = bunny.x - 1.5;
}
if (keyDown (“down”)) {
bunny.y = bunny.y + 1.5
}
}
function collection() {
if (bunny.isTouching(carrot)) {
carrot.y = bunny.y;
carrot.x = bunny.x;
SCORE = SCORE + 1;
}
if (bunny.isTouching (carrot2)) {
carrot2.y = bunny.y;
carrot2.x = bunny.x;
}
if (bunny.isTouching (carrot3)) {
carrot3.y = bunny.y;
carrot3.x = bunny.x;
}
if (bunny.isTouching (carrot3)) {
carrot3.y = bunny.y;
carrot3.x = bunny.x;
}
if (bunny.isTouching (carrot4)) {
carrot4.y = bunny.y;
carrot4.x = bunny.x;
}
if (bunny.isTouching (carrot5)) {
carrot5.y = bunny.y;
carrot5.x = bunny.x;
}
if (bunny.isTouching (carrot6)) {
carrot6.y = bunny.y;
carrot6.x = bunny.x;
}
if (bunny.isTouching (carrot7)) {
carrot7.y = bunny.y;
carrot7.x = bunny.x;
}
if (bunny.isTouching (carrot8)) {
carrot8.y = bunny.y;
carrot8.x = bunny.x;
}
if (bunny.isTouching (carrot9)) {
carrot9.y = bunny.y;
carrot9.x = bunny.x;
}
if (carrot.collide(basket)) {
carrot.visible = false;
}
if (carrot2.collide(basket)) {
carrot2.visible = false;
}
if (carrot3.collide(basket)) {
carrot3.visible = false;
}
if (carrot4.collide(basket)) {
carrot4.visible = false;
}
if (carrot5.collide(basket)) {
carrot5.visible = false;
}
if (carrot6.collide(basket)) {
carrot6.visible = false;
}
if (carrot7.collide(basket)) {
carrot7.visible = false;
}
if (carrot8.collide(basket)) {
carrot8.visible = false;
}
if (carrot9.collide(basket)) {
carrot9.visible = false;
}
if (bunny.collide(ledge)) {
bunny.bounceOff(ledge);
}
}

Hi Anisa,

There are a couple things that she should think about.

First, the start screen tutorial that I shared with you might help her with hiding the score until the game has started. The simpler way that will help her in her game is to have a variable called “showScore” or something along those lines that starts off as “false” but is set to “true” when she starts the game by pressing enter. Then, instead of straight up displaying the scoreboard in the draw loop, put the code that displays it into a conditional that checks for the value of the “showScore” variable.

Right now her method for increasing the score will make the score continue to go up because the rabbit continues to touch the carrot. There are two ways to solve this problem. The first (“correct”) way is to have a variable or property of the carrot set such that each carrot can only increase the score one time. That would be complicated. There is a second (“hacky”) way that will work better for her in this game. Just reset the score to zero at the beginning of the “collection” function. That means that every time the draw loop runs, it will reset the score to zero, then add a point for every carrot the bunny is currently touching. Since the bunny carries around all the carrots it has ever collected, that should give you the right score.

Also, the start/end screen should help her to make an end screen that will show when the time hits zero. She could also possibly set the timer to start when she hits enter by saving the starting framecount into a variable, then subtracting that from the World.frameCount before she does the multiplication on it.

Cool game!

Elizabeth

1 Like

Thank you Elizabeth! This makes sense. I’ll work with her tomorrow to debug and put these functions in place.

Elizabeth,

It kind of worked; now if we press enter the time shows up, but it we let go of the key, it disappeared and the score won’t show up.

Thank you!