1
00:00:00,480 --> 00:00:03,220
Do you know what's missing from Pac-Man?

2
00:00:03,220 --> 00:00:05,690
Ahm... snakes.

3
00:00:05,690 --> 00:00:08,930
What's missing from Snake games?

4
00:00:08,930 --> 00:00:11,160
Ghosts.

5
00:00:11,160 --> 00:00:13,110
So if...

6
00:00:13,110 --> 00:00:18,619
"I added a tail to Pac-Man"

7
00:00:18,619 --> 00:00:20,590
The first step is to establish the basics:

8
00:00:20,590 --> 00:00:24,390
we can build a copy of Pac-Man's maze, make the player control the yellow circle, and

9
00:00:24,390 --> 00:00:28,910
add the very suspicious-looking trail of cookies our friend is addicted to.

10
00:00:28,910 --> 00:00:31,320
With that in place, we can already have a little fun.

11
00:00:31,320 --> 00:00:34,590
You know, Pac-Man is just a snake, but without a tail,

12
00:00:34,590 --> 00:00:37,329
so we can torture it by making it grow.

13
00:00:37,329 --> 00:00:39,620
In the Snake games, the tail grows by one unit for

14
00:00:39,620 --> 00:00:42,489
every dot eaten, but in Pac-Man we have too many pellets

15
00:00:42,489 --> 00:00:45,820
and the tail will get out of control very quickly.

16
00:00:45,820 --> 00:00:49,070
So I increased the tail length by one bar for every few cookies eaten.

17
00:00:49,070 --> 00:00:51,770
"What are these tiles?"  - you ask?

18
00:00:51,770 --> 00:00:56,760
You see, the landscape in Pac-Man and most Snake games is defined as a set of atomic units of

19
00:00:56,760 --> 00:00:58,940
space that we call "tiles."

20
00:00:58,940 --> 00:01:03,620
Each tile has its own properties, some are obstacles, others can be walked on, one depicts our main

21
00:01:03,620 --> 00:01:07,760
character, and others depict their enemies, as well as small dots that our yellow brethren chew on.  The

22
00:01:07,760 --> 00:01:11,150
next parts of the game will be defined around this invisible grid.

23
00:01:11,150 --> 00:01:12,950
So keep that in mind.

24
00:01:12,950 --> 00:01:13,950
Let's take a look.

25
00:01:13,950 --> 00:01:18,430
Waka waka waka, let me make some sound effects since we don't have any yet.

26
00:01:18,430 --> 00:01:22,780
It's actually quite interesting, waka-waka, so it's really a snake game, waka-waka,

27
00:01:22,780 --> 00:01:26,850
but with some limitations due to obstacles, waka.  The

28
00:01:26,850 --> 00:01:30,190
only way to lose at this stage is to bite your tail.

29
00:01:30,190 --> 00:01:34,920
I think it's time to introduce a very famous gang of ghosts.

30
00:01:34,920 --> 00:01:36,210
Introducing...

31
00:01:36,210 --> 00:01:40,820
Blinky, the red ghost, "hunter" and leader of the pack.

32
00:01:40,820 --> 00:01:46,390
Pinky, the pink ghost who "ambushed" the car, also known as "Speedy," although he is not faster than

33
00:01:46,390 --> 00:01:47,390
the others.

34
00:01:47,390 --> 00:01:52,340
Inky, blue and "unpredictable", the one that requires more math to develop.

35
00:01:52,340 --> 00:01:55,880
And Clyde, the orange ghost, "a special, special boy."

36
00:01:55,880 --> 00:02:01,160
So yes, in case you didn't know, Pac-Man's ghosts have personalities.

37
00:02:01,160 --> 00:02:05,740
Technically speaking, they have different targets, they target different tiles as their

38
00:02:05,740 --> 00:02:06,740
targets.

39
00:02:06,740 --> 00:02:11,700
As a result, the ghosts seem to act as a team, chasing Pac-Man and cornering him.

40
00:02:11,700 --> 00:02:15,760
Before we get into the specific behavior of each ghost, there are a few

41
00:02:15,760 --> 00:02:16,760
common traits.

42
00:02:16,760 --> 00:02:20,060
Ghosts act in one of three possible modes:

43
00:02:20,060 --> 00:02:24,920
they can chase Pac-Man, they can run away, and they can be scared.

44
00:02:24,920 --> 00:02:29,359
All ghosts cycle through these states simultaneously, constantly switching between

