This is a simple walkthrough on how to install my Tetris clone, Blocks, on a Raspberry Pi.
On most computers running Debian (or Raspbian in the case of the Raspberry Pi), it’s as simple as clone, compile, run:
sudo apt-get install libncurses5-dev doxygen
git clone https://github.com/mike42/blocks
cd blocks
make
./bin/blocks
If you have any issues running this, then you need to fetch a newer version of GCC, as this needs C++11 support to compule (see last section for instructuins).
But if all goes to plan, you will get something like this in your terminal:
Use the keyboard to control the game:
- Move
- Right, down, left
- Rotate
- Up
- Drop
- Spacebar
- Quit
- q
Get a screen
Basically any project with graphics can benefit from one of these. Simply add on a TFT shield, such as PiTFT to create a tiny console:
Of course, this is still keyboard-controlled, but with some hacking, I’m sure you could map touch events to keyboard actions.
Troubleshooting: Update GCC
The Raspbian spftware image which many Raspberry Pi’s have is slightly too old to compile Blocks, which requires C++11 support.
Luckily, it’s very easy to upgrade from wheezy to jessie to add it. You know you need to do this if you get this error compiling:
$ git clone https://github.com/mike42/blocks
$ make
mkdir -p bin
g++ src/main.cpp src/blocks_game.cpp src/blocks_shape.cpp -o bin/blocks -lcurses -lrt -std=c++11 -Wall
cc1plus: error: unrecognized command line option ‘-std=c++11’
cc1plus: error: unrecognized command line option ‘-std=c++11’
cc1plus: error: unrecognized command line option ‘-std=c++11’
Makefile:2: recipe for target 'default' failed
make: *** [default] Error 1
Generally this means you don’t have GCC 4.8, which is not available in wheezy edition of Raspian.
$ g++ --version
g++ (Debian 4.6.3-14+rpi1) 4.6.3
Copyright (C) 2011 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
So to summarise this thread, you need to:
nano /etc/apt/sources.list
Find this line:
deb http://mirrordirector.raspbian.org/raspbian/ wheezy main contrib non-free rpi
And change the word “wheezy” to “jessie”:
deb http://mirrordirector.raspbian.org/raspbian/ jessie main contrib non-free rpi
You can then update everything with:
sudo apt-get update && sudo apt-get dist-upgrade
You are now running the newer jessie release, which gives you access to the GCC 4.8 package we need:
apt-get install g++-4.8
So we can pick up where we left off, and compile the game:
make
./bin/blocks