How to code a ScratchJr Pac-man Game

Here is a walkthrough video of the Pac-Man game made in ScratchJr on the iPad – the step by step ScratchJr tutorial is further down the page.

How to make a Pac-man game in ScratchJr PDF guide

Here is a downloadable pdf which includes the ScratchJr code blocks for each feature of the game.

Additional video tutorials to help code the Pac-man game in ScratchJr

These quick tip videos may also help:

How to create & code a basic joypad (up, down, left, right) in under 2 minutes

How to create & code an advanced joypad (jumping & shooting) in under 4 minutes

How to create and code a countdown timer in ScratchJr in under 1 minute

How to rename, save, share via email & airdrop a ScratchJr file in under 1min

Please email me on the contact details at the bottom of the page if you would like me to send you the ScratchJr file for this game – WordPress does not let me upload this file format here 🙂

Step by step video tutorial ‘How to make a Pac-man game in ScratchJr’.

Here is the step by step tutorial and resources to allow you to create and code your own Pac-man Game in ScratchJr on your mobile device.

How to make a Pac-man game in ScratchJr video transcript:

Intro

0:00[Music]

0:11hello everyone and welcome back in this video I’m going to take you step by step and click by click and show you

0:17everything you need to do to create a Pac-Man game in scratch Jr on your mobile device I’m going to show you how

0:24to make a custom background how to create ghosts to Auto navigate The Maze and then reset back to their original

0:30position I’m going to show you how to make a joyad to control Pac-Man I’m going to show you how to make an auto updating scoreboard and also going to

0:37show you how to make a countdown timer in addition to this I’m also going to show you how to create two end screens a

0:42game over screen and a winner screen I’ll also show you how to increase the

0:47difficulty of the game by speeding up and slowing down the ghosts all you need to achieve any of this is the free

0:53scratch Junior app on either your phone or tablet to get the best results from this video follow along on either a t TV

1:00tablet phone or any screen which you can access YouTube and pause after each step I highly recommend you go through this

1:06video first step by step and actually make the game yourself then watch the video again with the child you’re

1:12teaching this will make it easier for you to guide them cuz you’ll be familiar with the steps this video is 100% child

1:18friendly with no band language or inappropriateness I will be sharing this actual video with the parents carers and

1:23children in my class if you do need any extra help or have any questions please leave a comment below or VI the contact

1:30details on my website email me and I will answer you as quickly as I can okay let’s start by opening:

Step 1: How to customise a background in ScratchJr

1:37scratch creating a new project first job let’s

1:42delete scratch the cat and now let’s go to the select background button go to

1:48our custom background and the paint function so we want to create a

1:54background that has two sections the game playay section which will be black and an area where we can put the

1:59scoreboard board and also the joyad so let’s go to our crate square or

2:04rectangle button there we’re already selected black so let’s start the top

2:09corner here come all the way down and I want about

2:16five squares at the bottom of the joyad and scoreboard area

2:22great now let’s go to the fill button and there we go so we’ve created two

2:27sections in our background now what we want to do is create some walls and boundaries in the game so that it’s a

2:34maze like effect and Pac-Man can wander around gobbling up gold coins and

2:40avoiding the ghosts so I go again to my square or rectangle creation tool this

2:46time we’re going to use like a blue color I want to make the line slightly thicker I’m going to start here

2:54create rectangle goes from there to there I can actually use this

3:00this to move it up slightly we go so you can use this pointy tool here

3:08to move objects once you’ve created them I’m going to create another one over

3:13here oh undo that let’s turn that off so I need to go back to this

3:23tool there we go fantastic and one across the top should be a bit easier to draw so I can see

3:31it nice i’ got to move that slightly across actually there we

3:37go one on the

3:43bottom like that great now I want to put

3:49um some lines here another one here obviously if you

3:56want to be super lining things up you can use the squares to count I’m not in this

4:01case’s put there great put

4:07[Music] one there lovely let’s go here as

4:15well here as well and let’s have something I think