45
00:02:29,359 --> 00:02:34,079
dispersal and pursuit modes every few seconds, and can suddenly go into fear mode

46
00:02:34,079 --> 00:02:39,060
if the player eats a power pellet, those big cookies in the corners of the maze.

47
00:02:39,060 --> 00:02:43,030
Let's leave that last one for later, since we don't yet have a cookie to

48
00:02:43,030 --> 00:02:44,620
drink to trigger that behavior.

49
00:02:44,620 --> 00:02:47,550
But we can already work on the other two.  While

50
00:02:47,550 --> 00:02:53,019
in the Disperse state, each ghost moves to a designated corner and remains there

51
00:02:53,019 --> 00:02:55,730
until the Chase mode is activated.

52
00:02:55,730 --> 00:03:00,439
This is achieved by assigning them different target tiles that are

53
00:03:00,439 --> 00:03:03,489
outside the maze and therefore inaccessible.

54
00:03:03,489 --> 00:03:08,079
The motivation for this behavior is to give the player some space, relieve stress for a moment,

55
00:03:08,079 --> 00:03:11,150
and let him feel that the tension comes in waves.

56
00:03:11,150 --> 00:03:15,670
Now we need a few seconds to understand how the ghost moves from its current tile to

57
00:03:15,670 --> 00:03:18,700
the target one, of course, avoiding obstacles.

58
00:03:18,700 --> 00:03:23,170
At this point, we nerds would probably spend some time developing an algorithm for finding the

59
00:03:23,170 --> 00:03:27,079
shortest path (with the fewest tiles between two points) that

60
00:03:27,079 --> 00:03:31,540
a ghost can move along, only to realize later that that's not how Pac-Man works and delete

61
00:03:31,540 --> 00:03:33,730
all our code.

62
00:03:33,730 --> 00:03:37,329
Not that that happened to me... of course...

63
00:03:37,329 --> 00:03:43,879
Those wild, lawless ghosts don't take shortcuts in the original game.

64
00:03:43,879 --> 00:03:48,379
They try, but they are not smart enough, so sometimes they choose longer routes.

65
00:03:48,379 --> 00:03:53,400
Some might be tempted to fix this in the new game, but the way the ghosts move is a big part of

66
00:03:53,400 --> 00:03:58,530
Pac-Man, so I decided this option should stay true to the original implementation.

67
00:03:58,530 --> 00:04:02,379
Apparently, when at an intersection, the ghost calculates the distance between each

68
00:04:02,379 --> 00:04:06,680
adjacent tile and the target tile, measured in a straight line.

69
00:04:06,680 --> 00:04:09,249
Whatever is closest will be the next move.

70
00:04:09,249 --> 00:04:12,790
This approach makes them not always choose the best route.

71
00:04:12,790 --> 00:04:18,840
Look at this example, Blinky approaches an intersection, he must take into account four adjacent tiles.

72
00:04:18,840 --> 00:04:23,390
The top and bottom are discarded immediately, the first one is its current position, and the

73
00:04:23,390 --> 00:04:25,380
second one is inside the wall.

74
00:04:25,380 --> 00:04:29,360
Thus, he only needs to calculate the distance to the target from the point to the left and

75
00:04:29,360 --> 00:04:31,720
right of the intersection.

76
00:04:31,720 --> 00:04:34,920
Let's say the target is here, this other tile.

77
00:04:34,920 --> 00:04:40,440
Then the straight line from the left tile to the gate will be shorter than the line starting from the

78
00:04:40,440 --> 00:04:41,720
right tile.

79
00:04:41,720 --> 00:04:44,350
So Blinky chooses the route to the left.

80
00:04:44,350 --> 00:04:50,260
However, it is not faster as measured by the number of steps or the time it takes to reach a goal.

81
00:04:50,260 --> 00:04:54,420
This method of pathfinding is used in every case when the ghost needs to move towards a

82
00:04:54,420 --> 00:04:55,420
goal.

83
00:04:55,420 --> 00:04:59,310
We will use it to develop the next movement behavior: chase mode.

84
00:04:59,310 --> 00:05:02,690
What a ghost does in chase mode really defines it.

85
00:05:02,690 --> 00:05:07,410
Like the scatter state, they target different tiles, but these are more interesting

86
00:05:07,410 --> 00:05:08,850
(for us nerds).

87
00:05:08,850 --> 00:05:14,060
Blinky is the pursuer, the red ghost's target is the tile on which Pac-Man is located.  The

88
00:05:14,060 --> 00:05:19,940
pink ghost, very cleverly named "Pinky" in English, is considered an ambush, with

