I completed the melonjs platformer tutorial http://melonjs.github.io/tutorial-platformer/. And I had a question on advancing forward. I feel the next most important part of the game would be a win condition and a satisfying failure condition. So like "if you collect all the coins you win" or "you simply get to the end of the game" does anyone know a way to add that sort of victory condition?
As for a failure condition is there a way to give multiple lives where you put a few pictures of the sprite in the bottom left that are removed every time an enemy hits you or when you hit certain collision markers like in a pit. And would it be easier to end the game if you lose and make them start over?
Does anyone have an example in code of a victory or defeat condition using melonjs?
--
You received this message because you are subscribed to the Google Groups "melonJS - A lightweight HTML5 game engine" group.
To unsubscribe from this group and stop receiving emails from it, send an email to melonjs+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
For example you can use the hud to display the number of lives remaining similar to how the tutorial shows the score for the number of coins collected.
Inside HUD:
/*init*/
this.score = -1;
this.lives = -1;
/*update*/
if (this.score !== game.data.score) {
this.score = game.data.score;
return true;
}
if (this.lives !== game.data.lives){
console.log("Updating lives");
this.lives = game.data.lives;
return true;
}
/*Draw*/
this.font.draw(context, game.data.lives, 40, 40); //Top left corner
Then when you hit an enemy you decrease that information inside the game.data, in this tutorial you'd add the logic inside game.PlayerEntity in the init you would add an initial value such as 'game.data.lives = 3'
then inside onCollision for types.ENEMY_OBJECT you can use something like
if(!this.renderable.flickering){
game.data.lives = game.data.lives-1;
if(game.data.lives === 0){
//Player lost, reset game//
game.data.score = 0;
me.levelDirector.loadLevel('area01');
}
}
this.renderable.flicker(750);
I also used a bottom collision object to reset the player and score if they fell off the platforms.
You can do similar things with winning conditions too, like Jay posted earlier you can have goal collision areas or using the game.data like how this tutorial uses game.data.score to track the score from coins, just use logic inside the coin collected collision method to perform an action like displaying an end screen.
--
You received this message because you are subscribed to the Google Groups "melonJS - A lightweight HTML5 game engine" group.
To unsubscribe from this group and stop receiving emails from it, send an email to melonjs+unsubscribe@googlegroups.com.