Collision Detection
The main point of Fahrfall is to fall down the screen, land on a platform, and ride the platform back up the screen before you repeat the process. For that to happen, the program needs to know when the player is in contact with a platform. That problem is known as collision detection.
Collision detection in Fahrfall is fairly simple. Each platform is represented in the computer's memory by a bitmap, with a '1' representing each section of the platform and a '0' representing each gap. A variable keeps track of the horizontal position of the player on the screen, and that value is used as an index into a table containing bitmaps that represent the platform sections with which the player might collide in that horizontal position. When the player's vertical position is immediately above a platform, a simple bitwise AND operation between the two bitmaps is done. A non-zero result represents a collision (i.e. the player is standing on a platform).
Hidden Platform
As indicated, the collision check is done between the player and the platform on the line beneath the player. This presents a problem when the player is all the way at the bottom of the screen, since all three platforms will be above it. Without some accommodation, the platform data array will underflow and problems will be inevitable.
There are many potential solutions. There could be an explicit check for this situation, with the result being either to skip the collision check or to immediately end the game. Alternatively, a fourth entry could be added to the platform data array. The fourth entry could contain an all-zero bitmap (so that no collision would ever occur), or it could contain the data for the next platform.
The latter option is what I chose to do. This may seem silly, since only three platforms are displayed on the screen. But adding a fourth (off-screen) platform introduces an interesting gameplay feature. If the next platform would catch them, a player can be saved at the last minute through sheer luck when falling off the bottom of the screen! This only happens if the fourth platform is just about to emerge, but it still adds an element of fun for those who reallly enjoy Fahrfall.
Moving On Up
With collision detection all sorted, making the player ride the platforms is a simple matter. When a collision is detected and the platforms move up, the player is moved up at the same time. Similarly, if a collision is detected then the player does not move down. To make this work properly, collision detection must be run whenever there is movement of either the player or the plaforms (i.e. sometimes twice in a frame). Aside from that, making the player ride the platforms was just a simple matter of programming.
So the basic gameplay mechanics of Fahrfall are complete in this Apple II port of the game. At this point you can "play" using the joystick, so long as you don't care about keeping score. Nevertheless, there are still plenty of features and embellishments missing. So there is still more to come...I hope you will stay tuned!
No comments:
Post a Comment