Ok, I have GameCore class which handels EVERYTHING. I have three states in my game
1) Main Menu
2) Game
3) Intermission
On both Main Menu and Intermission I need it to check if RETURN is pressed, and if so, run a function in class GameCore. Now in EventRecieve.h(my code) I can't include GameCore.h because it would then in turn re-include EventReciever.h and loop.How can I get it so if a key is pressed, run a function in GameClass.h?
class MyEventReceiver : public IEventReceiver
{
private:
bool events[NUM_EVENTS]; // Stores true if event has been fired
public:
virtual bool onEvent(SEvent event)
{
if (event.EventType == EET_KEY_INPUT_EVENT)
{
if(event.KeyInput.Key == KEY_RETURN){
if(!events[RET_PRESS]) // Lock (sync for threads)
events[RET_PRESS] = true; // Fire
}
}
}
}
class GameCore
{
public:
run() {
checkForEvents(); // Every frame
}
checkForEvents()
{
if myEventRecevier->Activated(RET_PRESS) {
func(); // Call to your function
myEventRecevier->Invalidate(RET_PRESS);
}
}
}
*RET_PRESS and NUM_EVENTS have to be declared.
On both Main Menu and Intermission I need it to check if RETURN is pressed, and if so, run a function in class GameCore. Now in EventRecieve.h(my code) I can't include GameCore.h because it would then in turn re-include EventReciever.h and loop.How can I get it so if a key is pressed, run a function in GameClass.h?
Don't know if I really understood your problem, but the solution is to use forward declaration. In your GameCore.h file instead of including "EventReceive.h", just use a forward declaration of MyEventReceiver and include the file in your cpp file instead: