A month or two ago I asked myself the question - can you make a reasonable 'sprite' based game in BASIC and then compiled with ZZZIP. To produce a satisfying result some requirements needed to be satisfied:
- Flicker free.
- Pixel precise collision check.
- Ability to move in front of or behind objects on the background.
- A reasonable frame rate (+10 fps)
In other words, similar features to what you would expect from a MC program - except for the frame rate. This is after all BASIC even if speed enhanced by being run through a compiler.
I included some other feature, that might be of interest, even if they are not essential.
- Restart (RUN) the program in more than one resolution dynamically.
- Stop the program if the sprite reaches the right border zone. This was so I could test the frame rate speed, which clocked in at about 155 frames in 14 secondes, or 11 FPS with a standard 4 MHz EP128 machine.
The controls are laid out as follows:
Cursor keys: Increase or decrease speed in four directions. 4 speed levels.
<1> RUN program in graphics mode 5, colour mode 1.
<2> RUN program in graphics mode 1, colour mode 1.
<3> Fly behind other objects on the display.
<4> Collide with other objects on the display.
<5> Fly in front of other objects on the display.
When the ship reaches the border it stops in that direction - except for the right border, where the program stops, and running time is displayed.
I use a three-buffer display. Two buffers for alternating the graphics and a third for collision check. The advantage is that I can draw in any of the four colours on the two first displays and yet be sure that if pixels of the ship overlaps the mask on the third display, it will trigger a collision, because the mask is all ones (made with colour 3), so BAND'ing the ship with the mask returns a value different from zero, if there is any overlap. Another advantage of this approach is that since I repaint foreground and background directly for any changes and do not use a generic CLEAR channel command, I can maintain a complex background.
Just load the demo image and START the program.
As you can see all of the targets listed, are fulfilled at about 11 FPS. So for some types of games you could use BASIC. Some kind of game, where you don't need 50 FPS. like a submarine simulator at the same level as the first Silent Service game from Microprose.
Unfortunately there are some limitations about BASIC that limits the number of frames, I can generate.
First of all I have to do a lot of extra calculations because each of the three video pages may have addresses crossing a 16 Kb border, and since I use SPOKE extensively, I need to calculate the addresses as well as the page for each byte I poke. In fact, it takes about three seconds per frame in BASIC without ZZZIP. Fortunately ZZZIP can speed calculation and SPOKES up by at least a factor 50, since the operations are close to their MC code equivalents. I am sure a way can be found to make sure that memory used for each video page all stays within a 16 Kb page, and this would save a lot of calculations. Some other day perhaps....Suggestions are welcome.
BASIC only supports 2-dimensional arrays. This is a problem, because if I want to write routines, that can handle multiple objects flying around, I really need 3 dimensions, because I have to include the objects number as one of the parameters. It is possible to 'flatten' two or more dimensions into one dimension, but it quickly gets rather complicated, when you have to maintain meta-data about how data is stored to be able to work with the data. This also makes it hard to create standard routines, that can be used as a library for others wanting to create games using the routines as a backbone.
A third issue is the limitations causes by an integer compiler like ZZZIP, where addresses are limited in scope to 15 bit and where you only have integers available.
Still, I think the result proves, that it is possible to make some simple animations at a reasonable speed including such features as collision-check and depth-sensitivity.
regards
Jesper