89
00:05:19,940 --> 00:05:24,130
its target tile being four squares ahead of Pac-Man's direction, causing it to usually

90
00:05:24,130 --> 00:05:25,970
face Pac-Man from the front.

91
00:05:25,970 --> 00:05:31,440
Inky is a blue ghost, this one is more unpredictable, I personally feel like he's

92
00:05:31,440 --> 00:05:34,910
similar to Pinky but on a wider range.

93
00:05:34,910 --> 00:05:39,220
To find Inky's target, draw a line between Blinky's position and the tile two spaces ahead of

94
00:05:39,220 --> 00:05:44,570
Pac-Man, then extend that line to double its length;  The end of this new segment is

95
00:05:44,570 --> 00:05:46,470
Inca's goal.

96
00:05:46,470 --> 00:05:48,020
Finally we have Clyde.

97
00:05:48,020 --> 00:05:52,380
Yes, Clyde, translators stop trying at this point.

98
00:05:52,380 --> 00:05:57,430
As the name suggests, Clyde follows his own rules and doesn't really care about Pac-Man.  The

99
00:05:57,430 --> 00:06:03,620
orange ghost targets Pac-Man just like Blinky, but when he gets too close, he leaves,

100
00:06:03,620 --> 00:06:06,710
running off to his home corner and returning later.  There

101
00:06:06,710 --> 00:06:10,970
are many special considerations behind this behavior that I won't explain here, but I will share

102
00:06:10,970 --> 00:06:12,140
one that I find funny.  The

103
00:06:12,140 --> 00:06:17,150
original Pac-Man game had a bug where the Pinky and Inky target tiles would

104
00:06:17,150 --> 00:06:20,120
not follow their rules when Pac-Man looked up.

105
00:06:20,120 --> 00:06:22,920
They were significantly shifted to the left.

106
00:06:22,920 --> 00:06:27,140
As with the pathfinding algorithm, these issues still recur in Pac-Man clones,

107
00:06:27,140 --> 00:06:32,392
as they have a significant impact on ghost behavior, especially for experienced players.

108
00:06:32,400 --> 00:06:35,420
So, running and chasing, I checked.

109
00:06:35,420 --> 00:06:39,630
Now we can return to the frightened state where the ghosts turn blue and run away.

110
00:06:39,630 --> 00:06:44,210
They don't actually run away, they just move randomly, randomly choosing the next tile

111
00:06:44,210 --> 00:06:45,890
at each intersection.

112
00:06:45,890 --> 00:06:50,270
Our snake Pac-Man can also gobble them up in this state, forcing them to flee to his tiny

113
00:06:50,270 --> 00:06:52,770
home in the center of the maze.

114
00:06:52,770 --> 00:06:58,550
Speaking of tiny houses, I have one in my heart too, and you can earn a spot by subscribing

115
00:06:58,550 --> 00:06:59,550
to the channel.

116
00:06:59,550 --> 00:07:01,740
It was a forced transition.

117
00:07:01,740 --> 00:07:05,770
In fact, it would make me very, very happy, it warms my heart, it tickles my soul and so

118
00:07:05,770 --> 00:07:06,770
much more.

119
00:07:06,770 --> 00:07:09,590
But hey, only do it if you like the video, okay?

120
00:07:09,590 --> 00:07:13,400
If not, then I don't know, maybe you could leave a sarcastic like?

121
00:07:13,400 --> 00:07:17,920
Back to the game, about that VIP room the ghosts have, some of them are a bit lazy and

122
00:07:17,920 --> 00:07:20,190
stay inside for a while at the beginning of the game.

123
00:07:20,190 --> 00:07:24,180
To sum it up, Inky leaves after Pac-Man eats thirty cookies,

124
00:07:24,180 --> 00:07:25,520
and Clyde after ninety.

125
00:07:25,520 --> 00:07:30,270
All these features are developed, I think with the ghosts it's enough, although we will need to

126
00:07:30,270 --> 00:07:34,390
go back to them a little, we will need to study whether we need to adapt their behavior

127
00:07:34,390 --> 00:07:37,810
because of our new game mechanic: making Pac-Man grow a tail.

128
00:07:37,810 --> 00:07:40,600
But let's take a break for a second to do something stupid.

129
00:07:40,600 --> 00:07:45,640
I want to make sound effects, but using my most precious hole... My

130
00:07:45,640 --> 00:07:47,030
mouth, of course.

