Level Design in Pygame


Question

Hey--I'm trying to design my first game using the Pygame library for Python, and I was wondering what the best practices are for level design in general. I would love to hear what you guys think are good object oriented design patterns for managing levels. Also, I'm fairly new to Python--thanks!

1
3
12/9/2009 5:01:37 AM

Accepted Answer

With this type of game your maps are in terms of tiles (I'm assuming that by level you mean an individual level, not managing all of your levels). Each tile has

  • an associated picture (what it looks like on the display)
  • a type (ie, a wall, the ground, a trap, etc.)

When I create tile-based games in Pygame, I usually have a Map class which contains the current map:

  • the pygame.Surface of the map (what you'll be blitting to the display)
  • a list of lists (ie, a matrix) where each item is a Tile object (I've also done games where you just have a string that tells you what type of tile it is, and then you don't need a separate Tile class)

The map should be relatively static - you could have that traps become normal tiles after you step on them (this is pretty easy - when you do collision detection and it's a hit, just change that tile to a different Tile object (presumably the one for an empty tile)), but you don't want characters or movable blocks in the map if you can help it. Since the movable blocks have their own rules for how they can be moved, it's not as simple as just changing a tile - you'd have a whole set of logic, and at least two tiles would have to be changed (and what if you could move the blocks onto traps - you'd then have to remember, separately, what was below it - bleh). In my opinion it's easier to just have a class for each moving object and item.

In short, you have:

  • Tile
  • Map
  • Block
  • other movable objects/sprites

And that's basically your whole level. For multiple levels, if individual levels are always the same, you can just have a list of Map objects, one for each level.

8
12/9/2009 12:03:04 PM

If this is your first Pygame application, don't spend time worrying about "object oriented design patterns for managing levels". What you need to do now is to figure out how to make Pygame do what you want it to do.

  • Can you display everything you want to?
  • Is your display flicker-free?
  • Can you read the user input controls properly?
  • etc.

Object oriented patterns for managing levels comes later, much later.


Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon