Jump to content

  • Log In with Google      Sign In   
  • Create Account


Question about event handling


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
1 reply to this topic

#1 BambooCatfish   Members   -  Reputation: 130

Like
0Likes
Like

Posted 24 January 2013 - 01:18 PM

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, 24 January 2013 - 01:41 PM.


Sponsor:

#2 frob   Moderators   -  Reputation: 19633

Like
0Likes
Like

Posted 24 January 2013 - 03:34 PM

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.


Check out my personal indie blog at bryanwagstaff.com.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS