I am creating a tile based game, but the world is too big to have everything loaded at the same time. So I only load what is surrounding the player and update the view as he moves. Even though the world is tile-based this is not a turn-based game, the movement of the player and enemies is real-time.
For this reason any enemy outside the inmediate view will have tile-based "timed" pathfinding, because there will be no phisical world/objects/enemies loaded outside of the current view they will just be data moving around in an array until they are in the player's current view.
When an enemy is inside the view the timing between each move is easy... Move towards the next tile in the "pathfinding-list" and when he has reached it go to next, etc...
The problem is with enemies outside of the view. Since they are not phisically moving they are only data being shifted in an array. Obviously the time needed to move the data in an array to the next tile is virtually zero, so I want a "wait(-x);" instruction between each move of the enemies that are outside of the player's view.
The problem is knowing the value of "x" in the wait instruction... Each enemy type has a different speed and I want it to be accurate even when not "phisically loaded" in the current view.
EXAMPLE:
for an enemy loaded (inside the view) this is quite simple, lets say he is in tile 3,3 and the next "path-node" is 3,2. The move would look somethng like this if each tile is of size 32*32:
destination.y=32*2;
character_speed=world[3][3].npc.speed;
//MOVE ENEMY IN THE REAL WORLD
while(my.y>destination.y)
{
my.y-=character_speed*time_step;
wait(1);
}
my.y=destination.y;
//UPDATE ENEMY POSITION IN THE ARRAY
world[3][2].npc=world[3][3].npc;
world[3][3].npc=NULL;
that move function will take whatever time it needs to reach the tile and then the next movement will be executed for the next tile in the path.
What I would like some help on is to pre-calculate the time it would take to move one tile withought actually phisically moving an entity. the function for moving like this on a grid would look something like this:
character_speed=world[3][3].npc.speed;
//ONLY MOVE ENEMY IN THE ARRAY BUT AT THE CORRECT SPEED
walk_delay=???;
wait(-walk_delay);
world[3][2].npc=world[3][3].npc;
world[3][3].npc=NULL;
Of course the real walk function is more complex, turning the npc to look towards the correct direction, animating, recieving coordinates as variables, etc... But for simplicity this is just a dumbed-down example with only the essentials. What I am having trouble with is figuring out how to calculate the "???" in the second example (virtual movement in the array with a delay depending on speed, not real-world phisical movement).