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
Um... snakes.

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

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

5
00:00:11,160 --> 00:00:13,110
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 set up the basics:

8
00:00:20,590 --> 00:00:24,390
We can build a replica of Pac-Man's Maze, have the player control a yellow circle, and create

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

10
00:00:28,910 --> 00:00:31,320
If these are present, we can already have 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 swallow it by making it grow.

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

14
00:00:39,620 --> 00:00:42,489
by one unit for every point spent, but we have too many pellets

15
00:00:42,489 --> 00:00:45,820
in Pac-Man, the tail would very quickly get out of control.

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

17
00:00:49,070 --> 00:00:51,770
"What kind of tiles are those?" you ask.

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

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

20
00:00:58,940 --> 00:01:03,620
Each tile has its own properties; some are obstacles, others are walkable, one contains our main character

21
00:01:03,620 --> 00:01:07,760
and others their enemies and the small dots that our yellow companion nibbles on.

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

23
00:01:11,150 --> 00:01:12,950
So keep it in mind.  Let's

24
00:01:12,950 --> 00:01:13,950
see.

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

26
00:01:18,430 --> 00:01:22,780
That's actually quite interesting, Waka Waka, so it's actually a Snake game, Waka Waka,

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

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

29
00:01:30,190 --> 00:01:34,920
I think it's time to introduce the very famous Ghost Gang.

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

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

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

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

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

35
00:01:52,340 --> 00:01:55,880
And Clyde, the orange ghost, "the 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, they have different goals; they are targeting different tiles as their

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

39
00:02:06,740 --> 00:02:11,700
As a result, the ghosts seem to behave like a team that harasses and corners Pac-Man.

40
00:02:11,700 --> 00:02:15,760
Before we develop the specific behaviors of each mind, there are a few things they

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

42
00:02:16,760 --> 00:02:20,060
The ghosts behave according to one of three possible modes:

43
00:02:20,060 --> 00:02:24,920
They can chase Pac-Man, they can scatter, and they can scare each other.

44
00:02:24,920 --> 00:02:29,359
All ghosts switch between these states simultaneously, constantly changing

45
00:02:29,359 --> 00:02:34,079
between scatter and pursuit modes every few seconds, and can abruptly jump into fear mode

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

47
00:02:39,060 --> 00:02:43,030
's leave the last one for later, since we don't yet have the cookies our friend needs to

48
00:02:43,030 --> 00:02:44,620
chug to trigger this behavior.

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

50
00:02:47,550 --> 00:02:53,019
In scattered mode, each spirit travels to a specific corner and remains there to wander around

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

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

53
00:03:00,439 --> 00:03:03,489
located outside the maze and are therefore unreachable.

54
00:03:03,489 --> 00:03:08,079
The motivation behind this behavior is to give the player some space to

55
00:03:08,079 --> 00:03:11,150
temporarily reduce stress and to give the feeling that tension comes in waves.

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

57
00:03:15,670 --> 00:03:18,700
goal space, naturally avoiding obstacles along the way.

58
00:03:18,700 --> 00:03:23,170
At this point, we nerds will probably spend some time developing an algorithm to find

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

60
00:03:27,079 --> 00:03:31,540
the mind, only then realizing that Pac-Man .  That's not how it 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 it happened to me... of course...

63
00:03:37,329 --> 00:03:43,879
These wild, lawless spirits don't take the shortest route in the original game.

64
00:03:43,879 --> 00:03:48,379
They try, but aren't clever enough, so sometimes they take longer routes.

65
00:03:48,379 --> 00:03:53,400
One might be tempted to correct this in a new game, but how minds change is a big part

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

67
00:03:58,530 --> 00:04:02,379
Apparently, a ghost at an intersection 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 step.

70
00:04:09,249 --> 00:04:12,790
This approach means that they don't always take the best path.

71
00:04:12,790 --> 00:04:18,840
See this example: Blinky is approaching an intersection; it must consider four adjacent tiles.

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

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

74
00:04:25,380 --> 00:04:29,360
Therefore, only the distance to the destination from the left and

75
00:04:29,360 --> 00:04:31,720
right of the intersection needs to be calculated.  Let

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

77
00:04:34,920 --> 00:04:40,440
Then a straight line from the left tile to the goal is shorter than one

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

79
00:04:41,720 --> 00:04:44,350
Therefore, Blinky takes the path to the left.

80
00:04:44,350 --> 00:04:50,260
However, this is not faster in terms of the number of steps or the time it takes to reach the destination.