4:20will be quite good if we can have it just here let’s go here again

4:31there we go so now we’ve got some walls and boundaries for Pac-man to navigate

4:37around while they’re collecting the gold coins and avoiding the ghosts so I press

4:42tick to select that and there is our background area we can see have a look at our full screen you got the game

4:48playay area there and an area at the bottom where we can put our joyad and also and also a

4:54scoreboard next we’re going to create our Pac-Man character so I’m going to go to our plus character option I’m going


Step 2: How to create the Pac-man character in ScratchJr

5:00to go to select a blank screen and then I’ll paint option so that we can create

5:06our own character Pac-Man is a fairly simple character it’s going to be a circle that’s yellow then I’m going to

5:13cut out a bit for the mouth so first of all let’s go to our Circle creation function and

5:18yellow let’s make Pac-man there let’s fill that and now I need to cut a piece

5:27out to be the mouth now I can’t actually do that in this paint function but what I can do is go to the triangle function

5:34select black I create a triangle I’ll use this

5:39button here to spin it like this I’m then going to move it

5:47into this area here and fill it now you can see that the triangle is sticking

5:53out slightly but once I add that because there’s a black background and that

5:59white line is only because it’s selected it will look like Pac-Man with their

6:06mouth open so let’s make it a bit smaller so we go to our purple category go to our shrink

6:12option I think that’s a good size there and there we have our Pac-Man

6:18character next I’d like to create the ghost character so again I go to our plus character button go to the blank

Step 3: How to create the Pac-man ghost characters in ScratchJr

6:25option and click on the paint function this will allow me to draw for the ghosts now the ghosts are essentially a

6:32circle on top of a rectangle so the colors are red so the first one’s going

6:37to be red so again I go to my circle function create a circle then what I’m going to do is go to my rectangle

6:44function and try to line this up best I can that’s not great let me

6:51have one more go of that that’s

6:57better there we go and I’m going to fill that so there’s the ghost outline shape and

7:03let’s add some eyes so I’m going to go to the white op white color again circle

7:09make a circle there and fill that click on the Arrow so I can move it

7:19so there and now I’m going to create a second

7:24eye needs to be a bigger let’s try again perfect or close close

7:31[Music] enough click on

7:36it it to move it looks a bit wonky but hey that’s all

7:42good and now I’m going to create the pupils so they’re going to be in

7:48black and another

7:56one and I’m going to move them both

8:07amazing a little fiddly but hey there’s my first ghost fantastic now notice the

8:12ghost is selected so it’s got a white line around it and Pac-Man now has the white line removed cuz it’s not selected

8:19and it really does look like it’s mouth open which is fantastic I’m going to shrink this ghost

8:25now to that size and I’m going to move it into area where they’re going to start

8:32fantastic so now I need to make three more ghosts significantly easier made making a second one once You’ made one

8:39because you just go to the plus character button you add you sorry you select the one you’ve already created go

8:45to paint and we’re just going to change the color so the next one’s going to be like a pink color let’s try that

8:52one and we fill it there we go again shrink it

9:01so it’s the same size great again go to the plus go to the pink ghost we just created next one’s going to be like an

9:08aqua color which is this one

9:14select shrink that some move it into the

9:19area across a little bit we try one more in there so go to the plus button again

9:25select the one we’ve already created go to the paint option this one’s going to be orange

9:32and I’ve done a little tiny bit of research and these seem to be the classic arcade

9:38colors of oh of the

9:44ghosts there we go and there’s my our ghost and our Pac-Man character now we need to code The Ghost and Pac-Man we’re

9:51going to start with the ghosts because what we want them to do is basically move round on a cycle so they just

9:58continuously moving around in a cycle navigating around the walls and the

10:03obstacles so first I’m going to code the Red Ghost I’m going to put the gridon it makes it a bit easier

Step 4: How to code the red ghost character from Pac-man in ScratchJr

10:10to assign numbers to our movement blocks I want the Red Ghost to go up and round

10:16and then loop around this little island here so I’m going to click on the Red Ghost first of all I want it to start

