Road Rage – n900 game

The Lappeenranta University of Technology (LUT) organized 20th summer school on telecommunications during the last week. I was there arranging it and running a 24 hour codecamp. The theme of the summer school was “Supporting independent living with technology”. We had a number of seminaries related on the theme and at the end of the week we had a 24 hour codecamp. During the codecamp the students were introduced to the Nokia N900 smart phone that runs the newest Maemo operating system. The good side of the OS is that you can use Python to quickly develop applications and test them. This was the case on the one-day codecamp – Program something that supports independent living at home and do it quickly (and dirty :-P).

Even though I was helping people out most of the time and programming some harder parts (like the very evil how-to send an SMS), I still had time to do something own. As most of the readers know, I am a big game aficianado. Thus, I had to do a game 😛 All I had was a few dark hours of the night. I decided to use pygame as the library to program with and away I went!

An Idea?

Okay… Where do I start from? Well, I had a mobile device on my hands. The first thing that came to my mind was to create a certain limitation (in addition to the small amount of time I had). Thus, I decided that the only way to control would be with the accelerometer of the phone – no touching, no keyboard buttons. Just tilting the phone.

Fine, I had a limitation and the controls. Now, the game? I wanted to have something fast paced, quick to play, quick to fail and quick to start again. Thus, I came across the idea of a car game. Just your old, not-so-breakthrough, driving game.

So, now we have the game idea: A car driving forwards that moves according to the tilting of the phone. Nice 😀


Well, something easy and fast-paced. This was quite easy to come by. Imagine a car driving very fast on the wrong lane. There are other cars coming towards you. The player needs to tilt the phone to avoid colliding with the law-abiding citizens. As this would be too easy by itself, I added oil spills. If the car hits an oil spill, it looses maneuverability – the player cannot move the car for a few seconds, thus forcing the car to just keep going straight. This added some nice challenge to the game.

Also, the game keeps track of the player’s score. The further you get, the more points you get. In addition, if the player tilts the phone forwards the car goes faster and if tilted backwards the car brakes. Going slow is easier, but the player earns a lot less points in the exchange. So, either higher speed, higher gain and higher risk or the slow grandma way 😛 Now there is a simple gameplay logic and challenge to the game. All that is missing is…


Urmm… yeah. This is something that is needed. I guess. As I suck on drawing and making graphics I had to go with some really cheap stuff.  If you can go the whole nine yards, I decided not to even go to the start line. No fancy programs and pixel graphics. Instead, I drew the car, oil spills, the road and the oncoming cars by hand. Some really ugly and nasty pencil drawings. BUT! After editing them a little bit (just changing temperature, saturation, hue, brightness, etc.) I came up with pretty decent looking graphics.

Here are the graphics I created and edited (all in a short amount of time)

The Car:  

Enemy car:

Oil spill:  


The road:  

Ugly? Well, it still works surprisingly good.

Putting it all together

Okay, so now I had everything in place. Easy controls, cheap graphics and simple gameplay. The creation of this whole game from a scratch took me about 4 hours, which I am quite proud of. Here is a screenshot of the game (yeah, screen capture of a quick-paced game is not easy, but you get the idea):

If you are still interested and would like to try out the game (I think it works only on n900), get the source from the following page:

It’s completely free and open-source. Do whatever you want with it, but please, at least provide some credits to my work. Also, if you happen to use something I have made, please let me know. I would be more than happy to hear about it 😀


OpenCV 2.1.0 with Python bindings on Maemo (n900)

Howdy How!

Lately I’ve been really busy with my job at the university. However, I decided to give a short moment of my time to share some fruits of my work. I have been always interested in playing with the Augmented Reality stuff. So I decided to challenge myself a little bit and get some tools to work on n900. I found a version from the repository (2.0.something), which was missing the Python bindings. Now that I have lately worked with python (and still am), I really want those bindings to work!

Well, it seemed that there is only one option, to compile and configure everything to work manually. And that is exactly what I did. Finding all this was a pretty hard, so I decided to post everything here on my blog. There are probably some strange things, because I am no real Linux expert (and this is the first time ever I have created .deb packages), but following my instructions you should get opencv to work on maemo (with the newest PR1.2 firmware). So, keep on reading.

