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

Re: [pygame] Cross-References



--- Kris Schnee <kschnee@xxxxxxxxxx> wrote:

> Is this overkill, or is it all necessary? I'd like
> to have the game 
> world independent of the graphics engine, so that if
> I ever make the 
> leap to 3D the world will still work. (I also want
> the AI independent of 
> having a tile-based 2D world.) But this system
> creates a whole lot of 
> cross-references so that I can, eg:
> -Look up a character by name/ID
> -See the contents of a specific tile without asking
> every entity in the 
> world "are you here?"
> -Move a character within the game world
> -Tell the graphics engine to move the character on
> screen
> 

I've been through this, too. My conclusion, after
doing it two or three times, is that if you want to
give objects access to critical data like sprite
references or the position of other objects at all
times, you should be storing things in a global class,
and then anytime they want something that isn't
explicitly given to them, they reference through the
global class. The way to make a class accessable to
any namespace turns out to be relatively simple as
well, just non-obvious:

glo.py

class g:
    pass
-----
a.py
from glo import *

g.a = 2
import b
-----
b.py
from glo import *

print g.a
-----
'2'

> Re: a bit of code I haven't done, it seems like
> there has to be 
> coordination between Aquablue and Coral to make sure
> the graphics system 
> gets notified not just when a character moves but
> what animation they 
> should start playing, and I'm not sure whether the
> sprite system should 
> be explicitly told "play animation walk_north" or
> what.

The bulk of the animation-control work has to fall in
one area or the other - whether it should be part of
the AI, IMHO, would mostly depend on the nature of the
actions. If you were modelling physics like "move left
leg, then right leg" or just "x1->x2, y1->y2" then the
solution is a pretty natural progression of AI ->
physics -> graphics. But once you get into stuff
defined by rules like "perform spinning kick special
move" then the AI should command graphics directly to
play the animation - and if certain frames are
important for e.g. collision, AI is probably going to
want to manage every frame itself.

Hopefully that clears it up a little.

__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com