10:24moving on the green flag first thing I want it to do is go up so I it’s currently at 11 I want it

10:31to go up to 13 so that’s 2 cuz 11 + 2 is 13 I then want it to go across from 9 to

10:407 so that’s left two and then when it’s come back down to in line here so it can

10:48go around the island so that’s going to be down to 12 so it’s going to go down

10:54one so that is the first path I want it to take so let’s test that

11:00fantastic so it successfully goes around that initial wall there so let’s reset so check one more time great from here

11:07what I want it to do is to go across from seven to two so it’s going

11:15to go across five now I’m not going to collect that at the moment cuz I’m going to put it in a loop a repeat Block in a moment

11:21so I want it to go across 5 then go from 12 to 9 so it’s going to

11:30go down three I then want it to go back across

11:36to five CU where it started and then go up three to where it

11:45is and continue in that Loop so let’s have an up and a three so let’s go from here see

11:52what happens brilliant so it does it starts

11:58where it starts it does a whole loop with avoiding all the walls so what I now want to do is put that into a repeat

12:06block that’s not quite added that one so let’s just drop it in so here we can see

12:11it repeats this piece of code so it initially executes this one and then repeats this so let’s reset the ghost to

12:18where it starts oh let’s move this to there and just for now let say repeat

12:24four times see what happens okay so it goes up round br Brant and notice you

12:30can see the code executing as we go along brilliant that is absolutely

12:36fantastic and it should eventually stop great and what we can do there

12:45is if we go to this block here this block is the go

12:52home block so that should set it back to there and then we can say go forever so that means it will

13:00repeat that four times go home then go up and start again so let’s see that in

13:08action actually let’s stop that let’s just change that to two to save a bit of

13:14time right let’s go again so it’s going to do two of these Loops that’s

13:20one that’s two it goes home and then starts getting

13:27fantastic okay let’s stop that and reset so that’s exactly what we want the Red

13:32Ghost to do now like to code the orange ghost to do something similar but on this side so

Step 5: How to code the orange ghost character from Pac-man in ScratchJr

13:39let’s click on the orange ghost let’s get rid of that so again we want it to start on the green flag it’s currently

13:4611 we want it to go up to 13 so let’s go

13:51up two we then want it to go across from 12 to 14 so it’s going to go across

13:59cross two and then

14:05down one to 12 cuz it’s currently on 11 okay great so let’s just test that

14:11one brilliant it looks a little tight there doesn’t it so we’ve made that one

14:17a little bit too big so let’s try going down two see where it ends up oh and notice I

14:26accidentally pressed that green flag which started both of them if I just click this one here just test this piece of code

14:32here great so now what we want it to do is go

14:39across one two three four five squares now it might go

14:47um slightly over this island so we can move that in a minute in the background but let’s just try that now so I go

14:54across five so it’s from 14 to 19 then we want it to go down

15:00one which is fine let’s say down two so it avoids it then go back across

15:08five and then up two once you get these initial the first

15:14across and down U measurements correct the rest is just the opposite so let’s try

15:22that great try again fantastic we’re just going to have

15:27to need need to move that slightly down so let’s go to our background a second go to our paint to edit it we

15:38can there we go that is a little fiddly but we’ve got there so let’s click

15:47okay much better beautiful it clears it fantastic great so similar to last time

15:53let’s add the repeater block there to it uh connect that

15:59together put that on a two then let’s say go back to home and

16:06actually repeat that forever and let’s see what happens

16:14now brilliant it avoids all of the walls and then starts home

16:24again fantastic now we need to code the pink

16:29and aqua ghost we want them to the pink ghost to initially go up then go up and down up and down up and down so let’s go

Step 6: How to code the pink ghost character from Pac-man in ScratchJr

16:35to the pink ghost code P area green start on a

16:42green flag again so initially we wanted to go up let’s put the Grid on the grid turn

16:48off for some reason we want the ghost to go from 11 to

16:5314 so that’s three we then want it to come