How to get OpenCV to work on n900

The OpenCV needs to be build inside scratchbox and then deployed to the real n900 in question. The installation is based on the OpenCV installation instructions from the wiki:

I have built successfully the whole system from the stable package, not from the SVN (for some reason I wasn’t able to get cmake to compile from SVN)

NOTE: This can be built for both the X86 and the ARMEL. Just change to different scratchbox environment with sb-menu

If you want to try things on the emulator, you should compile the X86. Otherwise use ARMEL (so you can deploy it to the n900). Probably might be best to do both?

Working with the scratchbox

If you want to use the latest package, get subversion.

1. Install subversion

fakeroot apt-get install subversion

2. Install the rest of the prerequisites

apt-get install build-essential

apt-get install cmake

apt-get install pkg-config

apt-get install libpng12-0 libpng12-dev libpng++-dev libpng3

apt-get install libpnglite-dev ibpngwriter0-dev libpngwriter0c2

apt-get install zlib1g-dbg zlib1g zlib1g-dev

apt-get install libjasper-dev libjasper-runtime libjasper1

apt-get install pngtools libtiff4-dev libtiff4 libtiffxx0c2 libtiff-tools

apt-get install libjpeg8 libjpeg8-dev libjpeg8-dbg libjpeg-prog

apt-get install ffmpeg libavcodec-dev libavcodec52 libavformat52 libavformat-dev

apt-get install libgstreamer0.10-0-dbg libgstreamer0.10-0 libgstreamer0.10-dev

apt-get install libxine1-ffmpeg libxine-dev libxine1-bin

apt-get install libunicap2 libunicap2-dev

apt-get install libdc1394-22-dev libdc1394-22 libdc1394-utils

apt-get install swig

apt-get install libv4l-0 libv4l-dev

apt-get install python-numpy

3. Get the files and save them to your MyDocs scratchbox directory

(if default installation is done, this can be found in ubuntu from /scratchbox/users//home//MyDocs/

RECOMMENDED: download the latest stable Unix version

untar the file for example to OpenCV-2.1.0/ (the version I have tested this with)

or if you want to try your luck, from svn

4. create a build directory (the only difference to that one, is that o is not a capital letter

mkdir opencv-2.1.0

cd opencv-2.1.0

5. Now, lets use cmake to generate the makefile


This will use the cmake to build the make file

6. Now, we must create the .deb package for the opencv

export DEBULLNAME=”Your name”

dh_make -e –createorig

When asked for what kind of binary, just type s (= single)

After this you can edit the installation info etc. at ./debian (for example nano ./debian/control and just write a short description here)

7. Now, build the package (you have to be in the opencv-2.1.0/ folder

dpkg-buildpackage -rfakeroot

This will display a lot of output and you should see the build process in percentage running towards 100% (this will take some time, so grab a cup of coffee. For example check for some nice stuff)

8. If everything went okay, now you should be able to install the application from the .deb package

cd ..

fakeroot dpkg -i opencv-2.1.0-1_armel.deb


fakeroot dpkg -i opencv-2.1.0-1_i386.deb

Now you should have the whole thing installed on the machine (now scratchbox environment). The problem here is, that python is not configured properly.

9. Configure library path

Because the .deb installer does not install all the libraries correctly (at least with these instructions), you have to configure the path manually.

Export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH

sudo ldconfig (OR fakeroot, if inside scratchbox)

10. Configure Python

Now, finally only one part is still missing! The thing we went all this trouble through, configuring the python to work. In n900 you can replace python2.5 with just basic python command

Python2.5 [in scratchbox python leads to 2.3 version of python]

>>>import sys

>>>print sys.path


And after this everything should work just fine. Test it

11. Test OpenCV with python

>>>import cv

If no error comes up, this should work now 😀 You can test the installation in scratchbox by going to the original folder OpenCV-2.1.0/samples/python. Normally, when running on PC machine, the python test could be done for example by running python If you try to run


You will get no error, but nothing will show on the screen (at least when run solely inside the scratchbox and no virtual machine). If you run the same thing in n900, it should display you some nice stuff 😀

Okay, that was it. Have fun tinkering with opencv and python. If you get any errors/bug/missing things, please, post here so we can try to fix those.