• Advertisement
Sign in to follow this  

Question about event handling

This topic is 1823 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

Hey I know that "event" may not be the right word for this but I am making a RPG rouge type game and the basic premise I am working with right now is leveling up... The idea is when the player levels up they can select to raise thier HP, Power(attack), or Toughness(defense) by 1 point or take a "perk" instead. One of the perks I have in mind is a Lifelink ability... If you deal damage greater than 0 you gain a portion of that in HP.

 

In my mind I think of it as an "event".... Player dealt damage, any effect that activates when the player deals damage is activated and the code is run. I know events are used for GUI and input. Should I use delagates? I know I could just hard-code switches or if statements but that seems like a poor way of doing it... I have thought of an entity component system but that would requre a massive rewrite of my code and I am not looking to do that right now.

 

How can I implement something like that in a generic modular way where I can have diferent conditions that the perks could react to...(if that makes sense).

 

Thanks,

Nick

 

EDIT: I think I found what I was looking for... creating a system that allows the objects to send messages to eachother when they do things, using a finite state machine. Any other idas are still appreciated!

Edited by BambooCatfish

Share this post


Link to post
Share on other sites
Advertisement

Most major games have an event bus of some sort.

 

A common pattern is:

 

 

EventSystem.AddListener( int eventID, delegate)

EventSystem.RemoveListener( delegate )

EventSystem.SendEvent( int eventID, ... );

 

There can be additional versions with assorted parameters, such as adding a listener that only triggers on a certain actor, or on a certain target.

The SendEvent function could either be a variadic function (using the ... notation) or it could have several overrides that take specific parameters.

Share this post


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

  • Advertisement