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

Re: [pygame] My first game; the design of pacman



> First of all, i have map files.
> A map looks something like this:
>
> ####################
> #                           #
> #                            #
> #   P                       #
> #                           #
> #               G             #
> ####################
>
> Where 'P' is the Pacman... and so on.
> Now I go and read the mapfile into my program
> and replace the specific characters with real
> objects ("Pacman" in this case). Now I wanted
> to add to every object (like Ghost, or whatever)
> update and draw methods so that they can draw
> "themselves" onto the screen. Or would it be better
> to get all the objects and blitting them onto the
> screen, after I have moved them?


The usual way I go about drawing game objects that need to be redrawn every frame is to take advantage of the pygame.sprite module. Heres a good tutorial on the subject: http://kai.vm.bytemark.co.uk/~piman/writing/sprite-tutorial.shtml

> I'm a bit confused whether there should be a
> "Master class" which controls everything or if
> every object should take care only about itself.

Theres pros and cons for each of the two approaches. When you have each object take care of itself that means that each object will need to be aware of all the other game objects, and it will also need to manipulate them. Depending on the size of your game this can make changing game logic a nightmare as modifying one object might break another. It also can make it difficult for other people to follow the game logic as they'll have to jump from file to file just to see whats going on. An advantage though is that if say you wanted to see what code is making pacman eat pellets, instead of sifting through a massive control class, you just look at the Pacman class.

The good thing about having a master control class is that all the control logic is in one place. However like I touched on earlier finding a specific piece of code like pacman eating pellets could get difficult depending on its size. However good commenting and documentation can offset this.

I would recommend that you try both approaches so you can experience this for yourself.

> Second question:
> When all the objects ("Wall", "Nothing", "Pacman" and so on) are all
> in my list... what's when Pacman hits a Ghost? I know, I should use
> a second list. And in this "background" list, there should lie all the
> objects, that *don't* move. Right?


Like I said earlier you should look at the sprite module included with pygame, it gives you an elegant way to group your pacman and ghost objects and detect collisions between the two.
As for the background you know that the walls don't need to be redrawn, so you'd get better performance if you just blit them on the screen once.

And like the other guys said, you might want to try making something like a pong clone where these issues will come up, and you won't have to worry about stuff like complex ghost AI and map navigation.