How Tanx Works
The current version of Tanx was written over a period of around 3 years and is in BASIC. The combination of a 640 x 480 x 256 screen mode, 8 way scrolling and slightly unplanned code means that I cannot implement all the features I would like, for example I have a routine that means you bounce off the edge of platforms Chuckie Egg style, but it was just too much for poor old BASIC to cope with. So I am using the DeskLib C library to convert it to C. Out of all of the C libraries available, I found the SpriteOp functions easiest to use in DeskLib, the BASIC version of Tanx uses a sprite plotting system called FastSprite, which helps speed things up a lot.
The Main Character Movement
Our Hero can accelerate left and right, brake, and boost upwards. There are 6 images of the tank for the wheel movement effect in each direction, when you accelerate the images run through at steps of 1 for slow and 8 for full speed giving the effect of the wheels going round faster at higher speeds, if you look closely you will notice that the tank actually 'slides' along the platforms because it isn't quite right. When you boost, the tank is moved up the screen and a flame is drawn underneath it, after jumping you simply move down the screen until you hit a platform.
Tanx in action.
Our hero's bullets need to go faster than his top speed, otherwise he would be able to drive into his own bullets! To achieve this I plot the bullet at three points in front of the tank and check between the plot points for any collisions. All the other bullets move in 'real time' so only the point where the bullet is needs to be checked. The Big tank's bullets are a very crude 'homing' system where the bullet simply goes up or down and left or right dependant on where it is compared to its target.
Deciding if you want to get shot
The diagonal gun turrets and the large tanks, like most of the collision detection use a trig function to decide if the tank is close enough to be shot at. The Horizontal turrets and small tanks try shoot you if you are within a certain distance vertically and horizontally.
The platforms are the part of the game that were the most complicated bit of the game to achieve, they are in fact quite special. They consist of 4 images, a flat bit, two ends and a bit of foreground art. The platforms can be of any length, for example a 4 length platform would be 64*4+2*8 pixels in length, that is 4 * 64 is the length of the main section of the platform, and the two end pieces are 8 pixels, this is then used to detect if the point at the bottom center of the tank is in a 4 pixel high rectangle area, if it is, then the tank is positioned at a the top of this rectangle and a Boolean variable is set so the tank knows it is capable of jumping. These are not the exact numbers for this operation as quite a lot of tweaking was needed so it looks like you are rolling off the ends of the platforms. The enemies are simply told which platform they are on and the length of that platform, then go left and right of that platform.
Walls and Doors
The walls work in a similar way to the platforms, only they is only ever one wall section, there is no automated system to make a really high wall, the only difference is (other than being vertical and other crucial differences), to make sure it is impossible to drive through them I made the tank bounce away from the wall, this helps with issues such as hitting a wall at high speed and stopping dead, you can fall through the top of a wall, so all walls need a section of platform above them. Doors are just walls that disappear when a key is obtained.
All the collectibles are a four image animation, green coins for keys, yellow for heath and bullets, red damage you and then there are the exit keys, these are little pink rotating things that only appear one at a time, after you collect the first one the second one appears, get that and the third one appears, then the exit 'portal' appears which is the three pink things you collected in the form of a triangle.
To make the game eight way, I use two variables bigx and bigy, this point is used to determine what is plotted on the screen, every plot point is its position on the whole of the level added to bigx and bigy, if the tank gets near the edge of the screen either bigx or bigy is increased/decreased moving the whole of the screen. Various routines are used to determine what is done, for example I had to make sure that even if most of a platform was off the screen the bad tank still moved up and down it and what platforms to check if the tank is on them.
Output form basic crunch Xref:
Cross reference of ADFS::PizzaPie.$.gamesprogs.zRRR.TANX.
Main program Calls:
PROCback, PROCbaddudes, PROCbbaddudes, PROCbblibs, PROCblibs, PROCbloke, PROCcheckedge, PROCcheckplat, PROCdie, PROCdoorkeys, PROCdoorsb, PROCdoorsf, PROCdturrets, PROCerror, PROCfallornot, PROCfinnished, PROCforeplats, PROCgetlevel (3), PROCguns, PROCinfo, PROCinit, PROCkeys, PROClevxit, PROCmap, PROCnewhighscore, PROCplatforms, PROCplats, PROCplotguns, PROCprelevel, PROCprintstring, PROCscore, PROCshoot, PROCsoundswitch, PROCturrets, PROCwallsb, PROCwallsf
A full list of all the procedures and variables used in Tanx can be found in the Software directory on this issue of RISC World along with the latest version of the game itself.
Well, I hope this article might help to inspire some of you to knuckle down and write that game you have been intending to write for the last 20 years, sorry but I'm not going to release the BASIC source for tanx until I have finished the C version, which will probably be in about 20 years, but I will let you have a look at the procedure and variables list.