RETRO: Retro Invaders!

This is my entry for the contest to share with the forum. I wrote a space invaders clone. As with all dreams and aspirations I had intended to do much more. My original entry was going to be a interpreter or a virtual machine hooked up to a game API that would load games off of an SD card or virtual Mass Storage Device. I ended up spending most of my time getting a programming API for graphics and sound up and running though as well as doing research into interpreters and virtual machines. So this weekend showed up out of the blue and I had to write a game.

Compiled BIN File:
http://fab-favreau.com/retrombuino/RETROINVADERS_OC_MBUINO_V1.bin

Here is the code link:

Here is the youtube video:

The game itself is basic space invaders. Shoot them before they get to the bottom of the screen. It has a UFO saucer which you can shoot for extra points. You get 4 shields and each shield can be hit up to 4 times before it is gone. Hmm… as each level increases the speed of the invaders shots goes up. The invaders only speed up when there is less of them. You complete the level when you shoot all the invaders. The game ends when a) you run out of lives (you start with 3) or the invaders get to the bottom.

The LEDs turned out to be a pretty cool addition to the game. I wrote a class that blinks them and turns them on for a specified amount of time. They add a nice extra to the game. I use them on the intro screen and when the UFO is present.

The sound turned out to be really difficult for a few reasons. The biggest was that I had never written a sound engine before. The interrupt service routine working off the timer was the easier part. I also had a lot of trouble because there is no filter to filter out the PWM frequency to the speaker… so I had to run the PWM frequency way up there ~30 kHz.

The graphics turned out to be a bit of a bear too. Thanks to Chris Taylor for his really great LCD API. I picked up a couple of frames per second from that. I had modified the DisplayN18 class for blitting a single line buffer to the LCD panel however his is a little faster for some reason? I used a different approach to doing the graphics (as I have very little experience with anything other than double buffered displays). I have a tile map and a list of sprites. Each tile/sprite is 1 bit 8x8. They could be bigger. I ran out of time. That much is not special. What is different from what I can tell is that I use a 1 line buffer that is 160 shorts long. The render function first adds the tile map data into the line buffer first. Then the sprites are added over the existing data. You can have a great deal of different sprites and maps going to the screen and just have to rewrite the LCD memory once per frame. After each line is composited, the line is then drawn to the LCD. Kind of like an Atari 2600. Each sprite/tile has a foreground and background color and can be different from the other tiles/sprites. There is one color reserved for Transparency.

There are 16 colors to choose from. I chose a palette based on the Macintosh OS 4.1 palette I found on WikiPedia. It is a very nice mix of colors.

I found a sprite editor called SpriteX ( Google Code Archive - Long-term storage for Google Code Project Hosting. )… it works nicely except that the 16x16 sprites are in a weird format. Time limited me to 8x8 sprites. Oh well.

I used nokring to make the music. It makes RTTTL formatted ring tones which my sound api can play. Here is a useful site that has lots of arcade/video game ring tones with a link to nokring in the utilities page. ArcadeTones File Downloads

Other than all that stuff I used state machines to do most of the game logic. Please excuse the horrible coding as I tried to comment a lot of it however it is not very nice to look at. Lots of long functions…

I still intend to make a case and an interpreter for this thing. Good luck to everyone!

If anyone has any questions about it… please ask. I put a lot of work into it and have no problems sharing anything I learned.

8 Likes

Very impressive!!!

Your invaders move like Atari Invaders rather than Space invaders. (i.e. all as a single lump and not as individuals) Do you have any plans to restore the wavy Space Invaders stagger?

:clap: :clap: :clap:

Wow! Another incredible entry! :clap:

Thank you for sharing your code and for the elaborate description.
Interesting how you combined the various resources with your own inventions.
Great work! I’m looking forward to try things out and analyse your techniques when I find the time.

One question regarding your earlier investigations: How far did you get into adding hardware? On the mBuino platform I didn’t get a SD card working with the available libraries, perhaps you did? As for virtual storage, I thought of using an ESP8266, but it requires an additional power supply and I didn’t spend enough time on it yet. What were your findings?

@ Exprimenter =Thanks! I have not played the real space invaders much. I love the Atari 2600 version. I will take a look at it. Each invader is an individual sprite so moving them independently is definitely possible. I did not replicate the staggered march (not a steady cadence) when there are less of them. I ran out of time. I recently have started playing the game boy color version of space invaders. It is a lot of fun. It adds lots of new features like shields for the player ship and some advance weapons etc. The star field on mine needs some work… I only got scrolling the back ground a tile at a time. I spent half a day adding another tiled layer however I ran out of time with that and scrapped it. It would scroll 1 pixel at a time.

@ maxint = Thanks! Based on a comment on my post about extra hardware/modifications I decided to try to implement a Mass Storage Device to RAM. I found code examples for the embed platform. I cannot get it working though. It compiles and runs on the device however there is no recognition from windows that there is a USB device present. I did however get the USB CDC example running. As far as the SD card I gathered parts for it and I developed a plan in my head. My plan was to not use the built in SPI port since it has full time duty with the LCD and it is not brought out to the IO pins at the bottom of the RETRO. Instead I was going to write/port/borrow a software SPI driver to communicate with it. For the sound I did not use the PWM driver that came with MBed so I was already a little familiar with the LPC11u24’s manual. Since my goal was to load a program into RAM and then interpret it (or at least load chunks of it) I think a software SPI peripheral would be just fine.

1 Like

@ cfavreau - Congratulations on your winning submission! :clap:

2 Likes