[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] game design techniques



On Sep 5, 2004, at 8:23 AM, Josh Close wrote:
I'm starting to do some game design for the first time. I can get
things to move around the screen, but I don't really know what I'm
doing. What are some of the game design standards? Probably for just
2D games to start.
I don't know that there are any real "standards" beyond those that people impose upon themselves after figuring out what works for them. For games, as for other areas of programming, I find that the best way to learn is simply lots of trial and error, as well as looking at others' code. Fortunately, python simplifies and quickens the trial and error process.

How do you organize things?
Well, I'm still working on my first pygame project so I still have lots to learn, but for what it's worth: So far, I've got the bulk of the game logic in a single class which handles the game loop, creating all game objects, etc. I have a separate sprite subclass for each type of object in my game, as well as classes for game levels, the high score table, and a group of classes implementing a state machine for the game state, plus some small utility classes.

How do you get objects to move smoothly?
That depends. In my project, I'm throttling the game at 30 fps. At the low resolution I'm using, all modern machines I've tried it on seem to handle my game at 30 fps with ease, which means I can easily make smooth movement occur by coding as if the frame rate is constant (since in practice it generally is), just making sure that the movement vectors for each object are small enough pixel increments that movement appears smooth.

How do you get objects to move at different speeds?
Either give them different movement vectors, or don't update some of them every frame.

 How do you get
objects to not go past, say, a wall?
pygame provides nice collision detection functionality which helps with this. The problem that can occur is if the movement vector for a particular object is larger than the size of the object plus the size of the obstacle; one object can, in effect, "hop over" the other and the collision detection system won't bat an eye. So far I've avoided this by making a special case (keeping movement vectors smaller than that) but there are general solutions as well; Such a solution is presented in the book I mention later on.

Are there any good websites or books that would have some standards
for this sort of thing? Like a tutuorial or something? I've looked at
all the pygame docs examples, and that doesn't do much right now.
I'd recommend the book "Game Programming in Python" ( http://www.amazon.com/exec/obidos/redirect?tag=rebisoft-20&path=tg/ detail/-/1584502584/qid%3D1094419296/sr%3D8-1 ), it covers a lot of interesting territory. I haven't read the whole thing yet, and this is the only game programming book I've read (there are others out there), but so far so good. My current project was started before I picked up this book, and I haven't had the time or inclination to "re-tool" everything to match the methodologies/standards described in GPiP, but my next game project will probably borrow heavily from its concepts.

// jack