17:01down from 14 to five so that’s nine and then we

17:07want it to go up nine so it’s going up and down so initially it will do that then it will

17:12do that so we want that repeat

17:21again and then to go home carry on so let’s try that

17:31okay so you can see there I’ve made an error of that code I didn’t change that it was the one it needs to be a nine

17:38let’s try

17:45again

17:51fantastic this is the last one and it should to go

17:56home great fantastic so let’s stop that

18:01there reset we can use this code again for the aqua one however we’re just

18:07going to swap one thing around we want the pink one to initially go up we want the aqua one to initially go down so

Step 7: How to code the aqua ghost character from Pac-man in ScratchJr

18:15let’s change that to a down movement block oh

18:29and we want it to go down from 11 to five which is

18:34six Let’s test

18:41that okay so also I’ve made the error there these two need to be the other way

18:46around because it’s going up before it goes down that’s why it’s always good to test the code let’s try

18:53again again I’ve pressed that one instead of this one here to test just that Aqua one on its own

19:09fantastic right that works great let’s make sure it Go returns home fantastic

19:14so going to stop that there let’s go full screen let’s test what happens when we press green so all

19:20the ghosts go at the same

19:26time brilliant we don’t the ghost to touch each other because we may use that code later to

19:35trigger an end screen brilliant okay stop that there

19:41then reset now we’re going to create the joyad that will control Pac-Man so let’s

Step 8: How to create and code a joypad in ScratchJr

19:46go to our create character button go to our blank character and the paint option

19:52we’re going to create a square I’m going to create it in

19:57purple there is a square let’s fill that and return to our screen and there

20:05it is if you’ve seen any of the other videos I’ve made you’ll know that we use

20:10the same template essentially to make them all the same size so we go back to our plus character

20:16button go to the character we’ve previously created go to the paint option and we’re going to do this one is

20:23going to be green I’m going to bring that down all

20:28these these colors are associated with the various send message functions we’ve

20:33got so again we go to that plus character button go to the character we’ve previously created go to the paint

20:39option this one’s going to be red that all the way to

20:47here then we’re going to go one more time plus character button to the red one we’ve previously created paint

20:54option and this one is going to be blue

21:00just line that

21:09up there we go now we’re going to code each of these buttons so we’re going to start with a purple button I’m going to

21:15go to the start on tap then we’re going to go to our send message and that’s

21:20going to be purple I like to associate the color of the message with the actual button makes a lot of sense to me I’m

21:27going to copy this code acoss Ross change that to Green Copy

21:35across change it to Red copy

21:42across change that to Blue now we’ve got all our buttons coded

21:49we have to code Pac-Man to react and move once these buttons are

21:56pressed so let’s go to Pac-Man let’s go to the receive message turn

Step 9: How to code Pac-man to move in ScratchJr via the joypad

22:03that one to purple another receive message turn that one to Green I like to essentially

22:09reflect the keypad setup that one to

22:15red and one more to Blue so when the red um when the sorry

22:22the purple button is pressed it sends a message that triggers

22:27an upwards movement when the red button is pressed it sends a message that triggers a right movement

22:34of one when the green button is pressed it triggers a send message that triggers

22:40a movement left and then finally when the blue button is pressed it triggers a

22:47message that triggers a movement of down let’s test

22:52this fantastic great let’s have a look at that on full screen

22:59so we can move Pac-Man left sorry right left down and up great

23:06stuff next we want to code the ghost so that if Pac-Man touches the ghost the game is over so first we’re going to

Step 10: How to code the ghost to trigger the ‘game over end screen’ if Pac-man touches them.

23:14create a second screen and end screen we’re going to delete cats there I’m

23:19going to create an custom background ENT it’s all going to be

23:26black and then what we going to do is I’m going to add a custom character

23:32which will be a big Pac-Man big

23:38Pac-Man let’s feel that and using the free line tool I’m going

23:45to draw a sad

23:56face fantastic let’s add some

24:06text game over as big as it can be in

