Playing a sound in pygame

Posted by stu at February 24th, 2008

It can be useful to test sounds in your current engine (esp for testing MOD support), so I’ve made a tiny sound player for pygame. The code is just this:

import sys, pygame
from pygame.locals import *

import pygame.mixer

if __name__=="__main__":
    pygame.display.set_mode((120, 120), DOUBLEBUF | HWSURFACE)

    pygame.init()

    try:
        filename = sys.argv[1]
        pygame.mixer.init()
        sound = pygame.mixer.Sound(filename)
        print 'Press ESC to quit, any other key retriggers sound'
        sound.play()

        running = True
        while running:
            for event in pygame.event.get():
                if event.type == KEYDOWN:
                    if event.key == K_ESCAPE:
                        running = False
                    else:
                        sound.play()

    except IndexError:
        print 'Usage tplay.py filename'

The file is attached here: Tiny pygame audio player.

Posted in projects| No Comments | 

Ball breaker update

Posted by stu at November 19th, 2007

Reached a small milestone in my bat and ball game (BallBreaker), the fonts are implemented as bitmap fonts, meaning that everything on the rendered on the game screen is original material.

The current font system is based on tiles, so it should be easy to implement animation and cool stuff next, it definately feels like the project is about 1/2 way to releasable.

Switching to Cairo is starting to seem attractive, especially when making bitmapped versions of the fonts.

For the moment I won’t switch to Cairo as I’m very curious to see what happens to performance when pygame 1.8 comes out.

Another reason I haven’t switched yet is a bit of lazyness – the pycairo msi doesn’t install the cairo dll… and of course the learning that goes with the new API :)

Posted in projects| No Comments | 

Retro font

Posted by stu at October 8th, 2007

I’ve just finished the initial version of the font that’ll go into my game ball breaker (“Ball Breaker Caps”)… Some of the characters need more work, but it has the retro-future look I’m going for.

This means that I can feel happy about putting in the high score table and scrolling messages and they’ll have the look I’m going for.

Posted in projects| 3 Comments | 

Ball Breaker!

Posted by admin at October 5th, 2007

I’ve recently started learning python in earnest, to this end I’ve been writing a bat and ball game. I’m quite suprised at how much you get for your LOC in python… so far it’s about 1,000 LOC and has multiple powerups and bats, plus sound fx by ne7.

Title screen of ball breaker,

Graphics are made in inkscape and the GIMP – ingame screenshot after the cut.  (more…)

Posted in projects| No Comments | 

« Previous Postings