Hi, I have two quick questions.
The player can team up with NPCs against enemies, and their ally also follows them through rooms. When a player enters a room they're given a list of other characters who are there.
This works fine, however, as the player enters a new room first, (followed by their ally) the latter's name does not show up - the function for checking the room has been called before the ally has a chance to get there. In essence, how do I make sure their ally enters the room at the exact same time as the player, or if possible, just before? Room_AfterFadeIn gives a nasty jarring effect to the game so I don't think it's a solution.
Secondly, how can I implement a simple respawning system for items and characters? Dead characters are sent to room 0 and object visiblity is simply set to false when the player picks them up. Say, 1 minute for characters (2400 loops) and 30 seconds for items (1200 loops).
Thanks,
Atelier
Edit: Thanks for the help, both questions answered.
For the first problem, I suggest maintaing a variable (or a list if there can be more than one follower) for the follower, and in the "check" function add that variable/list...
For the second problem, when killing a character, just set a timer and when the timer is set return the character.
Well, that's my suggestion:
const int MAX_RESPAWNABLE_CHARACTERS = whatever;
const int CHARACTER_RESPAWN_TIME = whatever; // In ticks (1/40 sec)
struct RespawnableCharacter
{
int Delay;
int OriginalRoom;
int OriginalX;
int OriginalY;
Character * pChar;
}
RespawnableCharacter[MAX_RESPAWNABLE_CHARACTERS];
// This function must be called every tick:
function UpdateRespawnableCharacters()
{
int i;
while (i < MAX_RESPAWNABLE_CHARACTERS)
{
if (RespawnableCharacter[i].pChar.Room == 0)
{
if (RespawnableCharacter[i].Delay == 0)
{
RespawnableCharacter[i].pChar.ChangeRoom(
RespawnableCharacter[i].OriginalRoom,
RespawnableCharacter[i].OriginalX,
RespawnableCharacter[i].OriginalY);
}
RespawnableCharacter[i].Delay--;
}
i++;
}
}
Ofcourse, you must setup all the respawnable characters at game start...... Good thing if their indexes go in sequence(s), so you can use loops to do this. In general case --
RespawnableCharacter[0].pChar = cMyEnemy1;
RespawnableCharacter[0].OriginalRoom = cMyEnemy1.Room;
RespawnableCharacter[0].OriginalX = cMyEnemy1.x;
RespawnableCharacter[0].OriginalY = cMyEnemy1.y;
etc etc etc
If enemies are assigned to, let's say, indexes 5 to 30, it will be like
int i = 5;
while (i < 31)
{
RespawnableCharacter[0].pChar = character[i];
RespawnableCharacter[0].OriginalRoom = character[i].Room;
RespawnableCharacter[0].OriginalX = character[i].x;
RespawnableCharacter[0].OriginalY = character[i].y;
i++;
}
When character is killed, you simply do
RespawnableCharacter[X].Delay = CHARACTER_RESPAWN_TIME;
RespawnableCharacter[X].pChar.ChangeRoom(0);
have fun