How to write a Shoot 'em Up, by Phagex of LSD. The source code for this tutorial should be hanging around one of the Grapevine disks, and is self exctracting: GameTut.EXE Right, this is a tutorial for all the coders out there who have learnt how to put a screen on and make a few bobs fly around, but havent got an idea about how to put them to proper use. In this tutorial i have coded the basic platform (Nooo! not a PLATFORM game! (it isnt a PLATFORM game is it?)) of a shoot 'em up. Its a very simple move yer space ship around the screen, and shoot upwards against the nasty alien coming down at you type affair, only its a complete, fully commented source code that i've given you to play with. I've placed this game into the Public domain through Grapevine, but i have FULL copyright on this game, ie. the GFX and source. I know it isnt that much, but i'de prefer you to draw and eventually program your OWN routines instead of just lifting them from my source, although it really isnt the BEST source anyway! But it does do the job (which is all that matters when your coding for a living hehe!)... Anyway, off we go with a loose description of what happens: First of all you naturally kill the system and set the games variables, then we have a few presentation routines for fading in and out and displaying text. Start off with "Get Ready" and then head for the main game processing loop which is what i'll now describe in more detail... First of all, the screen is double buffered, which i'm sure you all know the purpose of, (y'know, keeps everything smooth and flicker free) not only does this mean that the screen has two memory banks, but all variables associated with the blitting and clearing are double buffered as well. The Aliens, Bullets and Explosions all have three data lists each, the first is the Variable Table which stores main variables about each item, and then theres 2 tables (double buffered) which stores the actual items Screen memory address, this is to allow for blitter clearing on the next frame. The Variable Tables are used differently for each type of on screen object, each alien has 4 words allocated to it, the 1ST is the downwards SPEED (ie. this variable is added to the aliens Y Position), the 2ND and 3RD are the X and Y Positions, and the 4TH is its animation FRAME. The SPEED variable is also used as an active FLAG, ie. if the speed is -1 ($ffff) then that particular alien is inactive (not shown), but if its positive ie. 1++ then the alien IS active and is used as the speed. Bullets are simpler in the way they just have 2 words, X & Y Positions, but if the X Position is -1 (Off screen) then its inactive and not shown. Explosions have 3 words, an X & Y and an animation Frame, similar to the bullet configuration. Now the first thing i've done at the start of the loop is to clear all the old objects such as the ship, aliens, bullets (fire) and explosions off the screen, this is done by storing the memory positions of everything on screen in the last frame. Then the clear routine just has to look up the last active objects and BlitClear them, this individual clearing is faster than clearing the WHOLE screen with the blitter. The next 2 routines service the bullets, first the bullets variable table is scanned, any active bullets are moved UP the screen by subtracting a speed variable from the bullets Y Position, if however the bullet reaches the top of the screen then its life is over and that bullet is disactivated in the VarList. The next routine blits the bullets onto the currently active screen. This is done by scanning the VarList for active bullets (X Pos <> -1) and just blitting onto the screen with any active bullets X & Y positions. Next are the alien routines, first a quick randomize routine which uses a few sources of varied numbers ie. X & Y Position of spaceship, raster X & Y position and contents of the KickStart ROM chip. The new random number is used as the new X position and for the speed of any new aliens activated. The second routine is the New Alien one, every 10 frames a new alien is activated, the routine searches down the aliens VarList for an empty location (ie. unactive alien) and the first empty location it finds it puts the random number into the X Position (within screen boundaries), zeros the Y position and animation frame, and uses the remainder of the random number as the new aliens speed. This sets a new active alien into the VarList. The third alien routine moves the aliens down the screen, same as the bullet mover works, but in the opposite direction. When the alien reaches the bottom of the screen, it is then disactivated. The fourth routine is a collision detection routine, it uses the VarLists of both the Bullets and the Aliens, its checks the X & Y Positions of all active bullets against all active aliens. If any bullets co-ords are found within an aliens, then the alien is disactivated, score is increased and the New Explosion routine is called. The explosion routine searches through its VarList for an unused explosion, gives the dead aliens X & Y Pos for a new explosions co-ords, and sets the frame to 0. The fifth routine is just a blitter routine, goes through the Aliens VarList, blitting any alien active. Next are the 2 explosion routines, the first just scans the explosion VarList and increases the Animation Frame number of any active explosions. When the frame counter of any explosion reaches 18, that explosion is disactivated as its reached its last anim frame. Second routine just blits the explosions current anim frames at their corresponding X & Y Pos. Next is a quick check to see if the spaceship has been hit, and if its in the process of "dying" then the next few routines are skipped. The CheckAlien routine is the other collision detection routine, where co-ords of active aliens are checked against the spaceships X & Y Pos. If the ship has collided, then an explosion is activated and a flag set to indicate death. TrackStick and TrackMouse just get the status of the joystick and mouse and set the movement flags accordingly. The MoveShip routine checks the movement flags and moves the ship Up/Down/Left/Right at the selected ship speed, it also checks the ships co-ords against the screen boundaries, and makes sure the ship doesnt wander off the edge of the screen! Then the ships X & Y co-ords are Double buffered into either 1 of two sets according to what screen the ship will be displayed on. Finally the SpaceShip is blitted onto the screen. Then we wait for the Vertical Blank period, then double buffer the screen and copperlist, and increase the time variables. A quick check to see if all the lives have been used up by the player, if they have then jump to the "Game Over" routines and exit, otherwise check the right mouse button, if pressed then quit anyway, else jump back to the mainloop!! And thats just about it! Well its a fairly complex process, but hopefully you've learnt the basics of it all. Theres quite a bit you can improve on, like the aliens, all they do is come down the screen at you, it shouldnt be too hard to make a routine where they follow a pattern, go left and right, in a circle or even both! Then theres intelligence routines, aliens that follow you or avoid you. Perhaps even a scrolly background that moves down the screen, complete with level maps and such. Theres plenty of ideas to add to it all. But remember to keep your source code simple and clean, it helps to be able to read and understand source that you coded while in a "different" state of mind like you were the other night hehe! Oh, i coded this game in Devpac 3.02, and i recommend you use it or a Devpac variant for source compatability, i dunno about this ASM-one and Trashm business. Devpac isnt the best, but i think its the most user friendly. As for future tutorials from me, well i'll keep 'em simple because i'm coding Satan On Speed for LSD and thats using ALL my free time up! But i may even come up with a tutorial on platform games, but then again, WHO HASNT CODED A PLATFORM GAME!!! There are just SOOO many!!! But i suppose theres always room for a GOOD platformer, most i've seen today are just simply shite. Also i'm upping quite a bit of my source code to Pazzas BBS, so when its online you can leech my codings heh, but dont go bothering Pazza for my code pleeze.... cya 4 now....