131
00:07:47,030 --> 00:07:50,440
Check out my very professional creative process.

132
00:07:50,440 --> 00:07:58,830
Waka-waka-waka-waka, oo-oo-oo-oo, nom nom nom.

133
00:08:06,508 --> 00:08:09,319
Oh, this is so stupid, I like it.

134
00:08:09,320 --> 00:08:09,820
GOOD-GOOD!

135
00:08:09,820 --> 00:08:12,040
Check it out, it's almost a game at this point.

136
00:08:12,040 --> 00:08:13,960
And believe me, it's not bad...

137
00:08:13,960 --> 00:08:16,490
We just need to tweak a few things before we finish the game loop.

138
00:08:16,490 --> 00:08:20,930
Let's get back to setting up ghost behavior.  The

139
00:08:20,930 --> 00:08:25,280
original instructions may tell the ghosts to move in a direction that is obstructed by

140
00:08:25,280 --> 00:08:26,890
Pac-Man's tail.

141
00:08:26,890 --> 00:08:29,270
What should we do then?

142
00:08:29,270 --> 00:08:33,729
"Alternative 1: Railroad Crossing"

143
00:08:33,729 --> 00:08:36,979
The most obvious choice is to simply make them wait until the train passes.

144
00:08:36,979 --> 00:08:40,909
This is the approach I have followed so far, due to its simplicity, which has proven to be

145
00:08:40,909 --> 00:08:44,169
quite boring.

146
00:08:44,169 --> 00:08:48,829
"Alternative 2: Stepping on the Hose"

147
00:08:48,829 --> 00:08:52,430
Another alternative is to make the ghosts ignore the tail completely, allowing them to

148
00:08:52,430 --> 00:08:54,829
disrespectfully step on it.

149
00:08:54,829 --> 00:08:57,290
I tried it quickly, but it feels weird.

150
00:08:57,290 --> 00:09:01,579
It's literally Pac-Man with the added difficulty of avoiding your own tail, making it

151
00:09:01,579 --> 00:09:02,949
insanely difficult to play.

152
00:09:02,949 --> 00:09:05,620
"Alternative 3: Rope Jump" It would be

153
00:09:05,620 --> 00:09:12,790
interesting to allow ghosts to skip the tile occupied by their tail and

154
00:09:12,790 --> 00:09:14,170
move straight to the next one.

155
00:09:14,170 --> 00:09:18,631
The problem with this approach is that it only makes sense at full 4-way intersections, since

156
00:09:18,631 --> 00:09:22,980
we want the ghost to jump over the rope and not hit the wall.

157
00:09:22,980 --> 00:09:28,569
Unfortunately, there are only six of them in the labyrinth, so it’s not worth trying.

158
00:09:28,569 --> 00:09:32,959
"Alternative 4: The Freak Out"

159
00:09:32,959 --> 00:09:38,009
This is the one I found the most fun and the one we keep by simply having the ghost bounce

160
00:09:38,009 --> 00:09:42,890
on the snake's tail while running in the opposite direction, like I would do in real life.

161
00:09:42,890 --> 00:09:45,380
It's simple, but also effective.

162
00:09:45,380 --> 00:09:50,839
I thought about trying more unique approaches, like making the ghosts push or

163
00:09:50,839 --> 00:09:53,220
split the tail somehow, but I couldn't think of anything concrete.

164
00:09:53,220 --> 00:09:56,709
If you have any interesting ideas, please share them in the comments.

165
00:09:56,709 --> 00:09:59,350
This type of change helps to unite the two games.

166
00:09:59,350 --> 00:10:03,180
I want to do something along the same lines with the power pellets effect, essentially

167
00:10:03,180 --> 00:10:06,790
make it affect the Snake part of the game as well.

168
00:10:06,790 --> 00:10:08,509
We can also try a lot of things here.

169
00:10:08,509 --> 00:10:13,600
I decided to temporarily make Pac-Man smart enough to not bite his own tail,

170
00:10:13,600 --> 00:10:17,300
mechanically allowing the player to climb over the tail for the duration of the effect.

171
00:10:17,300 --> 00:10:18,540
Results, achievements?

172
00:10:18,540 --> 00:10:19,699
Approved!

173
00:10:19,699 --> 00:10:22,560
The game has become much more enjoyable.

174
00:10:22,560 --> 00:10:26,389
It's not as frustrating, I feel like I have more control over the character.

175
00:10:26,389 --> 00:10:29,920
However, at the moment the game is (technically) infinitely complex.

