Game Development Reference
In-Depth Information
Before you can do this, you have to extend the PaintCan class so that PaintCan objects know that
they need to have a target color when they fall out of the bottom of the screen. Painter8 passes
along this target color as a parameter when you create the PaintCan objects in PainterGameWorld :
this.can1 = new PaintCan(450, Color.red);
this.can2 = new PaintCan(575, Color.green);
this.can3 = new PaintCan(700, Color.blue);
You store the target color in a variable in each paint can, as you can see in the constructor of PaintCan :
function PaintCan(xPosition, targetColor) {
this.currentColor = sprites.can_red;
this.velocity = Vector2.zero;
this.position = new Vector2(xPosition, -200);
this.origin = Vector2.zero;
this.targetColor = targetColor;
this.reset();
}
You can now extend the update method of PaintCan so that it handles the situation where the paint
can falls outside the bottom of the screen. If that happens, you need to move the paint can back
to the top of the screen. If the current color of the paint can doesn't match the target color, you
decrease the number of lives by one:
if (Game.gameWorld.isOutsideWorld(this.position)) {
if (this.color !== this.targetColor)
Game.gameWorld.lives = Game.gameWorld.lives - 1;
this.moveToTop();
}
You might want to decrease the number of lives by more than one at some point. In order to facilitate
this, you can change the penalty into a variable:
var penalty = 1;
if (Game.gameWorld.isOutsideWorld(this.position)) {
if (this.color !== this.targetColor)
Game.gameWorld.lives = Game.gameWorld.lives - penalty;
this.moveToTop();
}
This way, you can introduce steeper penalties if you want to, or dynamic penalties (first miss costs
one life, second miss costs two, and so on). You could also imagine that sometimes a special paint
can falls. If the player shoots that can with a ball of the right color, the penalty for mismatching
paint-can colors temporarily becomes zero. Can you think of other ways in which you can deal with
penalties in the Painter game?
Search WWH ::




Custom Search