If there is an arcade next to you Automatic machine Pac-Man, Ms. Pac-Man or something like that, then you are lucky, today they are in short supply. Even the very widely used 20 Year Reunion machines in which Ms. Pac-Man and Galaga, are not so common nowadays.
But to understand what's going on, it's enough to download a video from YouTube about one of these games and watch it for one minute:
You noticed. How does Pac-Man move smoothly and ghosts through the labyrinth? They slip so confidently and clearly.
This smoothness, as we will see, is an illusion, and that's not all. Here's another video from YouTube:
It is uploaded by Jamey Pittman, the author of the article Dossier on Pac-Man which became the source of much of the information about Pac-Man for my book. The video is rewound a bit to save you time. Look at him. Especially watch for Pac-Man and the red ghost (the manual says that his name is Blinky). Notice what happens around the fortieth second!
Have you seen? Pac-Man went through the red ghost without any problems! How did it happen? Is it possible to make this happen all the time?
Calm down, now I will explain everything, and yes, this is a constant behavior. If exactly fulfills Pittman's instructions on the first level, this will always happen.
What is " Sprite "?
Part of the two-dimensional graphics equipment used in games special graphic objects, which are called sprites. Perhaps you've heard this term in modern conversations about pixel graphics of characters.
But earlier the meaning of the term was different: it was designated as an independently moving graphic object that could be located anywhere on the screen, or over the rest of the graphics, called the background, or under her. The sprite is given the X and Y coordinates, the image and its color. They were often used for game characters, but also used as add-ons to the background and for other purposes.
Most systems supported several or (in the case of Galaga) a lot of sprites. They also had other names: Atari first called them "Player-Missile Graphics", and in the early Commodore documentation they were referred to as "M.O.B., Movable Object Blocks". However, almost everyone began to call them sprites.
The equipment of the arcade machine Pac-Man supports sprite graphics. It can display up to eight sprites on the screen at the same time, and this without using stunts with sweep lines. One of the sprites is the image of Pac-Man himself, plus four are used by ghosts. When Pac-Man eats the ghost, his eyes returning home use the ghost sprite.
Not everything that changes on the screen is a sprite. Another type of graphics used by the equipment of that time was the tile background . It was just a grid of individual graphic elements, stored in memory. When you change the contents of a memory area, a small portion of the screen corresponding to this part of the grid also changes immediately. Therefore, it's easy to work with these grids.
The points in the Pac-Man game are tiles (background tiles) erased when Pac-Man eats them. The flickering of the "Energizer", giving Pac-Man strength, is performed by staining these cells in black, and then in white every several frames. But these objects do not move, they can only be removed or replaced.
The problem with the characters' tile graphics is that it can not move smoothly. It is located on the grid, so a moving background object will not be able to move smoothly around the screen, as Pac-Man and ghosts do. It can only move between grid cells. It is impossible to move part of the grid space, it either is, or it is not.
Well, it's interesting. But what of it?
The Basics of the Pac-Man World
As a child, I wrote small games on Microsoft BASIC for my Commodore 64. This implementation of BASIC had problems. The programs were executed slowly and almost did not use the computer's stunning sound and graphics resources. If you wanted to do something with graphics and sound, you had to study mysterious technical commands for direct memory access called POKE, or learn how to write in machine code.
One of the outputs was the use of character objects instead of sprite graphics systems, like me Described above. Objects did jumps the size of a tile, but it was much easier to work with them. You could start creating a game using character graphics, and then, when the project was already big and serious, and he wanted to show people, switch to using hardware sprites.
The object in memory could still skip with the same Increment of eight pixels, but the player did not see it. All he saw was a flickering sprite image that could be larger than the character's tile and concealed what was really happening. Going to programming with the mind, you could interpolate the position of the sprite, so that its movement seemed smoother. If you did well enough, then the player never noticed the difference. Only you would have known the truth.
I guess you already guessed what I'm leading to. Because that's how the Pac-Man game was programmed .
In reality both Pac-Man and ghosts had two positions. This is the position of sprite graphics, smoothly moving across the screen, which the player sees. Such information is given to the player when he plays the game, but this is just a shadow, an illusion. If you want to understand how Pac-Man actually works, you need to look deeper.
"Behind the scenes" of the game Pac-Man also takes into account which character cells occupy Pac-Man and ghosts. On the screen there are no traces of these coordinates. I suspect that in the early stages of the development of Pac-Man, when experiments were conducted on gameplay, developers could draw tiles directly on the screen. Jamie Pittman found that these coordinates are used for the artificial intelligence of all ghosts, and they are also used to recognize all the collisions in the game.
To maintain this illusion, the game has to go on tricks. It tracks how far Pac-Man and ghosts have moved from their current cell to the subscription level, and switches them to a new position when they have moved far enough. A slightly faster object will have a speed that causes the cells to change a little more often.
These elements – grid coordinates, cell tracking and sprite position on the screen – create the illusion of a smooth movement. But from the game's point of view, the movement is exactly the same as in my case when I programmed the cell graphics of the characters on the Commodore 64.
Now we have all the information we need to understand how Pac-Man can go through ghosts.
Pac-Man collisions are recognized by comparing its grid coordinates to the coordinates of ghosts. If they are the same, then a collision occurs and one eats the other. If they are different, then there is no collision. That's all, no more, no less.
You can see that the reason for this decision is the speed of collision detection in the processor cycles. Each frame, he compares the numbers X and Y of the Pac-Man character to the numbers of each of the four ghosts. Due to this, he does not need to take care of distances and risky situations.
This grid (approximately) corresponds to the coordinate system of the tiles representing the real positions of the game characters. Collisions are considered exact coincidences of coordinates in the grid system. Collision detection uses this grid. The game registers a collision only when the coordinates of the tiles of both characters coincide. This means that they must occupy one grid cell.
The problem occurs when the positions of Pac-Man and the ghost moving towards each other are switched to the next cell in the same frame. Collision checking is performed after all objects have moved in the current frame. If Pac-Man goes to the Blinky cell, and Blinky goes to the previous Pac-Man in the same frame, an error occurs when recognizing the collisions. They changed places!
Since this is the only level of reality that really matters in the game, the visible does not matter to the player. Pac-Man and the ghost are just passing through, "disperse like ships in the sea."
Artificial intelligence (AI) in the game is deterministic in nature, so you can identify a pattern for repetition of behavior. Despite the fact that the time for the occurrence of a mistake with the passage through must be accurate to the frame, the player does not have to be accurate to the frame if he follows the rules for executing Pac-Man traffic patterns. That's how Jamie Pittman's video was recorded.
I gave such a detailed description to emphasize an important fact. It is very easy to perceive objects in the game as real. Pac-Man is such a object on the screen, ghosts are also objects, like a spaceship, Mario, Sonic, Solid Snake, a soldier from Call of Duty. They are all objects. But this is an illusion.
In fact, they all just give you a hint of an inner, deeper system. In this system, the computer has to do a serious job simply to determine that the two objects are touching each other . What you see on the screen is an illustration of the abstract world, and part of the game passes the player information from this world through the screen in a way that corresponds to its sense of reality.
It's very easy to forget how thin this connection is. How do you know which object on the screen you control? He is different from others and responds to management. And what if the same thing appears on the screen? Or your object will sometimes move randomly, respond to control signals with a delay, sometimes turn into an invisible, split into two, become like one of the enemies?
The designer's task is to make a connection between the inner world of the game and that, What you see on the screen, as simple and immediate as possible (of course, if it does not try to achieve some special effect). That is what the word is supposed to mean, the immersion .
Insert the coin into the arcade machine "20 Year Reunion" and the joystick of the first player enter: up, up, up, down, down, down, left, right, left, right, left. If the ghost on the Game Select screen turns pink and you hear a sound, everything is done right. Now, if you choose the game Ms. Pac-Man, then instead of it you will play the original Pac-Man.
On some graphics equipment you can use stunts with sweep lines to create strong magic. For example, in a system that can only display eight sprites, you can achieve more, although at the cost of CPU time and reduced flexibility.
In this respect, the Atari VCS / 2600 console is most notable, because most of the system graphics were created there Using tricks with lines of development. More details about these techniques can be found in the book Racing The Beam .
Dossier on Pac-Man: http://www.gamasutra.com/view/feature/3938/the_pacman_dossier.php?print=1
YouTube channel Jamie Pittman: https://www.youtube.com/user/jameypittman/videos