176
00:10:29,920 --> 00:10:34,260
Because there are two ways to lose: ghosts and tail;  but there is no way to win...

177
00:10:34,260 --> 00:10:38,580
You can sniff all the cookies, but nothing happens.

178
00:10:38,580 --> 00:10:42,999
To incorporate more mechanics from Snake, I made this game endless, re-spawning all the

179
00:10:42,999 --> 00:10:45,709
breadcrumbs once the floor is completely vacuumed.

180
00:10:45,709 --> 00:10:48,300
The goal is to score as many points as possible.

181
00:10:48,300 --> 00:10:51,649
And with that we move on to... the scoring system!

182
00:10:51,649 --> 00:10:56,540
I built it exactly like Pac-Man, except with an extra reward when the "level"

183
00:10:56,540 --> 00:10:57,540
is cleared.

184
00:10:57,540 --> 00:11:01,190
You get points by eating cookies, pellets, ghosts and... fruits!

185
00:11:01,190 --> 00:11:06,120
Yes, there are fruits too, from time to time they appear in the center of the maze.

186
00:11:06,120 --> 00:11:12,319
Actually, it's not fruit, there's a can of cola, a cocktail, pancakes, a loaf of bread

187
00:11:12,319 --> 00:11:13,319
and...

188
00:11:13,319 --> 00:11:14,319
the Galaxy boss?

189
00:11:14,319 --> 00:11:18,779
By the way, these are not the same in different versions of Pac-Man, I use the graphics of

190
00:11:18,779 --> 00:11:20,589
one called Pac-Man Plus.

191
00:11:20,589 --> 00:11:27,290
The one where they decided that scared ghosts should have a leaf on top of their heads...

192
00:11:27,290 --> 00:11:28,290
yeah...

193
00:11:28,290 --> 00:11:31,779
You might have noticed that I haven't followed the path to the tunnel yet.

194
00:11:31,779 --> 00:11:34,379
There is a reason for this.

195
00:11:34,379 --> 00:11:38,231
Designing this should be as easy as teleporting Pac-Man from one end to the other, but our

196
00:11:38,231 --> 00:11:44,050
yellow pie-shaped character is long, which makes it difficult.

197
00:11:44,050 --> 00:11:48,790
I had to redo the technical work on the tail to maintain the presence of separate parts.

198
00:11:48,790 --> 00:11:52,339
As you pass through the tunnel, a new part is created on the other side, this new part

199
00:11:52,339 --> 00:11:56,329
grows, and the old one shrinks, creating the impression of the tail teleporting through the

200
00:11:56,329 --> 00:11:58,160
tunnel along with the character.

201
00:11:58,160 --> 00:12:02,869
And having only two tail parts is not enough, in fact, you can go through

202
00:12:02,869 --> 00:12:07,460
the tunnel an unlimited number of times as long as the previous split is still ongoing, because

203
00:12:07,460 --> 00:12:10,600
we can step over the tail after chewing the bonus.

204
00:12:10,600 --> 00:12:16,660
This edge case was driving me crazy, but I think I got it working, let me know if (or when) you

205
00:12:16,660 --> 00:12:18,529
find a bug.

206
00:12:18,529 --> 00:12:19,779
And... oooh!

207
00:12:19,779 --> 00:12:22,129
I believe the game is over at this point.

208
00:12:22,129 --> 00:12:26,410
So I finished it off by adding some visual effects and a game over screen, balancing the difficulty

209
00:12:26,410 --> 00:12:27,410
and so on.

210
00:12:27,410 --> 00:12:30,759
By the way, I couldn't come up with a cool name for the game, so I decided to upload

211
00:12:30,759 --> 00:12:33,220
it with a placeholder and ask you for help.

212
00:12:33,220 --> 00:12:36,720
If you came up with a funny name while watching the video, feel free to leave it in the

213
00:12:36,720 --> 00:12:37,720
comments.

214
00:12:37,720 --> 00:12:41,160
I'll take the suggestion I like best and update the game's title with it.

215
00:12:41,160 --> 00:12:45,430
Giving you free input is probably a terrible idea, but I will trust you, please don't make

216
00:12:45,430 --> 00:12:46,740
me look like a fool.

217
00:12:46,740 --> 00:12:49,720
The game is downloaded, the link is in the description, go check it out.  It

218
00:12:49,720 --> 00:12:53,339
turned out to be a lot of fun to play, so if you were looking for a horror game...

219
00:12:53,339 --> 00:12:54,790
check out my previous video.

