Interaction (and access) between characters

Started by
1 comment, last by gabzuka 13 years, 9 months ago
Hey Guys,

I am making a game where the basic premise is that you control three characters and fight some monsters. Now, I have been having problems coming up with a way for these to interact with each other.

I have a TeamMember class and a Monster class. I have three instances of the Team Member class, one for each character you control and many instances of the Monster class, one for each monster.

Monsters should change state when they see the characters and attack them, this would mean changing the animation of the monster as well as firing the attacking mechanism all of which is inside the Monster class. Now the question is, what would be the best way of communicating these two classes?.

I feel there most be a clean and extensible way of achieving this as it is probably a common thing in games but I can figure it out. I guess I could pass the character positions to the monsters but what if later on I need the speed of the characters, or the health or who knows what.

Thanks a lot in advance,

G
Advertisement
Sorry if I'm overlooking something, but why not just store a pointer/reference to the current TeamMember target in your Monster class? That way you always have access to all information of your target without needing to copy anything.

Of course you could design this in a more abstract way, letting the target be a pointer to a common base class (of which both TeamMember and Monster would be derived) and deciding which attack patterns to use depending on what type the actual target is. That way you could make monsters attack each other too, for example when they're under a mind control spell or something like that.
I don't know what was on my mind but obviously that would be the easiest way.

I added a Entity class from where the main characters and monsters inherit so that they can have both as "targets" and could be expanded to have buildings, cars or whatever is in the game as a target as well.

Cheers

This topic is closed to new replies.

Advertisement