Let's figure out how to lose the game. Right now you can see what happens when you collide with something: something like
collision: function(other) {
other.center.y = this.center.y; // follow the player
other.center.x = this.center.x; // follow the player
}
Or something you've tricked out. How could we add a 'lose' state?
First: the alert
function. This pops up one of those annoying boxes you
have to click okay.
collision: function(other) {
// this line pops up a window that says 'you lose'
alert('you lose!');
// this one stops the game
this.c.ticker.stop();
// this is like hitting refresh in your browser
location.reload();
}
Next: you've added bonus characters to your game. Right now running into them just makes you grab them and take them with you. Let's turn them into power-ups that help you run faster.
First question: how fast can you run? You've already figured this out, and already changed it!
if (this.c.inputter.isDown(this.c.inputter.LEFT_ARROW)) {
// move by 2 pixels!
this.center.x -= 2;
}
Let's say 2 pixels are the speed. Now how do we make power-ups make us faster?
Well, we've been doing things with the collision
function - how about putting
it in there?
First - a person needs to have a speed to start out. First find the line that says
this.size = { x:9, y:9 };
Let's add a speed:
this.size = { x:9, y:9 };
this.speed = 2;
Cool! Now let's use it a little:
if (this.c.inputter.isDown(this.c.inputter.LEFT_ARROW)) {
// move by 2 pixels!
this.center.x -= this.speed;
}
And finally, let's increase it when you collide with something:
collision: function(other) {
this.speed = this.speed + 2;
}