24:12white there we go so let’s go back to our first screen let’s go back to one of

24:18our ghosts let’s add an extra piece of code so on bump I want

24:26the change screen scen function to be triggered and take us to the game over screen so let’s copy that onto the

24:36other ghosts let’s just check they’ve all got

24:42it they do let’s go full screen let’s press screen to start and let’s

24:50brilliant we run into one of the ghosts and it triggers the game over screen

24:56fantastic back to our original screen reset everything the last thing we need

25:01to do now for the basic version of the game is add some coins for Pac-Man to collect to do this I’m again going to go

Step 11: How to create and code the coins for Pac-man to collect.

25:07to my create character button go to blank character and paint I’m going to create some small white coins I was

25:15going to do them yellow but I think that would be slightly confusing with Pac-Man so I’m going to go to the circle function

25:22white create a small circle and fill that and press plus and

25:29there it is let’s put one here let’s

25:35add one so again we can use the same character each time let’s put one in

25:42this

25:47corner one in this

25:56corner one in this corner

26:04one in this

26:12corner on this

26:18corner one in this corner obviously you can add as many as

26:25you like

26:30I’m just going to add a few just for the benefit of the video there we go now we need to code these

26:37coins what we want the coins to do is disappear every time they are touched so

26:43we go to the yellow category on bump we want

26:50the coin to disappear what we’re also going to add is an orange send message

26:55we won’t need this now but this will allow us to create a scoreboard in the more advanced version so let me copy

27:02that across onto the other

27:09coins down a little

27:24bit there we go so let’s start our game let’s go across let me just see if this

27:31is actually yes that disappears fantastic see if I get across here great

27:36okay so let’s stop that reset Let’s Go full screen and let’s start our

27:50game oh game

27:56over and there you have your basic Pac-man game well done everybody congratulations you made a fully working

28:02version of Pac-man in scratch Jr on your mobile device now let’s look to add some additional Advanced features okay so now

28:09let’s make a scoreboard so first of all I’m going to go to the text function go to numbers and go zero space space and

Step 12: How to create and code a scoreboard in ScratchJr

28:16when I double space it does put a dot in for some reason so you just have to delete it and do it again space space

28:23again there it is so you double space this double space will allow the

28:30text to roughly fall into one digit per square which makes it easier to code the

28:37arrow that’s going to move across and Signal what the score is so we just keep

28:45going up to eight cuz we’ve got eight coins

28:54or there we go now I’m just going to change the text to White for now because it’s going to appear here and I won’t be

28:59able to see it otherwise so now let’s change that to Black and make it

29:07just second smallest and there we go we just put

29:13that thereit there

29:19actually great now I want to create an arrow that will point to the numbers as

29:25the coins are collected so I go to my plus character button go to the create character and

29:31paint St black let’s go to our triangle first of all it’s the top of the Arrow

29:37Head let’s a rectangle for the tail

29:42there we go let’s fill that fantastic and press plus there it is let’s bring

29:48it down to here let’s make that a bit

29:56smaller fit in great now what we want it to do is

30:03because we’ve coded our coins to send a message once they are touched and

30:08disappear we want our Arrow to receive that message which is orange and then

30:14move across one so let’s test that

30:21now now it’s not quite in line so let’s set it there a little bit

30:35let’s move it a touch

30:43more fantastic so it points to the numbers every time it moves along one square now what we want to do is when

30:50the scoreboard moves to eight we want that to trigger the screen to change to

30:56the winner screen so let’s first of all create a winner screen so let’s get rid of cat let’s again create a custom

31:09black screen now we want the character again

31:15so let’s go to our plus character paint option again let’s do Pac-man as a

31:20circle nice and big fill that again we’re going to go to

31:25our freehand draw function go to Black and let’s do a smiley

31:36face that doesn’t look great does it but let’s let’s try and improve that a little bit let’s do the eyes a bit

31:41better and then slightly thicker oh reset

31:55that great and now let’s put some

32:05text Winer up let’s make it white nice and

