will

It's All Geek to Me

Posts about technology, with a focus on web development with Python.

I am the author of Beginning Games Development with Python and PyGame.

So you are writing a game in PyGame and you come up with the most beautiful particle effect. But when you implement it, you find that the particles seem to jitter between pixels, and it spoils the effect. This is because PyGame can only render sprites at integer coordinates, even if you give it float values. OpenGL or other 3D APIs don't suffer from this because they can apply filtering and effectively render images between pixels (or sub-pixel). But you can't do that with a 2D blitter.

Until now that is! :-) I've written a small module that pre-calculates sub-pixel sprites so that you can render a PyGame surface at fractional coordinates. It's nice and easy to use, and is almost a drop in replacement. Here's an example: continue reading…

I have written a demonstration of a simple path-finding algorithm (in Python), for use in grid-based computer games. It used a breadth-first search to route a sprite from one part of a map to another, avoiding obstacles in between. The code is a listing taken from my forthcoming book, Beginning Game Development with Python and Pygame

To run it, you will need PyGame, and of course Python. The code is completely public domain, use it for whatever purpose you want and you don't owe me a penny. Here be a screenshot...

The other day I noticed that the words 'kiss' and 'lips' (don't ask) could be spelled on the same buttons when texting on a phone. I idly wondered what other related words could be spelled on identical buttons. That idle wondering festered in my brain and eventually turned in to a Python script (which is often the result of my wonderings). The script I wrote, groups words together by the sequence of phone buttons needed to txt them. It also filters out sequences with just one word, which I wasn't interested in. Here is the code:

Next I scanned through the output to find related words. I guess this could be done automatically if I had access to a thesaurus file, but that seemed more trouble that it is worth. Here are a few I picked out...

[24453] AGILE CHILD - A fast moving kid? continue reading…

Last week I started a new job as a full time Python developer. Prior to that I worked for a computer games company called  Evolution Studios. Evos - as it is affectionately known by employees - achieved a great deal of success with its latest game, Motorstorm, and it looks like they are set to keep producing hit games. There are a lot of great things about working for a games company, and being a games programmer gets you a lot of respect amongst certain circles (i.e. game geeks). So why give it up? Well over the last few years I have fallen in love with Python and I use it at every opportunity. Consequently I have been idly keeping an eye on the Python job board for Python related work and came across a job that I was perfectly suited for. It listed requirements for skills that I thought were incidental, and the work I would be been doing is not dissimilar to the type of Python coding I do to amuse myself in my spare time. Not sure if I can tell you about it yet, I would have to clear that with the boss. Did I say 'boss'? I meant client, because now I am now self-employed! continue reading…

It's good to see a few people using my BBCode module. I have since made some small fixes and added a feature. I've added a PygmentsCodeTag that uses the excellent Pygments module to syntax highlight code within a [code][/code] tag. It supports all the languages that Pygments supports, simply specify the language in the tag (i.e. [code python][/code]). You can still use the code tag that generates <pre></pre>, if you have another syntax highlighting solution. continue reading…

In the last few weeks I have been tinkering with a dynamic website created with Turbogears, but that's not what this blog entry is about. The website I have in mind is similar to a forum in that most of the content come from the users (can't tell you exactly what it is just yet). I wanted a way for users to post comments with simple formatting, but I didn't want to let them enter straight html - for all the problems that would cause. No doubt, some wise-guy would figure out that he could enter the <blink> tag! So I decided to implement something like BBCode, which I dubbed 'Post Markup'. continue reading…

A while ago I wrote a chess module for Python. Now this is not a chess-playing module, rather it parses chess moves, stores board positions and works out legal moves. It can also read and write PGN files. I can fairly confidently declare myself as an expert in this kind of thing, having written the PC chess game Chess Commander.

Chess is something that is very well defined, the rules are laid out in black and white, but there are enough juicy problems and gotchas to make it interesting to work on. It was the special case moves such as en passant and castling that were most tricky. I made extensive use of Python's generators extensively which did simplify things a great deal. continue reading…

Netstring.py’ is a Python module to encode / decode netstrings. A netstring is a simple protocol for encoding arbitrary strings in a file or datastream. They have the major advantage over the traditional zero terminated strings in that the reader knows the size of the string up front and does not have to examine the data a byte at the time.

There is no documentation for this module other than the docstrings, but hopefuly that should cover it. For more information on the netstring protocol see the official netstring protocol document.