Aight I'm finally going to help you out
Hope you had a great Christmas(If you celebrate it of course, otherwise it's just I hope you had a great day
)
Okay, so let's first establish what you want to create. What you want in your game is that the player potentially
triggers something and an
action is accordingly taken. That's known as an action-trigger system. The system is basically that you have a trigger object that checks if it has been triggered, you can make this as advanced as you want, if it is triggered then you tell it's action object to run. This is just scratching the surface of the system but you'll learn more if you try and fail yourself first, I'll always be here to help you again.
Anyway let's say we do it like, when something is triggered, we run the action in it's own thread. Then what if two actions are run that both want to output some kind of messages to the player? Like a message box as this
this one. Then the two threads would start overriding each others text. Things like this is fixable but it gives much more headache than needed. If you want an
action to wait 2 seconds but not lock the whole system then you can just simply have a
trigger that takes a specific elapsed time. All it needs inside itself is a sf::Clock and a float telling it when to trigger. Looking something like this:
class TimedTrigger : public Trigger
{
public:
bool Update(Engine &engine)
{
if(myClock.GetElapsedTime() > myTimeToTrigger)
{
TriggerAction();
return true
}
return false;
}
private:
float myTimeToTrigger;
sf::Clock myClock;
};
Why I have the Engine argument there is because I think of the
Update() of being a pure virtual method in the
Trigger class. And we need some object to check against if we are supposed to trigger or not. A more complex way to do this(but it removes the virtual call) is to make the trigger receive signals that give various information and make it only trigger when it get's an interesting signal like in this case maybe: "Signal.Application.Update" and take the delta time passed with the signal. If we would like to know if some character moved, then it would be: "Signal.Entity.Moved" and use the coordinates passed to check if we want to trigger. This is just an example using the same system as me of course.
Aight, Like I said, try yourself and fail and then come back and tell me what you think you made wrong(reflect a little bit) and I'll give you a more in-depth view of how the action-trigger system should be built.