In the game MoleMash, a mole pops up at random positions on a playing field, and the player scores points by hitting the mole before it jumps away.
This project shows how to build MoleMash as an example of a simple game that uses animation.
Components from Media, Drawing and animation will be introduced.
Step 1: Design the layout
Tips for you to do the layout design:
Canvas is the area where the moles can move.
Two ImageSprites (mole, bomb) are the main characters of the game.
Two Labels (Score, Heart) shows the score and the lives you still have to try the game.
A Button (reset) to reset the game.
A Clock (behind the scene) to arrange for the mole to jump periodically.
Two Sound (move_sound, hit_sound) to be played during the game.
Step 2: Identify the procedures of coding the app
What do you want to achieve? There are several targets you should accomplish:
When the player hits the mole --------> Score will be added, the mole will go to another random position
When the player hits the bomb --------> Score will be decreased, the lives will be decreased.
When the lives become 0 --------> Game over. The game should be reset.
When the player click the "Reset" button -------> The game will be reset.
Target 1: When the player hits the mole ----------> Score will be added, the mole will go to another random position
1. We create a Procedure "mole_move" to control the movement of the mole.
(1) the mole should move in random position inside the canvas.
(2) when the mole move, it will play a sound of "move_sound".
Now try to finish the blocks on the right-hand-side.
2. Set up a global variable "score" to store the score. At the beginning, the score should be 0.
3. When the mole is touched, do the following items:
(1) play the sound "mole_sound"
(2) mole_move
(3) bomb_move
(3) the variable "score" adds 10
(4) show the score
Target 2: When the player hits the bomb --------> Score will be decreased, the lives will be decreased
1. We create another Procedure "bomb_move" to control the movement of the bomb by applying the above skills.
2. Set up another global variable "heart" to store the lives. At the beginning, the lives should be 5.
3. When the bomb is touched, do the following actions:
(1) play "bomb_sound"
(2) the variable "heart" minus 1
(2) show the lives
Target 3: When the lives become 0 --------> Game over. The game should be reset
If the lives become 0, the game will show a notification to users to ask them to reset the game.
Otherwise, the mole and the bomb will keep moving.
Target 4: When the player click the "Reset" button -------> The game will be reset
When the reset button is clicked, do the following actions:
(1) set the lives back to 5
(2) show lives
(2) set the score back to 0
(2) show score
Step 3: Can you modify your game?
Level 1:
Add more moles & bombs, some are boss moles for getting higher marks; some are bigger bombs for losing more marks.
Add a golden heart for gaining 1 extra life. The golden heart should appear anywhere at any time randomly.
Add a countdown timer for the game. Once time is up, the game is over. (tips: set up one more Clock component)
Add a screen to show the final mark.
Level 2:
Add a screen beforehead. Let the player choose the difficulty level.
From easy level to difficult level, the mole/bomb will change position sooner and sooner.
Maybe:
When the score is above 100, the mole will change its position every 0.85s (850 milliseconds);
When the score is above 200, the mole will change its position every 0.65s (650 milliseconds) .
The following blocks may help you: