Writing Games with Processing: Setup and a Simple Player Character

16. December, 2013

We have an idea, now we need to write the game. Let’s use a screen size of 640 x 480:

void setup() {
  size(640, 480); //VGA for those old enough to remember

The next item on the task list is to render the game area. Let’s create a nice grass background:

void draw() {
  fill(174, 204, 27);
  rect(0, 0, width, height);

Too boring? Well, we can always add a more complex background later. Right now, we’re in development mode: We want to test some game ideas, quickly prototype something and play. Fancy graphics is our least priority right now.

What else do we need? The player character, Platty, the platypus:

int px = 320, py = 240;

void drawPlatty() {
  rect(px, py, 20, 20);
  textAlign(CENTER, CENTER);
  text("P", px+10, py+10);

void drawBackground() {
  fill(174, 204, 27); // green
  rect(0, 0, width, height); // fill whole screen

void draw() {

That’s it. Again nothing fancy, just the bare minimum.

You will notice that some of the numbers are related but it’s not obvious from the code. At this point, we’ll have to make our first design decision: Can the player move freely (pixel by pixel) or is the movement tile base (as in chess)?

At this stage, both are equally simple to implement. An ego shooter or a jump&run would use fluid movement while a puzzle type game often uses tiles.

Let’s use tiles:

int px = 320, py = 240;
int tileSize = 20;

void drawPlatty() {
  rect(px, py, tileSize, tileSize);
  textAlign(CENTER, CENTER);
  text("P", px+tileSize/2, py+tileSize/2-2);

Much better.

Note how I split tasks into different helper methods to keep the code readable. I could have done the player character rendering inside of the main draw() method. But by moving the code into different methods, I can keep things together that belong together while at the same time documenting my code. drawBackground() is like a comment explaining what the code in the method does. But unlike a comment, it can’t become outdated.

You can find the final version of the code here.

Next: Enemies!

First post in the series: Getting Started

Writing Games with Processing: Getting Started

15. December, 2013

Ever wanted to write your own game? Can’t be too hard, right?

Most games sold today are ego shooters. But the genre is sucked pretty dry. The most innovative games in the last years were simple, surprising and cheap. Examples are BraidFez, Thomas Was Alone. Those games didn’t thrive from multi-million development budgets, they throve from simple ideas. They were great not despite but because of their limitations.

In this series of blog posts, I’ll show you how to develop a very simple game using Processing.

Processing is a simple environment to create amazing computer generated images using a simplified version of Java like the one on the right (code).

Komplexe Methoden –  M.1 Zufall und Rauschen –  M.1.6 Agenten im Raum –  M_1_6_01_TOOL

Komplexe Methoden – M.1 Zufall und Rauschen – M.1.6 Agenten im Raum – M_1_6_01_TOOL

While you download the software, we need an idea.

In my case, the idea came from a brainstorming session organized by Zurich Game Developers at the MechArtLab. Everyone had to buy a Kinder Surprise egg (illegal in the USA, btw.) and create a game with the content. The eggs in my group contained a platypus, a crocodile and a frog.

After a quick brainstorming session we came up with this game idea: “Kribbit, the frog, runs a zoo. A small zoo. A very small zoo. Only a single compound. He has two animals: A poor, lonely platypus and a couple of crocodiles. The crocodiles promised to be nice to the platypus and not to eat him. But every time Kribbit looks the other way, the crocodiles try to eat poor Platty.”

That’s it. Game idea? Check.

What? Too simple for you? Well, complex game = low chance of success.

Next post: Setup and a simple player character.

Wine on OpenSUSE Without Sound

4. September, 2013

Yesterday, I tried to install the Windows game Homeworld on my openSUSE 12.3. After a couple of problems, the no-cd patch, I could start the game with:

/opt/cxoffice/bin/cxrun --bottle Homeworld homeworld.exe /1600 /enable3DNow /enableSSE /device gl /heap 1073741824

Note: For /device gl, you must install DirectX 9.

The main problem: No sound. Starting the Wine Configuration, I saw that it was using winealsa.drv in the Audio tab.

Looking into the terminal finally solved the mystery:

ALSA lib dlmisc.c:236:(snd1_dlobj_cache_get) Cannot open shared library /usr/lib/alsa-lib/libasound_module_pcm_pulse.so
ALSA lib dlmisc.c:236:(snd1_dlobj_cache_get) Cannot open shared library /usr/lib/alsa-lib/libasound_module_pcm_pulse.so

My system is 64bit but Crossover is probably a 32bit application.

Installing alsa-plugins-pulse-32bit finally solved the problem.

Also make sure you have this in your ~/.asoundrc:

pcm.!default {
    type pulse
ctl.!default {
    type pulse


Anomaly – Warzone Earth

21. September, 2012

Anomaly – Warzone Earth (forum) is basically a reverse tower-defense game. The computer builds the towers and you try to get past them.

The game works on Linux, Mac and Windows. Installation on Linux 64-bit was painless: just unpack the archive and execute the game.

By default, it runs in full-screen mode which is a bit of a problem for me since I have two screens. Alt+Enter toggles between full-screen and windowed mode.

Your goal is to lead a train of 5 armored vehicles through a dangerous area. You can heal the vehicles, give them directions, change their order, add and remove units. In later stages, you will get decoys that draw enemy fire, or smoke grenades that cover your for a time.

Some tactical tips:

  • Don’t rush. In most levels, you have lots of time.
  • Crawlers have a slightly higher range than the basic enemy towers. If you circle an adjacent city block, you can often take out some of the enemies with little or no damage at all.
  • Heal units using corners. Place the repair item in the corner and four units will be in range instead of the normal three.
  • If you need to heal the leading unit, place the repair token a bit ahead so the unit gets enough exposure.
  • Keep an eye on health. If a unit is losing a lot of health and you can’t reach it or you’re out of repair tokens, you can put them in a different place in the train. If the first or last unit is out of range, move the damaged unit there. Losses are really expensive in this game.
  • Try to clear all enemies. In the first levels, supplies will be dropped anywhere but soon, they will be dropped after destroying enemy towers. Plus, each kill gives you a bit of money that you should spend on more units or upgrading existing ones.
  • The first unit takes most damage. Upgrade it first.
  • When a unit is under attack, you can cancel the effects by dropping a repair token.
  • If you walk in circles around the basic towers, they will aim at you. That way, you can buy your tanks an extra moment since the turret will first have to turn back before it can open fire.
  • Plan ahead. The closest reward might not be the easiest. Try to single out towers. Drive past and out of range to repair or recharge shields.
  • Each tower has a specific weakness. Exploit them.
  • Some can’t turn. Don’t attack them head on; drive by instead or kill it from behind.
  • Behemoths do area damage. Use a decoy and place it far away from your units.
  • When you need to squeeze through a bunch of towers, use a smoke bomb.
  • Decoys work well with flash towers but you need to place it at a distance or the damage will spill.


Getting Fieldrunners From Humble Bundle for Android 3 to Work on 64bit Linux

18. August, 2012

I had several problems with Fieldrunners from Humble Bundle. The first problem is: There is only a 32 bit version, even though I get a download link for a 64 bit version – but both are the same.

The next problem is this error message:

cannot open audio device (Device or resource busy)
Fieldrunners: pcm.c:923: snd_pcm_state: Assertion `pcm' failed.

This is because Fieldrunners uses alsasound but on my system, PulseAudio blocks the audio device. To fix that, run the game with “padsp“:

padsp /opt/fieldrunners/Fieldrunners

which gives this error

ERROR: ld.so: object 'libpulsedsp.so' from LD_PRELOAD cannot be preloaded: ignored.

This is probably because padsp can’t find a 32 bit version of “libpulsedsp.so”. For openSUSE, you can find the package here: http://software.opensuse.org/package/pulseaudio Make sure you click “Show other versions” so you can select the 32 bit version (the browser will show you the 64 bit version if you use a 64 bit version of openSUSE).

Click on “32bit” to download the file (don’t use “1 Click Install”)

Use atool to unpack the archive (trying to install it with “rpm” or “1 Click Install” will fail since the package is for the 32 bit version of openSUSE). Copy the file “…/usr/lib/libpulsedsp.so” to “/usr/lib/libpulsedsp.so”. “padsp” will find it. Now you can run the game.

Unfortunately, the audio will be choppy for some reason. I have no solution for that (it’s also choppy when you disable pulseaudio). My workaround is to go to options and to disable sound effects and the game music.

Related articles:

Dealing With Cheating

13. July, 2012

All online games attract cheaters. Most of them try to ban players who cheat but Rockstar Games came up with a better approach: They herd them.

Makes me wonder what took them so long. It would be great if there was a special server for cheaters and people using modded clients. Just imagine how many people will start working on AI problems (identify threats, take cover, shooting at targets, move around in a complex maze).

What’s Wrong With Mass Effect 3

17. June, 2012

I’m one of those unhappy gamers (like many, many, many others) but until this video, I didn’t know why. It’s a bit hidden in the message but ultimately, it boils down to: ME 3 isn’t an RPG. It’s an ego shooter.

The main reason is that your decisions in the game don’t count. Just like Bioware ignoring the outrage of gamers, whatever you do in the game has no consequences whatsoever: After the game, everyone is dead (or will soon be dead for lack of food), the galaxy is devastated,  the citadel is gone (no place to meet anymore, so no galactic council), no travel between civilizations, the fleets who came to protect Earth are now stranded – a planet pummeled by the reapers for months. Good luck finding anything there but death.

And that’s why it’s not an RPG. In an RPG (and ME 1 and 2), Shepard was my character. I made decisions and my decisions mattered. In ME3, when the dialog options come up (if they come up at all), I often just get two ways to say the same thing. There is no choice anymore. Oh yes, I can decide to trick the Krogans or the Salarians in the early game. But in the end, all is moot.

A lot of effort went into making the fights harder. That worked; I was getting killed so often that I finally gave up on the game. But in ME2, my decisions mattered. I was Shepard. In ME3, I was just a remote controlled drone of the EA’s marketing department (“Give us all your money!”).

Journey (PS3)

17. March, 2012

Bored by the violence in Mass Effect 3? Solved Ratchet & Clank three times already?

How about a nice, relaxing Journey?

Journey is the latest … uh … game? by thatgamecompany. Remember flOw? Flower? If you already own those two, Journey is for you. If you don’t – give it a try. Discover the journey.

Two Nice Browser Games

11. January, 2012

If you’re looking for a simple game to fill a five-minute gap, here are two by Microsoft:

  1. Pirates Love Daisies (tower defense)
  2. Cut the Rope (logic puzzle)

Even though developed to show off IE9, they work perfectly well in Chrome.

One Day Left To Buy Darwinia

5. December, 2011

There is a little strategic gem to buy at Humble Introversion Bundle: Darwinia. Hurry up, there are only 24 hours left … until you have to buy the game elsewhere … where you can’t set the price.

The goal of the game is to help little 2D people (the Darwinians) recapture their artificial world after a nasty virus infection. It’s not too easy and not too hard, the graphics is simple, the controls are easy to master.

I also tried Uplink (same producer) but the game is a little bit too text-heavy to blast off some steam after work.