This article entails the 12 easy steps on how to create a Pacman game in Scratch.
The article shows the different guidelines and steps used for creating a Pacman game on Scratch. These simplified steps make it very easy to understand.
Games are an important factor necessary for the daily amusement of kids and teens. A child tends to be very happy when he or she plays any kind of game. With the aid of games, kids are very delightful and strategic; it can also be used as a leisure time during busy hours for parents.
GET IN TOUCH
Your Kids Deserve More
Kids can also learn how to create or make a Pacman game following these step-by-step processes. Using these steps or procedures your kids can master the art of creating a Pacman game or any other game without stress and a lot of effort.
As we all know, Scratch is a programming language and an online community where children can program and share interactive media such as animation, stories, games etc with people from all over the world. A Pacman game is a maze action video game whereby the yellow, pie-shaped Pac-Man character travels around a maze trying to eat the dots, avoiding four hunting ghosts.
The background of a scratch app and Pacman game will be displayed below:
Scratch is categorized into three sections:
We shall be looking at the scripts and its component which we will be making use of
The scripts contain various items called ‘blocks”, the blocks are used essentially for coding; with the aid of these blocks under the category of the scrips, you can create a well-coordinated design on your scratch application. We shall be looking at the various scripts, blocks and functions.
There are nine(9) scripts on the Scratch application. These scripts are:
- Motion- it is used for the movement of the sprites
- Looks- it has to do with the physical appearances of the sprites, language, costumes etc
- Sounds- it has to do with the rhythmical functions, making various kinds of music
- Events- this allows the sprites to take in different kinds of actions
- Control – it governs, directs and determines the sprite activities
- Sensing- this has to do with the logical reasoning, colours of the sprite
- Operators- this contains mathematical quotations used while creating a code.
- Variables- this contains characters, and quotations necessary for coding.
- My Blocks- this is used in creating more blocks for your commands.
Also, it is worth noting that the script performs the same function for both the sprites and the background.
As seen in the diagram above, we shall be looking at the simplified step-to-step approach to creating a Pacman game on Scratch.
12 easy steps on how to create a Pacman game on Scratch
1. CHOOSE A BACKDROP
The backdrop is more of a background for the game, it displays the stage where the game ought to take place. By default when you click on “Choose a Backdrop”, different backgrounds/backdrops will be shown; your backdrops can be created/designed or they can be saved and imported into your scratch.
A sample will be displayed below:
Select “Convert to Bitmap”, it automatically converts to bitmap for the purpose of editing and adding different features. This is a sample of the backdrop, for the purpose of learning; you can save and import this to your scratch application which is ready to be used.
After doing this, we design a backdrop for “Game Over”, which is very essential during this game. Using the same paint tools, we create a design.
2. DRAW THE SPRITES
There are 3 sprites required in a Pacman game, although it can be more than 3; it is effective when 3 sprites are being used in creating a Pacman game.
- Pacman sprite
- Ghost sprite 1
- Ghost sprite 2
The Pacman is the sprite that eats up the dots and serves as the player while the Ghost sprites stand as obstructions to the Pacman from taking in the dots.
This sprite is called the Pacman sprite
6 simple steps on how to create a Pacman of your choice.
- Select a sprite by clicking on the icon “Choose a Sprite”, and .select “Paint”, it automatically takes you to the section called ‘Costume’ where you will be able to create your design
- Select “Convert to Bitmap” for the purpose of your creation
- Select the circle shape, place it on the background, select the eraser, and take away some lines in the circle, more of creating a shape of a semicircle
- Select your line shape, create a semi-circle, and apply colour by selecting your colour paint
- To create a shape for the eyes, select the square-like shape, place it in front of the PacMan created and then apply any kind of colour for the shape.
- You have successfully created a PacMan
For your Ghost sprites, make use of the same format, adding your own design and templates.
This is called the Ghost sprite 1
This is called Ghost sprite 2
We shall also bring out the dots sprites as shown on the first image which serve as food or meal for the Pacman, we shall be using two different kinds of dots; bonus and dots which will be placed in several parts of the backdrop otherwise called a background.
This is called “Dot backdrop”
It looks very tiny during your design but clear when placed on the backdrop, the same applies to both the dot and bonus.
3. CREATE A VARIABLE FOR ‘SCORE’ AND ‘HIGH SCORE’
A variable is a quantity that can assume any set of values, therefore we shall create a variable of the score and high score, in which each score is seen on the ‘score’ button and the highest goal points reflects on the ‘High Score’ button, the ‘variable’ can be gotten from the variable block inside the ‘Script’ category. Here is a sample:
4. MOVEMENT OF THE PACMAN AND DIRECTION CHANGES
The game becomes useless if the Pacman does not move or change directions, the excellency of the game is concerned with the movement of the sprites, the Ghost and Pacman sprites. For such to happen, we need to write down a code. The codes are as follows:
Move to your “Event” block, pick up ‘When the green flag clicked
Move unto ‘Control’ and get your “Forever” block for the continuous movement of every action taken
Using the arrow keys, the sprite gets direction and also changes movement using 0,180,90,-90 as its directional module.
5. GIVING THE PACMAN ABILITY TO EAT
In order for the Pacman to take in the dots or bonus otherwise called eating the dots, we create a code creating an ability for the Pacman sprite to be able to eat which enables the increase in scores.
‘Events’, click on ‘when green flag clicked’
Move to ‘Control, bring out the ‘Forever’ block
‘Looks’, bring out Switch costume to …’
Also, add your ‘Wait’ block giving time 0.3sec for a proper code
Below is a sample:
6. WHEN PACMAN TOUCHES THE MAZE WALL
In order to make the game a creative one, make sure that whenever the Pacman touches the maze wall, it should go back to its starting point; i.e whenever and wherever the Pacman touches the maze wall, it should be redirected to its starting point.
Bring in your ‘When the green flag is clicked’
Forever block gotten from ‘Events’
‘Wait until’ block gotten from ‘Control’
‘Point in Direction’ gotten from ‘Motion’
‘If then else ‘ block gotten from ‘Control’
‘Color touching colour’ gotten from ‘Sensing’
‘Move 2 steps’ gotten from ‘Motion’
These steps help u in making a code to prevent the Pacman from jumping over the maze wall.
The codes for this action are given below:
Do the same for the up and down arrow keys.
7. ADDING A SCORE WHEN THE PACMAN TAKES IN A DOT OR BONUS
It is very important to add scores when the Pacman has taken in any dots or bonuses. The dots serve as a meal for the Pacman, therefore, as soon as the Pacman eats any dots, a score should be added. The score always depends on the range of values you choose.
Bringing out your blocks, ‘When the green flag is clicked,
wait 0.4-sec blocks;
The next is your sound, this gives a ‘bite’ sound; when the Pacman takes in any dots, it immediately makes a sound. The ‘Sound is gotten from the sound block, to pick a sound of your choice; select the ‘sound’ section, click ‘Choose a sound’ different kinds of sounds automatically display
Select the ‘Dot sprite and make this code as shown above.
8. CHANGING THE COLOR OF THE GHOST
In order to make the game look more attractive to kids, we change the colour of the ghost while in movement, this initiates the ability for the ghost to change its colour while moving around the maze wall.
The code for this activity is given below:
‘When the green flag is clicked’ gotten from the ‘Control’ block
‘Show’ gotten from Looks’ block
; Forever’ gotten from ‘Control’ blocks
‘Switch costume to’ gotten from ‘Looks’
‘Wait 0.3 sec’ gotten from ‘Control’ block
The combination of these blocks gives you a code.
9. MOVEMENT OF THE GHOST
The movement of the ghost sprites is a very essential factor in the Pacman game, the movement of the ghost]t creates a barrier for the Pacman to eat its meal. When the ghost comes in direct contact with the Pacman, the Pacman utterly disappears which means a Game is Over.
Add the Glide 1 sec to x:___ & y:___ block from Motion blocks multiple times to make sure that the ghost is moving on a fixed path. Your x and y values will be automatically present when you pull out the blocks, as they will be the coordinates of the current location of your ghost sprite.
Below is the code for the movement of the ghost sprites:
Repeat this code for the other ghost sprite, making use of different numbers for the x axis and y axis
The blocks ‘go to x: y:’, ‘glide… secs to x: y: ‘ is gotten from the script ‘motion’
10. MAKE PACMAN DIE WHEN CAUGHT BY A GHOST
The code used for creating this action is very important, to make your game more creative and sensible, make a code in which the Pacman disappears when it comes in contact with the ghost sprite displaying a game over text.
The codes are understandable and comprehensible when followed outrightly.
To get the ‘and’ block, ‘=’ block, move to the script called ‘Operator’, every mathematical function contained in each block is found in the script.
11. BRINGING OUT THE GAME OVER AND CHANGING ITS BACKDROP
When the life from the variable block equals zero, we input the Game Over text on the background, also changing the background/ backdrop
12. RESET YOUR MAZE PLAYGROUND
To play as many games as you want, it is ideological that your maze game is reset.
Begin with ‘When the green flag is clicked from the ‘Event’ block; to move back to the previous backdrop, insert ‘switch backdrop to’…, and the ‘Show ‘ block from ‘Looks’
From the motion block, pick out the ‘Go to x: … y … block, also ‘Point in direction 90’; the numbers show up automatically reflecting the current position of your sprite.
Adding variables ‘Lives’ and ‘Scores’ from your variable block. For life, input 3 and score, type in 0.
Below is the code for this action
You have successfully created a Pacman game using Scratch. You can also add any other features you wish to in order to make the game more fun.
To learn more on Scratch and other games that can be invented through Scratch or any other application; if you wish to train your kids on coding, how to make games, programming or any other coding activities
Contact Imagine Stem Academy.