Yesterday was just one of those days. You know the days where you can't seem to wrap your head around a concept. For me this concept was how to create a system that could easily handle events. As I am currently winding down on major coding parts for the recursion game, I found myself struggling to add certain events to the game. While with an event system this should make it easier, for lack of words it was not.
So let me describe the system. You have an App that is running. The App can be thought of as the main program. The App contains a pointer to a Screen. Anytime the App wants to update or draw, it calls the Screen's update and draw. Now the Screen can hold anything, but for this you only need to know it holds Rooms, with Game_Objects in it, and a Player. Think of a Room as a mini screen, where Game_Object is object the player can collide with, which allows us to have collision and triggers. So if your still with me great! If not then sorry you will have to look at the picture.
Currently the system handles four types of events: Timer, Keyboard, Mouse, and Collision. A problem right off the back in my system is that collisions are handled by Box2D, while keyboard and mouse events are handled by the App. Do I think of this a major problem, not really, but it would be nice to have them all centralized. So right now if the player collides with a Game_Object, the object will have a function called to handle that event and perform whatever actions it needs to.
That is all that I have and it becomes very tricky when adding a new events because of new classes, but after talking to a very good friend of mine last night. If I were to do this again I think there would be major changes. So let me describe the new system and maybe it can help you if you need one someday.
The first thing I would do is make the distinction between an SystemEvent and a GameEvent. A SystemEvent is something that happens in the system that should then notify all Listeners that "HEY ITS TIME!! ITS FINALLY HERE!!!" and the object should say, "OMG I CANT BELIEVE IT!!!" and the a big party happens and everyone goes home happy. SystemEvents would be the four main Events previously described, Timer, Keyboard, Mouse, Collision. A GameEvent on the other hand is purely based in the game. So an example of a GameEvent would be an Explosion, DoorTrigger, and anything else that requires a effect on object in the game. Now this may seem confusing so let's talk about an example.
So your main character is walking through a lovely room with white walls(the building is cheap so its all they could afford) When your character sees a larger red button. Of course you are going to go hit the big red button!!
Now when you hit the button by a colliding with it it sets off an explosion!!!!
Now in this example you can see that a SystemEvent was fired by the player colliding with an object. This event was passed to the object similar to the old system, but now that object will push a new Event to an Event Manager. Such as with our example an explosion. The Event Manager can now contact every object that is listening for an Explosion Event and say "OMG DID YOU SEE THAT?!?!?".
This approach allows from input to come from different place and funnel them into one area that can then be interpreted and handled by anyone who is listening. There are some draw backs and of course everything is situational. So this may not fit your system very well. Like this system I will trigger a BLOG EVENT and say,