You could make a variable to hold the current active character. You could actually make an array to store the information you would need in a struct, one struct for each character. Then when you move (keydown or mouse click) the active character would move, do it's action, whatever. When the turn ends, increment the variable for the current character.
WARNING: Rough example follows.
Here is a struct to store a character name, reference to an actor (sprite), some hit points and some magic points. You could do whatever you need. The important piece is probably the actor pointer.
This example also creates an array of two heros and sets some default values.
- Code: Select all
struct character {
char *name;
Actor* actor;
int hp;
int mp;
} heroes[2] = { {"hero one\0", 0, 10, 10}, {"hero two\0", 0, 5, 15} };
Then you could have a global value for which character is active and the total number of actors (for bookkeeping).
- Code: Select all
int activeCharacter = 0;
int numberCharacters = 2;
Then when you want to move one, you could do something like this.
- Code: Select all
heroes[activeCharacter].x += 5;
At the end of a character turn you would increment the activeCharacter, taking care to make sure you don't go past the end of the array.
- Code: Select all
activeCharacter = (++activeCharacter) % numberCharacters;
To attack one randomly (assuming all characters are in a place where they could be attacked), you would just generate a random number from 0 to numberCharacters.