Monday, May 19, 2014

Squadron4 game now in graphic mode

Squadron4G is born

Like I said earlier in this blog, my goal in programming with Python was to reach some kind of knowledge of the "graphical mode" - something to be honest, I was kind of excited and anxious about.

Excited because it means I will have  access to colors, loading images, changing palettes, using "sprites" and later adding sounds effects, maybe music etc ...

Anxious because during my past experiences in programming that was pretty much the end of the road (except maybe that Sprite Editor I was doing in Turbo Basic back in the days (on 320x200 screen resolution and 4 colors))

Pygcurse to the rescue

Now enter pygcurse, this was the missing link for my Python's adventure - something that could be a bridge between the curses library and pygame (which for the moment still seems a little too complex).

After reading the manual, and some sources from the pygcurse package (especially, I made the "port" of the code into something more graphical "friendly" and Windows compatible.

My strategy for the "port" was to override all the curses standard function (addch(), addstr(), inch() and so on) at the start of the program - to minimize the changes in the rest of the source. And to my amazement it worked quite well, almost immediately ... because I couldn't figure how to replace the inch() function since they was no equivalent, that was until I figure that the PygcurseSurface object had a table variable : _screenchar[x][y] which  holds the character at cell x, y.

Problem was the geometry : 80x24 in text mode doesn't play well in graphics - it was ridiculously too wide. The code was working, but the design had to be redefined.

Now the game is running in 40x40 area - there are colors, and even a new feature for the player I just added this morning : "Teleportation"by pressing 't' the player will teleport himself back in the center of the area. A very handy feature, when he will get surrounded by the chasers. But Teleportation costs 100 out of the countdown score, so again a feature to use wisely.


Where is squadron4G?

It is hosted at - and here are :

 NB :
To run the game pygcurse is required (just copy in the same folder)



One last thing concerning my first game (the one in text-mode) the curses library I was using - isn't compatible with Windows machine, they need to use another separate library - and changing a bit of the source code too (maybe?!).

To be fair, Python is pre-installed on OS X and Linux - so I never thought that windows user should have to select which version they needed to download on

In conclusion, the installation for Window user might appear as a little heavy :
The first time they need to download python from, then pygame from, then pygcurse from github, and then finally my source code hosted at

No comments: