I have an idea of how I want to approach this but i'm not sure if it is ideal. By event I mean for example, if the player wins, a bunch of sparks fly for 1 second. I was thinking of creating my game engine class, then creating a game event base class that has 3 void functions, update, draw, render. There could be for example fireforks for collecting 100 coins for 3 seconds. The way I want to implement it is by having an event vector in my game engine where I can push the fireforks animation in. once something is pushed in the vector, the game does event[i].render() etc... For removing it I thought that each event could have an event length in frames, and each frame a uint is increased, if the uint matches the length, it is popped from the vector. I just wasnt sure if doing it like this was the best way.
Thanks
I would have each event instance have a method called isDone, or something like that. Then, for each frame, iterate through your events and:
if (event.isDone()) {
//remove the event
} else {
event.update();
}
Doing it this way allows for easier changes in the future. Not all events will last for a fixed amount of time (this might not be true for your game), some might even depend on things other than the current frame.
But in your eventBaseClass, you could define isDone as:
return this.endFrame >= game.currentFrame;
and override it in any events that you need to.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With