Jump to content
  • Advertisement
Sign in to follow this  
Telamon

Handling between entities - Need a good design...

This topic is 4815 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I just added (openable/closeable/smashable) doors to my roguelike game. Right now right-clicking on a door brings up the actions that you can perform on it in a nice context menu. Like so:
The exercise has given me an inkling of a design problem that I'ven't anticipated. How do I model interactions between game entities? At the moment, I have an abstract Entity class which I subclass for Items, Doors, and Critters (the PC is a critter). The get the doors working, I just added several functions to the Door entity (Open, Close, Smash). Then, when I need to generate a list of actions that can be taken on a tile, I loop through all the entities on that tile, check if it's a door, check the door's state, and generate the appropriate list of actions. This is kind of messy, and door interactions are pretty simple. So I think I need some sort of event/message processing system? The thing I am trying to avoid is having, for example, a Critter entity trying to open a door, call the Door entity's OpenDoor() function directly. I think all these requests should be channeled through a message system of some sort. This should make it easier to manage things like printing out notifications to the text console... If I sound confused and unsure, it's because I am. The system I've worked out as far as the Entities are concerned, I think, is pretty good and has worked well so far. So maybe someone can help me with the last piece. PS - I'd also like it to be easy to generate a list of all actions that can be taken on an Entity - both for pushing this info to the GUI and for pushing environment data/options to the AI.

Share this post


Link to post
Share on other sites
Advertisement
how about parent/child relationships?

set up the door with a linked list of children "actions" and a simple AI to control them (basicly doors are then critters)

For example a door critter could have two children actions "operate" and "smash"...each action itself can be a critter entity that effects its parent.

So the player comes across a door and right clicks on it...the game then runs through the list of children and reports them to the GUI..."operate" checks if the door is open or closed, and sends the GUI the appropriet menu item..."smash" does the same...player selects open and the "operate" critter changes the parents open/close flag...and the parent then chages to the appropriate graphic, and switching to allow things to walk through it.

In this way the "action" critters could have "action" children of thier own...for example there could be a "lock" critter with a "operate" child action...activateing the "lock" option could then promote its "operate" child to a sibling (or from door->lock->operate to door->operate->lock) allowing the door to be opened/closed.

Additionaly such "action" critters could be placed elsewhere on the map allowing the same system to be used for remote switches/pressure plates/etc. to open/close doors...

And by useing a list of active critters you can keep processing time down despite everything haveing its own AI...player selects "open door" which adds the "operate" action to the list of active critters. next update the "operate" action adds the parent door to the list of active critters, and removes itself from the same list...next update the door critter changes its graphic and collision settings and removes itself from the active critter list, etc...

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!