Skip to content

mmartinortiz/rgb-led-matrix-space-invaders

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

The RGB Matrix Space Invaders

This project started during the 2020 Chrismas after I bought an RGB Matrix to play around. My goal with this game is to put the matrix in use and learn how to build a video game from scratch (without help of any framwork). You can also find this project with some more detailed instructions at Make: Projects.

Running in the Raspberry Pi

Playing space invaders with the Raspberry Pi

Running in the command line

Playing space invaders in the command line

Hardware

I'm not afiliated in any way with the following vendors. The links are added so you can find the hardware I got, feel free to buy your hardware at the vendor of your preference.

As you can imagine, you need to connect everything together :-)

Software

  • Python 3
  • RGB Led Matrix library (I used it check that the led matrix was working)
  • The flaschen-taschen server
  • Your favourite IDE. For this project I choose Visual Studio Code. In my daily programming life I use PyCharm, but I heard so many things about Code, that I thought that it was the perfect moment for checking new tools. Even I still feel more productive with PyCharm and I like more how it handles some things, I found quite handy the possiblity to develop remotely in my Raspberry from my laptop.

Setting up things

The Flaschen Taschen server

The RGB Matrix library needs to be run as root for accessing the timer of the Raspberry Pi (More here here or here). I had problems to run the game as root and get access to the joystick, so I went with a solution proposed here:

  1. Start a server (as root) that will listen for specific messages and write the images into the screen
  2. Run the game as no-root and send the sprites to the server

Some dependencies need to be fulfilled first:

sudo apt-get install libatlas-base-dev

Then the server can be cloned and built

git clone --recursive https://github.com/hzeller/flaschen-taschen.git
cd flaschen-taschen/server
make FT_BACKEND=rgb-matrix

The parameters for running the server may vary depending of the Raspberry that runs the software (see the parameter --led-slowdown-gpio) and the position of the RGB Matrix (see --led-pixel-mapper). The following parameters are for a 64x64 RGB Led Matrix running on a Raspberry Pi 4. The rotation is for my custom position of the matrix on my desk.

cd flaschen-taschen/server
sudo ft-server --led-rows=64 --led-cols=64 --led-slowdown-gpio=4 --led-pixel-mapper="Rotate:270"

If you do not have a RGB Led Matrix, you can still play around with the game. Make sure to compile Flaschen taschen server to use the terminal as a backend and then run the server with the following parameters

cd flaschen-taschen/server
ft-server -D 64x64

If it looks too big in your screen use the --hd-terminal option.

The project dependencies

  1. Create a virtual environment for your project (always a good practice) (you will need to install python3-venv with sudo apt install python3-venv the first time)
python3 -m venv venv
  1. Activate the environment
# for bash, run
source venv/bin/activate.sh

# for fish, run (if you do not know the fish shell, you have something new to check: https://fishshell.com/)
. venv/bin/activate.fish
  1. Install the requirements
pip instal -r requirements.txt

Now you are good to go, run python main.py.

How to contribute

This has been a toy project for the Chrismas of 2020 since I wanted to learn how to code a game, and I had a very nice LED matrix next to me. If you think that some aspects can be improved (and the really can) or do you want to implement some nice additions, feel free to fork this repo and make a merge request.

For the design of the sprites I've used pixelorama, exporting the project as an animation in multiple files.

For the code itself, I hope it is self-explanatory.

About

Play Space Invaders using a Raspberry Pi and a RGB Led Matrix

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages