Game Development Reference
In-Depth Information
In order to temporarily display the arrow, you reuse the
VisibilityTimer
class from the Jewel Jam
game. You create an instance of this class and add it to the game world as well:
this.hintVisible = new VisibilityTimer(hint);
playingField.add(this.hintVisible);
You also add a button that the player can click to display the hint on the screen:
this.hintButton = new powerupjs.Button(sprites.button_hint, ID.layer_overlays);
this.hintButton.position = new powerupjs.Vector2(916, 20);
this.add(this.hintButton);
Finally, you extend the
handleInput
method of
Level
to deal with the Hint button being pressed:
if (this.hintButton.pressed)
this.hintVisible.startVisible();
The Hint button can only be pressed if it's visible, which in some cases it shouldn't be:
After the player makes the first move, the Hint button should disappear, and the
Retry button should appear.
If the player chose to switch off hints in the Options menu, the Hint button
should never be visible.
For the first case, you need to keep track of when the player makes their first move. You add an
extra member variable
firstMoveMade
to the
Level
class. When you give an animal a velocity, this is
done in the
AnimalSelector
class. Once the player has clicked an arrow and the animal is moving,
you set the
firstMoveMade
variable to
true
:
this.selectedAnimal.velocity = animalVelocity;
this.root.firstMoveMade = true;
Second, you have to handle the Hints setting from the game Options menu. You do this in the
update
method of the
Level
class. You simply check what the value of the Hints setting is in the
GameSettings
variable, and update the Hint and Retry button visibility state accordingly:
this.hintButton.visible = GameSettings.hints && !this.firstMoveMade;
this.retryButton.visible = !this.hintButton.visible;
As you can see from these two lines of code, the Hint button is visible only if
GameSettings.hints
is
true
and the player has not yet made a first move. The Retry button's visibility status is always the
opposite of the hint button's visibility status. So if the Hint button is visible, the Retry button isn't,
and vice versa.
Resetting the Level
After a player moves a couple of animals around, it can happen that the level can't be solved
anymore. Instead of having to quit and restart the game, let's give the player a means to reset a level
to its initial state.
Search WWH ::
Custom Search