Click Here To Go To The Your Computer Archive



Written By Bobby Rao


Cover Art
Click Here To Enlarge Loading Screen

Loading Screen
Click Here To Enlarge Opening Screen

Opening Screen
Click Here To Enlarge Screenshot

Game Screenshot
Sprite Programming ================== Bobby Rao explains the game using his sprites routine which was promised last month Last month I showed you how to define characters for the sprites routine and this month I will show you how to use them in your own Basic programs. But first a few explanatory notes on topics mentioned last month. To achieve animation a sequence of slightly different characters needs to be displayed. To define these sorts of characters I would advise first defnining a Basic character and Saving it uncompiled and then reloading it - more than once if necessary - so that each stage of the animation may be defined simultaneously, swapping between characters to simulate the animation. Then when all the characters are ready they may be Saved one after the other. The string of addresses which you enter at the end of a sprite's attributes go to make up the sprite's normal and termination sequences of animation. The characters at the given addresses are displayed in order, repeatedly. To obtain an effect like a pendulum swinging then, although only three distinct characters are required - the pendulum to the right, to the left and at the centre - the characters must be displayed in the order centre, right, centre, left. Thus four frames of animation are required here and the character addresses must be entered in this order. This method applies to many types of animation so please note it carefully or you will end up with jerky animation. Sprite Magnification -------------------- When using the magnification facility note that as the sprite grows or shrinks its centre remains stationary or moves with the speed defined for the character. Hit colours - I explained the easiest way to use these last month but if you understand how colours of pixels are stored in bytes by Mode 2 then let me say that each byte altered by printing a character is "Anded" with the hit colour byte for that sprite and if the result is not zero a hit is registered. Printing - When you have the sprites routine in memory then by loading the code produced by CHARPRT. To print a sprite character in memory onto the screen xLOAD the sprites routine and "PRT CODE". This latter Loads into $C00 to $C1F so the first fouruser definable characters are unusable. To print a character at $1300 in memory at $20 along the X axis and $80 down the Y axis use the following in Mode 2: &74 = &13008020 CALL &LC00 The character should now appear and to remove it use the same commands. Note that you can print onto the screen at any time while sprites are in motion and they will move without corrupting the background. After you have defined and Saved the code of the sprites using the sprites' generation program you may use this code by first setting PAGE to &2000, typing New and then *LOADing the code. To start the sprites first go into Mode 2 and then use the following lines of Basic: ?&8D=0:?&8F=0:?&D3E=no. of sprites:?&D3F=0:?&8E=1:?&FE6E=&1F: ?&FE6D=&E0:?&FE6E=&E0:?&FE6B=(?&FE6B) AND &BF:?&FE68=0:?&FE69=30: ?&206=&4F:?&207=&12 To stop the sprites use ?&FE6E = (?&FE6E) AND 127 To make the sprites, move more slowly put a larger value in &8E - 1 is fast and 256 is slow. Location &D3F contains the number of dead sprites and is updated each time a sprite dies, that is, finishes its termination sequence and disappears. To see at any time if a sprite number N is dead use: ?(&D40+(4xN)) which will return a value greater than 128 if the sprite is dead. Page &D is used by the routine and for every sprite there are four bytes which hold data about where the sprite's attributes are. The first byte of the four holds the length of the sprite's attributes. Also 128 is added to this number if the sprite is dead. The second and third bytes hold the address of the sprite's attributes - low byte followed by high byte. The fourth byte of the four contains the number of the frame currently being displayed - initially this contains [text missing]. The first of these groups of four bytes is at &D40 because the memory from &D00 to &D3D is used to hold a copy of the attributes of the sprite the routine is working on. This is the limiting factor in how many frames of animation one sprite can have, that is, its attributes must fit into &D00 to &D3D. To alter any of the sprites' attributes you must first find out where in memory they are stored. The "next free address" stated after loading in character data for the sprite defining is where sprites' attributes start. The length of this data for a particular sprite is given by 20 plus twice the number of frames of animation used in normal movement and in the termination sequence. So for a sprite with four normal frames and three termination frames the total length of its data is 20+2x(4+3)=34. Although this is all you really need to know to be able to write a game using the sprites you probably still have no idea how to go about it so I will outline a Galaxians-type - with listing - as an example. The first thing to do sounds obvious: define the game. My game will consist of several levels of various types of aliens each type moving in a different manner and each member of a level moving independently of each other. The player will be represented by a ship at the bottom of the screen which may fire single bullets upwards, move left or right and thrust upwards, being pulled down again by an unknown force. With the sprites routine in position and PAGE set to &2000, there is 4K for a Basic program and 3.25K for sprites characters and attributes. I thought that at least four frames of animation would be required for good effects so with a three frame explosion the attributes for a sprite would be 34 bytes long. Also I thought that seven aliens would be adequate for each sheet and this together with the player's ship, its bomb and three bombs for the aliens means that at anyone time 12 sprites may be active. Thus, as the attributes for a bomb are 24 bytes long the attributes can take up (7 x 34) + (1 x 34) + (3 x 24) + (1 x 24) = 368 bytes. However if on one of the levels the aliens have more than three frames of animation this number will increase by 14 per extra frame, so to be on the safe side we may assume that 400 bytes are needed for sprites' attributes. I want eight levels of aliens and if each has three characters of 10 by 15 pixels for its normal frames of animation these characters would occupy 8 x 3 x (10 x 15/2 + 2) = 1968 bytes. This figure arises because when you define a character of 10 by 15 pixels and Save it compiled, it only takes up half the number of bytes you would expect because of the way Mode 2 stores pixel colours. Also for each character you must add two bytes for height and width. To this figure we must also add the space taken up by the ship, which is of three 10 by 15 frames, and the explosion which is used for both aliens and the ship; this is also three 10 by 15 frames. Thus the total space occupied by characters is 2430 bytes. Hence this plus the room taken up by sprites' attributes gives about 2800 bytes used, leaving about 500 bytes free for more frames in certain levels or some larger characters. Now we have defined our game we can concentrate on the fun part: defining the characters. You can do what you like here and if you feel particularly artistic try to make the levels have more than four frames of animation. However, there are a few things to note: try to fit the characters for each level into about 300 bytes per level and do not forget to leave room for your ship and an explosion - three frames. The explosion will be the same for all the aliens on all levels and also for your ship so try to make all these characters about the same size because it looks odd when a tall, thin alien has a square explosion half its height. When defining a bomb, a simple 6 by 2 block is sufficient and if you are lazy you can use the same character for both the aliens' and your ship's bombs. The bombs will have no explosion and will disappear on hitting something. Also define your bomb using only flashing colours because we will later define aliens so that they only crash into flashing colours - just passing through the other colours. Do not use flashing colours for any other characters. After you have defined and Saved - compiled - the characters you need set PAGE to &2000, type New and Load in the Basic part of the sprites defining program listed last mouth. Run this program and Load in all your character data. I advise you to make a list of the characters you Load in and their corresponding addresses in memory as told to you by the program. I include part of the list I made so you can see how it is used in the game listing given later. FILENAME ADDRESSES OF SUCCESSIVE FRAMES (IN DECIMAL) Rocket 4864,4941,5018 Skull 5095,5172,5249 Wobbler 5326,5403,5480 - 6 more alien types Explosion 6788,6865,6942 Ship 7019,7096,7173 Alien missile 7250 Ship's bomb 7258 Next free address is 7266 When you have finished you will be told the next free address after the character data in decimal. Convert this number to hex (as detailed on pages 410 and 411 of the User Guide) - let us call it WXYZ - and 'use it in the following command: *SAVE "chardata" 1300 WXYZ This will Save the character data all in one go for use with the actual game program. We do not need to use the rest of the sprites defining program because many of its functions will be duplicated and used repeatedly in the game program so do not enter Data lines as the program asks. Now type in and Save one after the other listings 1 and 2. These Load the character data, the sprites routine and the game program. Make a copy of the character data and the sprites routine - listed last month - after listings 1 and 2. You must type it in as it is printed and will have to adjust it to fit your graphics which are, of course, different from mine. Here are a few points to note about the data lines - 60 to 100. All the sprites are normal size. Note that the aliens can crash into flashing colours only, so as long as only your bomb is of flashing colours they will only crash on hitting that. Your ship stops on hitting any edge of the screen. Also your ship will explode on hitting any colour - so the program cannot let you go faster than your bomb or you may hit it. Your ship always starts off at 40 along the X axis and 237 down the Y axis. Your bomb has an upward speed of six pixels per frame and does not move sideways - these are not changed by the program. Also this sprite will terminate on hitting an edge or on hitting any colour. The aliens' missiles move down at six pixels I per frame and do not move sideways. They also terminate on hitting any edge or on hitting any colour. Line 100 is just to tell the program data ends here. Type in these lines but make the following changes: the fifth number in each line should be changed to the number of frames of animation you have for that sprite type, the sixth number should be changed to the number of frames of termination animation, the eighteenth number should be changed to 128 plus how long you want the termination sequence to go on and the last few numbers which are addresses for characters making up the sprite and its termination sequence should be changed to suit your graphics. For the aliens' line insert addresses for the first type of alien - these will be altered by the program to suit each level. Lines 110 to 200 are used to set up system variables which are listed below. ST% This the start of the sprites' attributes FLT% The number of fleets (levels) of aliens ALN% How many aliens there are per fleet ALNB% The max. number of alien bombs on the screen simultaneously FRM% The no. of frames of animation of the aliens (must be same as in line 60 data statement) TFRM% The number of frames of animaČtion of the aliens (must be same as in line 60 data statement) TDUR% Length of aliens' termination sequence SFRM% Number of frames of animation for your ship (must be same as in line 70) STFRM% Number of frames of termination sequence for ship (must be same as in line 70) ATL% This is the length of the attributes for each alien sprite. SATL% The length of attributes for the ship. This is also calculated as above. MATL% The length of attributes for the ship's bomb and for the aliens' missiles. This is not calculated and assumes a sprite with only one frame of animation that disappears on hitting something. SHP%* The address of the ship's attributes. SHPD% The address of the ship's data in PAGE &D BMB% The address of the ship's bomb's attributes BMBD% The address of the ship's bomb's data in PAGE &D MIS% The address of the first sprite that is an alien bomb. MIDS% The address of the first sprite that is an alien bomb's data in PAGE &D All the last five variables are calculated and change with other relevant variables. Lines 210 to 230 call PROCINIT repeatedly so I will now explain this procedure. Lines 850 to 920 are PROCINIT. This is a procedure which will you must have in any program you write with sprites as it stores the sprites attributes and data in &D page in the correct place. Line 250 sets some more variables: G% is the number of goes you have (lives) E% is the number of bombs you start with L% is the level you are on H% is how many times you have completed all the levels. Line 260 calls Procreset which is at lines 510 to 610. Proclevel sets the characters which make up the aliens' sprites, sets their speeds and their actions on hitting a screen edge for each level of alien. It obtains this information from lines 1100 onwards. These Data lines - one for each level of aliens with line 1100 corresponding to the first level - contain first the addresses of the characters which make up that alien in the order you want them displayed. The next two numbers control the sprites' speed in the X and Y axes respectively. If the speeds are entered then each alien has that speed but if 128 is added to the speed then each alien has a randomly chosen speed up to the speed entered. The next number is bounce control - see last month's article. The last two numbers are random displacement controls-and say how much random speed the sprites should have - see last month's article. All the parameters reset by PROCreset and PROClevel should be reset each time you wish to reincarnate or initiate a sprite. Line 260 then calls PROCstart - lines 930 to 1000 - and this initiates the interrupts.