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

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



Hi Kai

See inside ...
On 3/20/06, Farai Aschwanden <fash@xxxxxxxxxx> wrote:
Hi Kai
See inside...

[ Moving, Blitting]
=> What you probably want to say is that you would like to work in
the pure OO way, like in Java or C/C++. Python is highly dynamic and
easy to use. You don't need to care about creating new instances of
the same object like you do in the mentioned OO languages, Python
references to the newly created objects (ghosts), you don't need to
create an expl

Hmm, i don't know what you mean. Do you mean "new instances of the same class"?
=> No, creating new instance of object "Ghost"


If you want to make it more complicated, check the class Thread. ;)
The Ghosts are all of the same type of object, they only differ in
their coordinates. So why making it more complicated?

I don't know how to make it easier. When i hit a 'G' in the List, i replace it with a Ghost-Object:

if c == 'G':
    c = Ghost()
=> Its turns too complicated to scan the whole list to check what type of object to display. Well it's a way...
How about to work with a list or a dictionary? Like
monster_list = [(color_a, x_coordinate, y_coordinate, ), color_b, x_coordinate, y_coordinate, ), ...]
This list repesents 2 ghosts in 2 tuples that you only have to go through and read out the coordinaties for blitting them by their coordinates (you need another routine updating those coordinates depending on the movement of the ghosts). You also can add more tuples (more ghosts) or creating a new list for the non moving big pills that the Pacman can eat to catch the ghosts for a certain time. If a ghost is caught you can reset is coordinates at his revival coordinates. The small pills needs to be displayed as well.




=> There is no right and wrong way, its all up to you and how much
work you want to spend into it to finish it. Some ways needs of
course more time than others.

Hm, i think I will make a master-class. Otherwise every object have to know where the other objects are.
=> You have to create a master class, like any program got it. Just a very draft "doing" list inside this master class (independent if there are called functions/other classes in it):

start loop main_class:
- check player input (keyboard, joystick, ...)
- repaint Pacman depending on players moving direction (update new coordinates of Pacman)
- Move Ghosts (here you need a "stupid" or smart (AI) function to move the ghosts around)
Keep in mind to add a move delay routine in here (how fast the ghosts are moving around). The
higher the level there might come more ghosts and/or they move faster (just as an idea).
- Check: Pacman got hit by a ghost (Pacman's coordinates are close to a ghost's coordinates from
previous described list or easier: Pacman and ghosts are sprites -> collision detection)
stop loop main_class


This was just a brainstorming to give you some ideas how it could be done. Of course there are other ways to do it.

As mentioned in some other mails adressed to you there are many, many examples and descriptions around.

Regards
Farai



Second question:
[How about a background list?]
=> You always know the positions of the ghosts and also of the Pacman
(f.e. in a list) . The only thing you have to do is to use collision
detection or to ask if the coordinates of the Pacman is close or
equal to any other existing ghost. This can be done very easily in
Python.

Ok, that's a great thing. Thank you.


=> Good luck on working it. Sure there would be easier games as for
the first project but people need challenges. ;) And its also
interesting to walk into to the steps of minds who created such games
20 or 30 years ago. ;)

Thanks for you answer. Kai