81
00:04:50,260 --> 00:04:54,420
This pathfinding technique applies to any case in which a mind needs to move towards a goal

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

83
00:04:55,420 --> 00:04:59,310
From this we will develop the next movement behavior: the tracking mode.

84
00:04:59,310 --> 00:05:02,690
What a spirit does in hunting mode is what truly defines it.

85
00:05:02,690 --> 00:05:07,410
As in the scattered 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 field where Pac-Man is located.

88
00:05:14,060 --> 00:05:19,940
The pink ghost, very cleverly called "Pinky" in English, is considered an ambush; its target tile

89
00:05:19,940 --> 00:05:24,130
is four spaces in front of Pac-Man's direction, meaning it usually hits Pac-Man from the front

90
00:05:24,130 --> 00:05:25,970
.

91
00:05:25,970 --> 00:05:31,440
Inky is the light blue ghost; this one is more unpredictable. Personally, I find it

92
00:05:31,440 --> 00:05:34,910
similar to Pinky, but in a larger area.

93
00:05:34,910 --> 00:05:39,220
Inky's target is found by drawing a line between Blinky's position and the tile two cells in front of

94
00:05:39,220 --> 00:05:44,570
Pac-Man, and then extending that line to twice its length;  Inky's goal is to reach the end of this new segment

95
00:05:44,570 --> 00:05:46,470
.

96
00:05:46,470 --> 00:05:48,020
We finally 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.

99
00:05:57,430 --> 00:06:03,620
The orange ghost, like Blinky, aims at Pac-Man, but when he gets too close, he disappears,

100
00:06:03,620 --> 00:06:06,710
scatters in his home corner, and returns later.

101
00:06:06,710 --> 00:06:10,970
These behaviors have many specific considerations that I won't explain here, but I will share one

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

103
00:06:12,140 --> 00:06:17,150
In the original Pac-Man game, there was a bug that caused Pinky's and Inky's goal tokens to

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
These were shifted significantly to the left.

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

107
00:06:27,140 --> 00:06:32,392
because they have a significant impact on the ghosts' movement behavior, especially for experienced players.

108
00:06:32,400 --> 00:06:35,420
So, scattering and hunting, checked.

109
00:06:35,420 --> 00:06:39,630
We can now return to the frightened state in which 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 erratically and randomly choose their

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

112
00:06:45,890 --> 00:06:50,270
.  Our snake-like Pac-Man can also swallow them up in this state and make them run to their tiny

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

114
00:06:52,770 --> 00:06:58,550
.  Speaking of tiny homes, there's one in my heart too, and you can earn a place by

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

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

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

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

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

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

121
00:07:13,400 --> 00:07:17,920
Back to the game, to the VIP room that 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
In summary, Inky gets out when 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 developed features, I think that's enough about the ghosts, although we'll have to come back to them in a moment

126
00:07:30,270 --> 00:07:34,390
, we need to investigate whether we need to adjust their behavior due to our new game mechanics

127
00:07:34,390 --> 00:07:37,810
: making Pac-Man grow a tail.

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

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

130
00:07:45,640 --> 00:07:47,030
My mouth, of course.  Take a look at

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

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

133
00:08:06,508 --> 00:08:09,319
Ah, that's so silly, I love it.  OK OK!

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

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

136
00:08:13,960 --> 00:08:16,490
We just need to tweak a few things before we end the game loop.  Let's

137
00:08:16,490 --> 00:08:20,930
return to optimizing the behavior of the ghosts.

138
00:08:20,930 --> 00:08:25,280
The original instructions could cause the ghosts to move in a direction

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

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

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

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

143
00:08:36,979 --> 00:08:40,909
This is the approach I have pursued up to this point, because of its simplicity, which

144
00:08:40,909 --> 00:08:44,169
has proven to be rather boring.

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

146
00:08:48,829 --> 00:08:52,430
Another alternative is to get the ghosts to completely ignore the tail so they

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

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

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

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

151
00:09:02,949 --> 00:09:05,620
"Alternative 3: The Rope Jump"

152
00:09:05,620 --> 00:09:12,790
It would be interesting to allow the ghosts to skip the tile occupied by the tail and jump directly to the next one

153
00:09:12,790 --> 00:09:14,170
.

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

155
00:09:18,631 --> 00:09:22,980
we want the ghost to jump over the rope and not crash into a wall.

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

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

158
00:09:32,959 --> 00:09:38,009
This is what I enjoyed the most, and we keep it by simply letting the mind bounce off the snake's tail

