JavaScript Introducing JavaScript Finishing the Game Wrapping It Up

Nour El-din El-helw
Nour El-din El-helw
8,228 Points

Trying to improve the game we made

I tried to use the ideas to improve the game that the instructor gave us but i think i messed a lot of stuff up : 1- i tried to display lives but it still displayed score. 2- i tried to use the lives system but now when the player touches any object(except the platform of course) the game crashes. thx for ur answer advance

Steven Parker
Steven Parker
170,317 Points

You forgot to show your code. Please make a snapshot of your workspace and post the link to it here.

2 Answers

John Bastian Bolhano
John Bastian Bolhano
4,799 Points

Crashed is caused by line 79 in game.js, you had a spelling error you wrote cuurentLife it should be currentLife

if (currentLife === losingLife) {
    player.kill();
}

in line 124 and 125 you had this

text = game.add.text(16, 16, "SCORE: " + currentScore, { font: "bold 24px Arial", fill: "white" });
    text = game.add.text(200, 16, "LIVES: " + currentLife, { font: "bold 24px Arial", fill: "white" });

your variable text has two assignments one for SCORE and for LIVES, try making a variable for each like this then add it two the update function below

textScore = game.add.text(16, 16, "SCORE: " + currentScore, { font: "bold 24px Arial", fill: "white" });
textLives = game.add.text(200, 16, "LIVES: " + currentLife, { font: "bold 24px Arial", fill: "white" });

function update() {
    textScore.text = "SCORE: " + currentScore;
    textLives.text = `LIVES: ${currentLife}`;
}

in line 71 and 72 you had this code

  } else if (item.key === 'poison') {
     currentScore = currentLife - 1;

what happens here every time you grab the poison the currentScore is decreased by one and not the life try changing it to this

  } else if (item.key === 'poison') {
     currentLife = currentLife - 1;

if you try to collect all the coins and the star your score will 105 and the game won't do anything since you have set winningScore = 100; so in line 76 try doing this one

   if (currentScore >= winningScore) {

this will make the badge appear if the score is equal or greater than 100

Hope my solutions helps and enjoy learning :D

Nour El-din El-helw
Nour El-din El-helw
8,228 Points

Hey thx but why did u put currentLife after a dollar sign and between brackets like that ${currentLife}

John Bastian Bolhano
John Bastian Bolhano
4,799 Points

ah right, that is an ES6 syntax, you will learn that in future lessons, it is way more convenient writing it that way XD. it is basically just

textLives.text = "LIVES: " + currentLife ;