Archive for July, 2009

A unittest green bar for the console

One thing the unittest module is missing for me is a green bar of success (or a red bar of fail), so here’s one I cooked up to scratch my itch (windows only at the mo’, sorry):

import sys
import ctypes
import unittest

class GreenBarRunner(unittest.TextTestRunner):
    FOREGROUND_GREEN= 0x0A
    FOREGROUND_RED  = 0x0C
    FOREGROUND_WHITE= 0x0F
    FOREGROUND_YELLOW=0x0E

    def __init__(self, verbosity=2):
        unittest.TextTestRunner.__init__(self, verbosity=verbosity)
        STD_OUTPUT_HANDLE = -11
        self.std_out_handle = ctypes.windll.kernel32.GetStdHandle(
            STD_OUTPUT_HANDLE)

    def set_color(self, color):
        bool = ctypes.windll.kernel32.SetConsoleTextAttribute(
            self.std_out_handle, color)
        return bool

    def run(self, test):
        r = unittest.TextTestRunner.run(self, test)

        failed_count = len(r.failures)
        errored_count = len(r.errors)
        total = r.testsRun
        ok_count = total - (failed_count + errored_count)

        sys.stdout.write('\n[')
        self.set_color(self.FOREGROUND_RED)
        sys.stdout.write('#' * errored_count)
        self.set_color(self.FOREGROUND_YELLOW)
        sys.stdout.write('#' * failed_count)
        self.set_color(self.FOREGROUND_GREEN)
        sys.stdout.write('#' * ok_count)
        self.set_color(self.FOREGROUND_WHITE)
        sys.stdout.write(']\n')

Usage:

suite = unittest.TestLoader().loadTestsFromModule(example_module)
GreenBarRunner(verbosity=2).run(suite)

It’ll execute the TextTestRunner so you won’t lose the test names and stack traces and afterwards display a red/yellow/green bar:

GreenBarTestRunner

Ta-da.

Zombies!

Hey folks, yup first blog post here! (and hopefully not the last)

Two days ago I began work on a zombie shoot-em-up top-down game – basically you get chased down by unending hordes of zombies and you’ve got to shoot them all. At the moment it’s pretty basic, but I’m happy with the progress I’ve made so far:

The player currently moves around using WSAD for forward, backpedal and strafe, and uses the mouse to aim/face in a particular direction.

Specifics of stuff implemented:

  • Map scrolling
  • Zombies pathfind using A*, and adjust their route so every couple of seconds. They have no maximum range, and can track the player across the map. With more than two dozen zombies the game crawls to a halt (unless the player stands still).
  • Blood splats and spray appear with each shot. The splats will stay on the ground for a little while, and the spray will stick to walls.
  • Ammo counter and ammo crates.
  • Huge compensation cannon pulse rifle.
Return top