Arduino Video Game
I have always wanted to build a video game and finally, I have done it in my own little way.
I knew I wanted to build a space ship kind of shooter game. Two player ofcourse. Another thing I knew was that I wanted to use interrupts for all the button press – forward, backward, right, left and shoot. There were a lot of design decisions to be made in this project. The first one was what should be the shape of the spaceship and the bullet/missile. I tried out a few different choices and rounded in on one.
Simultaneously, I started looking for some interrupt libraries. There are several available actually. After trying out a couple, I decided to go with ‘pinchangeint-v2.19beta’.
First, I tried to get a spaceship on the screen shooting continuous bullets which worked just fine. And I forgot to mention this earlier, but I am using a 16×2 character LCD display because, well, I have no other option. I have a few spare 16×2 lcd lying around and I thought it would be a good idea to use them. I do agree that it makes the game very restricted, but it I went ahead with it anyhow.
I had to come up with an overall scheme of things. How would everything work together? As I mentioned earlier, the button press will be handled by interrupts. The most important thing to decide would be to decide how to update the screen. There is a main function which will draw all the characters on the lcd. The other important function is to detect collisions between ships, missiles and obstructions. And there are a bunch of other functions to calculate positions of missiles and ships.
When you look at the code you will find that it is kind of messy. I could have made it neater and organized it better. The functions are written separately for the two players. Instead, I could have made a single function and then pass some parameter into the function. I hope you get the idea. In my defense I would say that I had no incentive to do any of that. I did a quick and dirty implementation and if it works I am happy with it.
Here is a few pictures of the hardware and the game in action.
Note from the video that the obstacles/barriers are designed to stop only the ship and not the missiles.
The source code is available at https://github.com/nakul13/Arduino-Video-Game.