game creation
collision detection
the importance of design
pseudocode
using a forever loop
Watch the screencast on the right and do your own maze. You can upload the maze background from here, or you can paint your own maze in Scratch.
Then, create your own maze, using a picture off the internet or your own drawing. Make sure the picture you download or draw features solid colors - not gradients or shadows, otherwise wall collision will not work properly.
Afterwards, do Extension 1 and Extension 2 from "Starting from Scratch" (p. 25).
Extension 3:
When finished, add another level to your game: when the sprite reaches the other sprite, it will display "Level 2" (You can do this through a new background. Then display a different maze, one's that's more difficult than the first one and program it the same way as the first one.
Extension 4 (revised):
When the sprite touches the wall, the sprite will, instead returning to the initial position, back up 10 steps (or whatever number of steps it would go forward).
Extension 5 (revised):
Add the two player capability to your maze. Use another sprite for the second player; also use another set of keys (not the arrows) for the movement of this sprite. Make sure the sprites say hello to each other when they meet in the maze. Whichever sprite comes to rescue the friend first, wins.
Read pp. 31-34 of "Starting from Scratch" and fix the mistakes the programmer has made. (We will do this activity together)
Create another maze, similar to the first one. When the sprite touches the wall, play a sound effect and flash the screen (by changing the scene background back and forth).
Introduce "tokens" to collect in your maze. Every time it "collects" a token, it makes it disappear and increases the score by one. When the hero hits the wall, decrease the score by 1.
The code on the right-hand side determines what happens every time you decide to create a clone. It is important that the clones each have their own unique location in the maze - otherwise, you'd end up with 10 tokens on top of each other. While choosing the location, though, it is important not to position the clones on the wall or so that they are on top of each other or just overlapping. For this we have the "repeat until" loop which keeps looking for the right position for the token until it finds one where the token is not touching the wall {color blue in my example} and is not touching the other tokens {in my example color orange}.
You can remove the wait block - it is there for demonstration purposes only for you to see how the token keeps changing its location until one is found that meets both conditions mentioned above.
Create a little quiz game, where the sprite will ask you 3 questions about himself. When you answer the question correctly, then say "Good!" and increase the score by 1. Otherwise, just say "No!".
This should get you started (it doesn't, though, keep track of the score):
We will improve on our maze and turn in into a Pacman game.
Search the Scratch gallery for "Pacman" and check out the different implementations of the perennial classic {here's a good example}.
Start working on your own Pacman game - you will need the game backdrop - you can either draw your own or use an existing one {you will have to either draw your own maze, the main character or the tokens by yourself using the built-in Scratch vector editor};
Create the Pacman character - you can either draw your own or use an existing one - there should be two costumes for Pacman - open and closed mouth.
Add the movement functionality to Pacman (with the use of arrows).
Add wall collision detection (like you did in one of the extensions in the previous unit - when it senses the wall, it will back up a couple steps).
Create a score variable and set it to zero to begin with.
Create a token that will be collected by Pacman when it touches it (i.e. the token will disappear). This will increase the score by one.
Duplicate the token and position the duplicates in the various parts of the maze.
Create a variable that will hold the lives of Pacman. Set it to 4 initially.
Create an enemy that will be running back and forth across the maze. If it touches Pacman, he will lose a life. After he lost all lives, display "You're dead!" and end the game.
Display the "You got them all!" message after Pacman has eaten all the tokens and end the game. The easiest way to find out how many tokens Pacman has eaten is to use the score variable.
If you want to create your tokens in a more sophisticated way, you will want to use the so called cloning: