What do you mean its not the new year? Yesterday was 32 AW, today is 33 AW. That's After Will. Which also makes it my birthday. continue reading…
166 posts tagged with python
What do you mean its not the new year? Yesterday was 32 AW, today is 33 AW. That's After Will. Which also makes it my birthday. continue reading…
After my previous post regarding the the is_power_of_2
and next_power_of_2
functions, Richard Jones pointed out that Pyglet has an implementation that used the bit-twiddling method. Since I had something to do a direct comparison with, I wrote a script to test the run time of the two methods.
This produced the following results on my humble PC.
The results are conclusive - bit-twiddling is still a big win in Python. I figured that the bit-twiddling is_power_of_2
function would be faster than the float math version, but I was surprised by the next_power_of_2
result. It pays to profile!
I also tested it with Psyco, and got the following results. continue reading…
Added a few functions to gameobjects.util that seemed worth sharing. The first two are two-dimensional versions of range
and xrange
. When iterating over something 2 dimensional (such as pixels in an image) you typically have an outer loop for the y coordinate, and an inner loop for the x coordinate. The range2d
and xrange2d
functions combine these two loops in to one and take range iterables as parameters.
Here's how you might use range2d
to iterate over the coordinates in an image.
The xrange2d
function returns a generator rather than a list, but works the same. continue reading…
A novice games programmer learns he can move a sprite by adding a constant to its position every frame. For a while he is happy and mocks the master games programmer for having wasted many years learning. But soon the novice realises his sprites are unpredictable and move at different rates on different machines. The novice is despondent and visits the master for advice.
"Master. Why do my sprites not obey my commands? They jump when I ask them to slide."
"Frame rate is like the wolf, it can not be tamed", replies the master. continue reading…
I've moved Game Objects to Google Code. It's new home is http://code.google.com/p/gameobjects/. There are source and Win32 packages available.
Game Objects is intended to be a collection of classes to assist with the creation of games, or other realtime applications. Currently there is a 2D and 3D Vector class, and a well optimized 4x4 Matrix class, but eventually Game Objects will contain code for general route finding, entity management, AI and other cool stuff. I'm happy to take suggestions, and if you would like to submit code - even better! All classes should following these commandments.
I've uploaded a simple example of how to use OpenGL with PyGame. It's a listing from my forthcoming book, Beginning Game Development with Python and PyGame, and demonstrates how to initialize OpenGL, create a light and draw a simple 3D 'world'. It also shows how to use the camera matrix to create a simple 'fly-cam'.
To run it you will need PyOpenGL, which you can download from the website, or from the command line if you have Easy Install (type easy_install PyOpenGL
). Use the cursor keys to look around, and the Q/A keys to move forward and back. You can also press Z and X to roll the camera.
Here's a screenshot. continue reading…
Postmarkup, my BBCode parser module now has a new permanent home on google code (http://code.google.com/p/postmarkup/). It's more than adequate for my needs now, just wish I had time to work on my TurboGears site! I thought I would have more spare time since becoming a full time Python contractor, but I'm as busy as a... sorry, too busy to think of similie.
I had a little spare time to do some work on postmarkup.py, my BBCode module. It now handles Unicode correctly, which was a big omission, considering its intended use. I also added a few other features. The tag parameter string can now be specified in 3(!) different ways. For example, the following 3 lines are equivalent.
[link="http://www.willmcgugan.com"]My homepage[/link]
[link http://www.willmcgugan.com]My homepage[/link]
Another addition, is an [img]
tag.
There is also support for lists (ordered and un-ordered), with the phpbb syntax. For example:
[*]Apples
[*]Oranges
[*]Pears
[/list]
This produces an un-ordered list. continue reading…
I enjoy optimizing code. These days I don't get the opportunity to do it very often, since I prefer working in high level languages now. Which is why I have been particularly enthusiastic in optimizing the 3D math classes in Game Objects. continue reading…
I've just uploaded a new version of Game Objects. The 3D maths classes (Vector2, Vector3 and Matrix44) are reasonably stable now. I'd like to invite Python coders to play around with them, and suggest any improvements. My intention was to make something that was very easy to use, but well optimized. Game Objects is public domain. Do what you want with the code - go crazy!
There is no documentation at the moment I'm afraid, but here are a few edited highlights.