// use it for whatever - Swordsman (2/15/08)
#define ANIM_LEN 80
int last_walk_adj_hook_time = systemtime;
int player = 0; // set this to the player entity index, I can't figure it out right now
int last_dir_key = 0;
int frame_pos = 0;
int up_anim[80];
int down_anim[80];
void SetAnims()
{
/* The middle part (i-j<10) sets the frame wait for each frame
the numbers on the far right are the actual frames.
I prolly could've done this with a dict...
That way the global arrays wouldn't have to be a fixed and
calculated length (which is currently required to be the sum
of all the waits in the animation) */
int i, j;
// Up animation!
i=0; // I know verge initializes to 0, but it's nice to be safe
for(j=i; i-j<10; i++) up_anim[i] = 5;
for(j=i; i-j<10; i++) up_anim[i] = 6;
for(j=i; i-j<10; i++) up_anim[i] = 7;
for(j=i; i-j<10; i++) up_anim[i] = 6;
for(j=i; i-j<10; i++) up_anim[i] = 5;
for(j=i; i-j<10; i++) up_anim[i] = 8;
for(j=i; i-j<10; i++) up_anim[i] = 9;
for(j=i; i-j<10; i++) up_anim[i] = 8;
// Down animation!
i=0;
for(j=i; i-j<10; i++) down_anim[i] = 0+1;// haha, I just realized, you can't use frame 0
for(j=i; i-j<10; i++) down_anim[i] = 1; // at all here. well, don't use frame 0 in your
for(j=i; i-j<10; i++) down_anim[i] = 2; // up or down scripts. in fact, you should probably
for(j=i; i-j<10; i++) down_anim[i] = 1; // just reserve it for code like this.
for(j=i; i-j<10; i++) down_anim[i] = 0+1;
for(j=i; i-j<10; i++) down_anim[i] = 3;
for(j=i; i-j<10; i++) down_anim[i] = 4;
for(j=i; i-j<10; i++) down_anim[i] = 3;
}
void WalkAdjust()
{
int total_pressed = 0;
total_pressed += (key[SCAN_UP] != 0);
total_pressed += (key[SCAN_DOWN] != 0);
total_pressed += (key[SCAN_LEFT] != 0);
total_pressed += (key[SCAN_RIGHT] != 0);
// if two directional keys are pressed simultaneously...
if(total_pressed >= 2)
{
if(last_dir_key == SCAN_UP)
{
entity.specframe[player] = up_anim[frame_pos];
frame_pos++;
frame_pos = frame_pos % ANIM_LEN;
}
else if(last_dir_key == SCAN_DOWN)
{
entity.specframe[player] = down_anim[frame_pos];
frame_pos++;
frame_pos = frame_pos % ANIM_LEN;
}
else
{
entity.specframe[player] = 0;
frame_pos = 0;
}
// There's no reason to avoid left/right, if that was the last
// key pressed. The engine defaults to those.
}
// or, if just one directional key is pressed, store it
else
{
entity.specframe[player] = 0;
frame_pos = 0;
if(total_pressed != 0)
{
if(key[SCAN_UP]) last_dir_key = SCAN_UP;
else if(key[SCAN_DOWN]) last_dir_key = SCAN_DOWN;
else if(key[SCAN_LEFT]) last_dir_key = SCAN_LEFT;
else last_dir_key = SCAN_RIGHT; // must be the right key (or am I wrong? ;)
}
else // or, don't.
{
last_dir_key = 0;
}
}
}
void WalkAdjustHook()
{
int frameskip = 10;
if(last_walk_adj_hook_time < systemtime)
{
while(last_walk_adj_hook_time < systemtime and frameskip > 0)
{
WalkAdjust();
last_walk_adj_hook_time++;
frameskip--;
}
}
}
void SyncWalkAdjustHook()
{
last_walk_adj_hook_time = systemtime;
}
void AutoExec()
{
SetAnims();
HookRetrace("WalkAdjustHook");
//map("test.map");
}
// 10,000 hours in notepad