Python, Game writingOctober 17, 2005 1:32 pm

Overview:

So we successfully jammed on Saturday. Most important things first (a priority that cost me on the day), a pretty picture:

pyai

Ok, so it’s not that pretty - but as a result of less than 8 hours work, it’s not so bad. The green dudes move around the world. Two of them drop purple slug trails and do a very dumb wall following. The other two do a similar dumb wall following but bleet sounds when they hit a purple trail. The bleets move around the world, propogating and stopping when they hit walls. Odd, but lovely and general.

Setup:

  • Hardware - Two PCs (Dave’s shiny laptop, Dom’s tiny PC and ridicoulously heavy CRT. I’m buying a bloody TFT if I’m ever doing this again! Actually, scratch that, I’m getting me an iBook), USB hard disk, pad of paper.
  • Software - Python 2.4, Pygame, Subversion, TortoiseSVN, Emacs/IDLE, Paint Shop Pro.

Timeline:

10 til 11: Dave makes coffee. Sketching general plan on bits of paper. Decide on a discrete 2D grid where agents can move in straight lines. Agents can sense properties of other agents and can spawn/destroy agents. Every agent takes it in turns to move, so world mutated in place.

11 til 12: Cake. Arrays in Python. Simple colour filled images in Pygame representing array. Setup subversion local server.

12 til 1: Matthew arrives and looks puzzled. Got single dude (a green square) moving towards a wall (red squares) and running through it.

1 til 2: Quiche. Got dude bouncing off wall into oblivion. Paved over boundary to oblivion. Added slug dudes that left purple trails. All dudes bounce of purple trails.

2 til 3: Chocolate covered coffee beans. Check out repository to Matthew’s disk for Dave to work off. Realise how much better svn is than cvs. Dom/Matthew work on making renderer shinier. Dave works on having more than one thing per cell.

3 til 4: Yum yums. Dom has written bad isometric engine. Matthew realises a Better Way. All whoop as walls suddenly pop into glorious 1983-isometric-style existance. Dave writes level reader.

4 til 5: Dom draws some not so pretty pictures for agents and walls. Talk about general voxel engine. Remember the company we work for.

5 til 6: Matthew goes home for parential responsibilies. Work on adding sounds to world. Supposedly propogate around the world, letting other agents avoid stuff. Demonstrates flexibility of what we’ve done, but doesn’t quite work.

6: Fin.

Bad Things:

  • It’s not a game!
  • The isometric renderer took 2 hours
  • Mechanical refactoring in Python is hard to do in a bug free way. Compilers do this well
  • Time pressure makes ditching bad implementations hard

Good Things:

  • It’s a lovely general tilebased AI engine!
  • Writing something graphical with Pygame is very easy
  • Having 3 people in one room with a tight timescale avoids coding inertia
  • Subversion is great

What I Learnt Today (or Saturday, in fact):

The stuff that I find hard is also stuff that other people find hard (shocking, heh?). The difference is that brighter folk keep the options in the background and go for the best option given current information. I typically stay in a stuck state.

Small concrete goals are good. ‘What are we going to do in the next hour’ and the like.

Having someone watching me work is great. Matthew pointing out how stupid my rendering logic was helpful. A step back saved us yet more pain.

More XP style estimating and planning would have helped. We could/would have dropped the rendering/sound propogation and moved onto something like user movable objects, or something more game like.

Python works well when types are fluid, but is painful once you’ve decided.

I get distracted too easily. People pestering me to get on with it is a good thing.

Cake is good.

Nintendo DS, LuaOctober 10, 2005 11:32 pm

More fun with coroutines. Having written off Lua for the job (creating new variables due to typos? Agh!) we decided to have a look elsewhere. There’s not exactly a glut of small embedded languages that support coroutines. In fact, there’s just one, Io. It looks really interesting, but frankly it’s a bit too bleeding age for me right now (F# is about as bleeding as I can cope with).

Anyway, implementing game logic in coroutines is still a cunning plan - the more Dave describes it the more cunning it gets, so I tried (naively) good old Python. It’s had generators since 2.2, so maybe, just maybe, I could write coroutines using some dummy yields. Ah. No. Realised this evening (with a little prototyping and other help) that it’s not possible without switching to Stackless Python. Which would mean breaking all the libraries I want to use - the major merit of Py. Sigh.

In other (kind of related, and better) news, my DS PassMe arrived today. Now I can start ‘real’ DS development. In that vast amount of spare time I have. *cough*

And in further (kind of-kind of related news), myself, Dave and another colleague, Matthew are attempting our first Game Jam this weekend. Hopefully we can get something fun done in a day - I’ll post the results next week!

Graphics, Visual StudioOctober 3, 2005 10:38 pm

After using C++ in anger for about four years I’m constantly troubled by coding inertia - when you know you should create a new class/factor out a base class/extract a method - but it’s just a little bit too much effort. Especially when combined with CVS and multiple Visual Studio 6 workspaces/projects. Yagh!

So? Well, C#, Visual Studio 2003 and Subversion working together almost gets rid of this inertia. The only problem remaining seems to be me. I still put off (or at least overestimate and dread) what end up as simple, mechanical refactorings.

The motivation for this upbeatness is that I just managed to rip out the hardcoded particle generation and force application from my particles engine and add fountains that move in the wind in about 10 minutes.

fountains

Tomorrow, hopefully, I’ll get them reacting sensibly to some implicit surfaces (well, some kind of floor, to be precise). Oh, and they look better moving. Honest!

Nintendo DS, Lua, Visual Studio 7:12 pm

I’m quite happy with Visual Studio 2003 (I’ll be even happier with 2005, judging by the beta). I’m determined to use it for as much coding as possible - something I never managed in Visual Studio 6.

Anyway, I’ve semi-happily got it working with F# (an OCaml under the CLR, for those who care. A lengthy post may eventually appear on this subject). Tonight I’ve started using Lua again and have got into a reasonable state of editing/running code in Visual Studio. I downloaded lualite and added lua.exe as an external tool in VS with $(ItemFileName)$(ItemExt) as arguments and $(ItemDir) as the initial directory.

There’s probably a better way of getting it to play nice with project configurations and the like, but this will more than suffice for now.

As for justification for Lua? Well DaveT (a wise work colleague) has a crazy idea That Might Just Work about Lua and DS development. I’ve currently got plans of a yielding PacMan. Don’t ask.