32:11big there we go excellent so let’s go back to our

32:18original screen we’ve got our Arrow there we now need an actual object that

32:23that Arrow will touch that will then trigger the winner screen to appear so let’s add another

32:31character we’re going to use one of our buttons let’s edit that let’s turn that

32:37white let’s turn that white there it is and I’m going to put

32:44that just there so what will happen is when that is touched and let’s make that

32:52a bit bigger we can see it there when that is

32:59touched it is going to trigger the Winner’s screen so let’s give that a test now so

33:08let’s go full screen oh no let’s reset first of all

33:13full screen and off we go let’s try and collect all of

33:25these oh game over let’s try

33:31again actually let’s move this along a little bit so that it triggers it when I only

33:37collect a few less of the um

33:44coins yeah there we go winner fantastic so let’s go back to here re

33:52set let’s move this all the way to there

33:58and there’s our scoreboard the last thing we want to do is add a timer in this corner here so when the time’s up

Step 13: How to create and code a countdown timer in ScratchJr

34:04the game is over so again we go to our plus character option go to the blank character and paint and we’re going to

34:10create first of all a red circle um to represent a clock let’s fill

34:16that okay that’s absolutely massive so let’s make that smaller and small enough to fit

34:22there there we go great now what we want to do is add

34:27an arrow we’ve already have made one so we can use that character again let’s go to our Arrow plus it now it’s a bit big

34:36so let’s make it smaller so it fits in and what we want is oh just deleted

34:46it I just moved it moved behind the red circle okay so let’s just test um what

34:54it looks like when it spins yeah great so that could slightly

34:59be down the touch cuz it spins from the center of the arrow and we want it to

35:04make it look as realistic as possible if it is a clock going round

35:11great just remove that remove that now we’re going to code the clock now the

35:16actual part we’re coding is the hand on the clock or the timer so what I’m going

35:21to do is I’m going to go to green flag to start because we want the the time to start as soon as the game starts

35:28we’re then going to ask it to rotate this direction here and every time it

35:34rotates it can the full Revolution is 12 rotations so we want it to wait let’s

35:40say 22 seconds each one so every one of these is a tenth of a second as I said

35:48it’s 12 movements for a full resol um Revolution so that will be 12 times and

35:56then once that is is over we want it to go to the game over screen which is number

36:02two cuz the time will be up so let’s give that a test Let’s Go full screen

36:07for this actually so you can see it’s starting to move the goes to move around looks great

36:15we can move Pac-Man if we want to collect

36:23some we need it there now nearly a full Revolution here we go

36:35and game over fantastic it worked let’s make that smaller again back to our

36:40original screen reset everything now before we test it in full screen the full game I’ll be honest this is a

36:45little tricky for me this game at this speed so what I’m going to do is I’m going to go to my ghosts and I’m going

Step 14: How to change the speed of the ghosts to increase or decrease difficulty

36:52to slow them down so this button here is a set speed button we can change the

36:58speed at the moment it’s the M mid middle speed there’s a fast and a slow setting I’m going to click it on slow

37:05and put it there and let’s just see what happens to this go compared to the others see it’s

37:13significantly slower so you can now change the diff level difficulty of the game so I’m

37:19going to stop that and reset I’m going to make them all slow

37:36there we go now let’s test this game full screen here we go great okay let’s get

37:43this one first see if we can hit that winner screen

38:05near there run out

38:13time let’s try one more time going a bit

38:24quicker oh

38:37let’s try again going a bit quicker

39:00it’s actually really really difficult but hey that’s the game guys well done

39:06everybody please let me know if you man managed to complete the game and access that window screen well done everyone

39:13congratulations and Well Done everyone for making a Pac-Man game in scratch Jr on your mobile device if you need any

Outro

39:20extra resources or need to contact me if you have any questions please visit my website link will be in the description

39:26below please also so share with me any versions of the games you’ve made I’d love to learn from what you’ve done

39:32thanks again for watching and I’ll see you next time bye

39:37[Applause] [Music]