Avast, pirate game
-
A little pirate game somewhat designed to evoke the Atari 2600. You are thrust into the middle of a boarding action on the high seas, and it's up to you and your skills with a cutlass to take the ship.
Code: AUR73MND9V
I did a lot of reading about the Atari 2600 to make this. The 2600 was a second generation video game console, released in 1977 (well before my time, but I did get an Atari Flashback just after high school). The system had 128 bytes of RAM and programmers had to count CPU cycles to time IO writes to the graphics co-processor which, in turn, modulates a video signal in real-time. For example if you wanted to draw an object in the middle of the screen, you would have to time the CPU to perform an IO operation to enable that object the very instant the television's electron gun was halfway across the screen.
Because it is modulating a video signal the units of measure are color cycles and scanlines rather than pixels. There's only like 76 CPU cycles per scanline to do all rendering processing in real-time, and the CPU has only three registers of which only one supports math. Memory was so expensive in the 1970s there was no way to build a frame buffer, so instead Atari's hardware supported a limited number of graphics objects. The co-processor automatically modulates the video signal based on the state of its registers as the electron gun races across the screen.
- There is a 20 bit playfield object which is either repeated or mirrored on either half of the screen, per scanline. It is intended to serve as walls in a game like Pac-man. The playfield object is used to draw the ship.
- There are two player objects which are eight bits each. These can be drawn either eight, sixteen, or thirty-two colour cycles wide, per scanline. They can be duplicated once, twice, and I think three times per line at fixed distances. In Avast, these are used to draw the enemy on screen.
- There are two missile objects which are one bit each. These must share the same colour as the corresponding player object and can be drawn one, two, or four cycles wide per scanline. In Avast, these objects are used to draw the swords.
- There is a ball object which is also one on/off bit. It must be the same colour as the playfield and can be drawn one, two, or four cycles wide per scanline. This object is not used in Avast.
- The background colour can be set as well.
I didn't follow all the constraints - I haven't counted cycles or limited myself to three register variables. I think it would be possible to port this game to an actual Atari 2600 but it would require a lot of trade offs and optimizations. I did manage to recreate the ocean in Stella (an emulator) though.
The main trick is a precomputed depth table. I count the scanlines from the top of the screen and use that as an index into the table to determine what the in-world distance is from that point on the ground to the player character. The the player's Z position is subtracted to allow for movement. Next I take the bitwise AND with the number 3, which is shorthand for taking the remainder of the distance divided by four. This final number is used to grab the appropriate colour for the ocean or the deck of the ship, giving the illusion of forwards and backwards motion. I also have a masking image for the shape of the ship, and the depth table is used to determine which row in the image applies to the present scanline.
This is generally the same technique used in classic arcade games like Space Harrier and Outrun.
Avast is an updated version of my submission for Gamejam 32. Sure, there are more things I can do with it, but since you can now win and lose I'm calling it 1.0. If do I return to the project I'll probably rewrite it to use native FUZE4 graphics capabilities.
The code is kind of messy, and also dedicated to the public domain.
~Max