Classic Computer Magazine Archive COMPUTE! ISSUE 30 / NOVEMBER 1982 / PAGE 44

Laser Gunner: BASIC Animation

Gary R. Lecompte
Lewiston, ME

For PET/CBM Upgrade and 4.0 BASICs (5K RAM) and Atari, this arcade-style game achieves an impressive graphics animation without the use of any machine language. Also, the Atari version introduces a new Player-Missile technique (also entirely BASIC) which results in excellent vertical motion.

Laser Gunner is an arcade-type action game. The player controls a laser gun which moves up and down on the left of the screen behind a force field and fires at invading enemy spaceships. The invaders also fire lasers and attempt to open holes in the force field. Every hit weakens the force field until an entire hole is made. A hit through a hole ends the game.

Laser Gunner is written for PET/CBM. It is an example of animation accomplished without the use of machine language routines. The drawback of this type of coding is obvious. Only one string may be animated at a time with any speed. However, by working your game format around this, you can still make action games fast and challenging.

The animation of the laser gun and the position of laser fire, as well as the location of the invaders, are controlled with the use of the location routines. The row and column values are POKEd into memory locations 216 and 198. A print statement following these routines will print that string beginning at the location determined by the row and column values. Changing the row and column value and printing the same string again accomplishes animation.

The force field changes are made by PEEKing the location of the hit, determining the character at that location, and POKEing the value of the next character to that location.

Invader explosions are done by coding cursor movements and printing characters from the invader string.

Sound routines are intermixed with laser and explosion routines. This assures that animation and sound will blend.

Invader ship location and laser fire are determined by randomizing routines. Skill level is provided by giving the player a minimum preset delay. Actual time before invader laser blasts is always unpredictable.

Stars are created with simple POKE statements to predetermined locations.

All routines are placed in order of importance, with those used most at the beginning. This allows for the fastest program execution possible to increase animation speed. REM statements should be deleted for best effect. The key to speed is simplicity. The shorter the program statements, the greater the speed.

Notes On The Atari Version:

In your corner of the universe, a zone of high-pressure radioactive plasma is contained by a platinum-iridium "wall." Your ship, immersed in the red zone, is charged with a vital duty: defend the wall. The vengeful enemies of your civilization send wave after wave of attack ships in an effort to breach the wall. These semi-smart robot ships will concentrate their firepower on your weakest spot, and mercilessly try to fire their way into the wall.

Your only defense is your powerful particle beam which you use to fend off the attacking drones. The enemy ships are wary of your power, so if you move too close to an attack point, you can spook the enemy ship into picking another target. Move to shoot at the new position, and it will just cruise back to another vulnerable spot. You must not let the enemy blast a hole in the wall since, like a balloon stuck with a pin, the radioactive plasma will explode, reducing your ship to an expanding shell of iridescent particles.

As the Laser Gunner, try to quickly react to your enemy's shots. Follow the ship as well as you can, and do not stray too far from a weak spot. When you destroy one ship, another will appear at a random position, and will home in on a vulnerable spot in the wall.

A Novel Player/Missile Technique

For a game written in BASIC, "Laser Gunner" is reasonably fast and smooth. The smoothness of motion comes from player missile graphics, but the speed comes from an unusual technique that lets you move player-missile graphics at machine language speed. That's right – no machine language is used in Laser Gunner, yet the vertical motion is quite satisfactory.

A special graphics technique is used here. Instead of storing the player/missile graphics at the top of memory, a large string is dimensioned to hold the player/missile data. When a string is dimensioned, a block of memory is reserved for it. The starting address of the string can be determined by using the ADR function. The problem is that player/missile graphics must start on an even 1K boundary (the address must be a multiple of 1024), or a 2K boundary (divisible by 2048) for a single-resolution player/missile graphics. Strings are given the next available address when dimensioned, which would only be on an even kilobyte address by sheer coincidence.

So when the ADdRess of the string is determined, we must find what offset to add to the address to reach the next boundary. It can be shown that in "worst case" conditions (i.e., the address is just one byte past a 1K or 2K boundary), we must allow for an offset of at least 1023 bytes for double resolution, or 2048 bytes for single resolution P/M graphics. So, although double-resolution P/M graphics require only 1024 bytes, we must dimension the holding string at least 2048 bytes. Then, a simple calculation (lines 150–160 of "Laser Gunner," Atari version) will give us the starting address within the string of the P/M base address, PMBASE. This value is then used to "set up" P/M graphics as usual.

The advantage of using a string is twofold: one, we know that BASIC is covetously protecting the string from the "RAMTOP Dragon" (see COMPUTE! October 1981, Issue 17) and other nasties. Second, we can use BASIC's fast string manipulation commands to move segments of strings around, "scroll" a string, erase a string, copy one string to another, and more. Since the memory being moved in the string is the P/M memory, these manipulations directly modify the players and missiles. And since these string operations internally proceed at machine language speed, we get fast P/M animation using BASIC. Although the code is not as straightforward as dedicated P/M commands such as PMMOVE or PMGRAPHICS, it sure beats cryptic USR statements. As a matter of fact, since BASIC permits such flexibility with strings, it may be the best solution to using P/M graphics from BASIC.

It is also possible to "fool" BASIC into believing that another section of memory is a string by modifying a string's Variable Value Table, but it's pretty tricky. The method described above is preferred, although it's a bit wasteful of memory. Watch upcoming issues of COMPUTE! for a complete explanation and guide to using this string technique for fast arcade-style animation. Meanwhile, type in and look at the coding of "Laser Gunner." The technique might be of use in your own programming and you'll also have fun playing the game!