159
00:09:38,009 --> 00:09:42,890
and running in the opposite direction to how I would in real life.

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

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

162
00:09:50,839 --> 00:09:53,220
, but I couldn't find anything concrete.

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

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

165
00:09:59,350 --> 00:10:03,180
I want to do something similar with the effect of the power pellets, essentially

166
00:10:03,180 --> 00:10:06,790
influencing the Snake part of the game as well.

167
00:10:06,790 --> 00:10:08,509
We can try out many things here as well.

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

169
00:10:13,600 --> 00:10:17,300
allowed the player to mechanically walk over the tail for the duration of the effect.

170
00:10:17,300 --> 00:10:18,540
The results?

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

172
00:10:19,699 --> 00:10:22,560
The game is much more fun now.

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

174
00:10:26,389 --> 00:10:29,920
However, at this point the game is (technically) infinitely difficult.

175
00:10:29,920 --> 00:10:34,260
Because there are two ways to lose: the ghosts and the tail;  But there's no way to win...

176
00:10:34,260 --> 00:10:38,580
You can snort all the cookies, but nothing will happen.

177
00:10:38,580 --> 00:10:42,999
To incorporate more Snake mechanics, I made this game endless by re-

178
00:10:42,999 --> 00:10:45,709
producing all the breadcrumbs when the floor is completely vacuumed.

179
00:10:45,709 --> 00:10:48,300
The goal is then to get as many points as possible.

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

181
00:10:51,649 --> 00:10:56,540
I built it exactly like in Pac-Man, except for an additional reward when a "level"

182
00:10:56,540 --> 00:10:57,540
is completed.

183
00:10:57,540 --> 00:11:01,190
You earn points by eating cookies, power pellets, ghosts, and... fruit!  That

184
00:11:01,190 --> 00:11:06,120
's right, there are also fruits; they appear from time to time in the middle of the labyrinth.

185
00:11:06,120 --> 00:11:12,319
There are no real fruits, there's a can of cola, a cocktail, pancakes, a loaf of bread,

186
00:11:12,319 --> 00:11:13,319
and a...

187
00:11:13,319 --> 00:11:14,319
Galactic Boss?

188
00:11:14,319 --> 00:11:18,779
Incidentally, these are not the same in different versions of Pac-Man; I am using the graphics

189
00:11:18,779 --> 00:11:20,589
from Pac-Man Plus.  The one where

190
00:11:20,589 --> 00:11:27,290
they decided that frightened ghosts should have a leaf on their heads...

191
00:11:27,290 --> 00:11:28,290
yes...

192
00:11:28,290 --> 00:11:31,779
You may have noticed that I've never taken the path to the tunnel before.  There's

193
00:11:31,779 --> 00:11:34,379
a reason for that.

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

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

196
00:11:44,050 --> 00:11:48,790
I had to revise the technical functionality of the tail to support disjoint parts.

197
00:11:48,790 --> 00:11:52,339
As the character traverses the tunnel, a new section is created on the other side; this new section

198
00:11:52,339 --> 00:11:56,329
grows while the old one shrinks, giving the impression that the tail teleports

199
00:11:56,329 --> 00:11:58,160
through the tunnel along with the character

200
00:11:58,160 --> 00:12:02,869
.  And having only two rear sections is not enough; it is actually possible to

201
00:12:02,869 --> 00:12:07,460
go through the tunnel an unlimited number of times while the previous split is still in progress, because

202
00:12:07,460 --> 00:12:10,600
we can climb over the rear after a power-up.

203
00:12:10,600 --> 00:12:16,660
This edge case drove me crazy, but I think I've cracked it. Let me know if (or when) you

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

205
00:12:18,529 --> 00:12:19,779
And... oh!

206
00:12:19,779 --> 00:12:22,129
I believe the game is feature-complete at this point.

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

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

209
00:12:27,410 --> 00:12:30,759
By the way, I couldn't find a cool name for the game, so I decided to

210
00:12:30,759 --> 00:12:33,220
upload it with a placeholder and ask for your help.

211
00:12:33,220 --> 00:12:36,720
If a funny title came to mind while watching the video, feel free to leave it in

212
00:12:36,720 --> 00:12:37,720
the comments.

213
00:12:37,720 --> 00:12:41,160
I will take the most popular suggestion and update the game's name accordingly.

214
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 me

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

216
00:12:46,740 --> 00:12:49,720
The game is now uploaded, the link is in the description, check it out.

217
00:12:49,720 --> 00:12:53,339
It was a lot of fun to play.  So if you're looking for a terrible game

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

