Re: Double Dispatch Problem: Mobile Creatures and Projectiles in a Game World
- From: "Aaron J. M." <ajmacd@xxxxxxxxxxxxxxx>
- Date: 29 Mar 2007 10:45:05 -0700
On Mar 29, 9:50 am, "Daniel T." <danie...@xxxxxxxxxxxxx> wrote:
I don't think there is a "lazy" solution, you need two lists. Here's a
+reportCreaturePostion( Point )
+reportProjectilePosition( Point )
+creatureAt( Point ): boolean
+projectileAt( Point ): boolean
+attachTo( World )
Mobiles tell the world where they are, and ask the world if there are
any creatures or projectiles at that location. If there are, the mobile
does what it knows it should do.
So, World keeps two lists (Creatures and Projectiles), and all
are able to attach themselves to a World. World would need the
attachCreature(Creature, Point) and attachProjectile(Projectile,
in that case. I'd also have to change World whenever I wanted to add
new type of Mobile.
It might get more complicated when I want to get timing involved.
just one list in World I could give World the method update() which
tells all the Mobiles to move(). The two lists could be just as easy
since I could loop through both lists, but what if I want every
to have a "speed" which affects the order in which they need to be
updated regardless of their actual class? I would have to introduce
third list that holds (references to) all of the Mobiles and loop
through that when I want them to move.
- Prev by Date: Re: Long Life Objects
- Next by Date: Re: Separation of concerns
- Previous by thread: Re: Double Dispatch Problem: Mobile Creatures and Projectiles in a Game World
- Next by thread: Re: Double Dispatch Problem: Mobile Creatures and Projectiles in a Game World