Hi all,
I recently started working on a simple networked Battleships game as I thought it'd be within my reach, thought I've run into an interesting problem and I'm not sure how to approach it.
Basically, I'm using a simple entity management class to display animations, and I'd like objects of that class to be able to call an action in the main game or do something else to otherwise let the game know they've finished animating. For example, when you click on a grid square to attack your opponent, I wanted a flashing crosshair animation to play for a few seconds before showing whether you hit or missed your opponent. Then, the game runs a function called "swapPlayers" that simply moves over to the other player's turn. The problem I have here is I'd really like to start the "attack" animation, but only call the "swapPlayers" function once it has displayed for the time I've specified. As it stands I call them both at the same time, which means the animation shows as it should, but also immediately changes turn, which means you can't see if the shot you took actually hit or missed.
Hopefully the above explanation makes some sense. I'd post some of my code by it's already a bit big to just slap on a forum post and may not make things much clearer. I've written a short summary that should explain the function of my code a little.
Code:
//entity class that animations are objects of
class entityManager {
void animate(); //function simply starts a timer and keeps looping the animation until a time limit is reached
};
//the function in the main game that checks if a shot hit or missed
//and plays the appropriate animation before swapping players
void checkShot() {
//code to check whether the shot hit or missed would go here
//the part that's giving me a problem:
explosion.animate(); //object of entity class
swapPlayers(); //gets called at the same time as "animate", but ideally needs to be delayed until it's finished.
}
If anyone can offer any advice on dealing with this problem, I'd be very grateful. The solution might be really stupidly obvious, but I've been trying to figure a way around it for a while and have got nowhere.
Thanks