Re: RPG game in UML
- From: "Phlip" <phlipcpp@xxxxxxxxx>
- Date: Sat, 24 Sep 2005 22:00:43 GMT
weer1 wrote:
> I am developing an RPG game and was wondering if I would have
> advantages when I use some OO for the battle-engine. Actually I am now
> trying to model the whole game in UML, just for the fun of it.
>
> I have a model like this now:
>
> GameObject
> ^ ^ ^
> | | |
> Hero Tree Stone
The source to the original Rogue (the character-mode game on a VT100 console
where you crawl a dungeon, fighting each letter of the alphabet until you
get to the Amulet of Yendor) used that pattern, in C. Specifically, it had a
'struct Object' with a bunch of members. Suppose one was Power. To
"polymorph" this into a Monster, C used
#define Object Monster
#define Power Strength
That's not really polymorphism (and I'l get beat up if I don't get to be the
first to remind you that the C languages should not abuse the
preprocessor...).
The polymorphism comes when each object has a pointer to a behavior
function:
struct Object {
int Power;
void (*behave)(Object * obj);
...
};
Now the main work loop of the program only needs to traverse a list of
objects, calling each one's behave() function. This will polymorphically
adjust its monster or object, adjust the map, and/or adjust other objects.
> Thats about it. I also got a simple relation between hero---player.
> And an Action-class still hanging loose.
>
> Now the fun starts.
>
> Lets presume there are only hero-type characters in this game so every
> player(user) has a hero (not A character). I think weapons play an
> important role. A Tree could be the weapon for a hero. Even a tree
> could BE a hero (yes, you can play a tree in this game!).
>
> If I do, how do I model these things?
Modern games animate everything. Getting attacked by a huge B might once
have been scary (if you were _really_ low on ammo, weapons, and hit
points;), but nowadays that bat must flap and stuff.
So, each aspect of each game object is, in turn, an object. A Bat is an
object containing a Wing object pointing to a State of Flapping, containing
an index into a Flap Animation. Attacking a bat requires sending a message
to the root object, so its AI component decides to flit away, so it repoints
its State to FlapAway, and synchronizes the index of the animation to the
matching index, permitting a smooth transition.
This all requires a generic component hierarchy (Composite Pattern), a
system to render that hierarchy to the screen (Interpreter Pattern), and a
phat message bus to carry all these messages around (Observer Pattern
between any two components). Without all those objects, you either use
threads (which are hardly a design solution), or your attack() method does
not return until the Bat has animated its wing in FlapAway mode.
>From here, you may want to download one of scores of open source games and
read their source. Game programming is one of the hardest disciplines
available today.
--
Phlip
http://www.greencheese.org/ZeekLand <-- NOT a blog!!!
.
- Follow-Ups:
- Re: RPG game in UML
- From: weer1
- Re: RPG game in UML
- References:
- RPG game in UML
- From: weer1
- RPG game in UML
- Prev by Date: RPG game in UML
- Next by Date: Re: RPG game in UML
- Previous by thread: RPG game in UML
- Next by thread: Re: RPG game in UML
- Index(es):
Relevant Pages
|