Dan Furst
05-30-2007, 02:21 PM
Hi guys,
This script allows a freeform combo to follow the contours of a wall, or any other solid construct. The movement pattern is the same as the Sparks in Mario 2, if know what I mean. The ff combos are capable of following dynamic walkability patterns, and have a variety of speeds. You can have as many combos on the screen as ZQuest allows.
In this example quest, I made the combos damage type and they look like traps. (The cheat is "4" if you are impatient or can't get through.) I developed and tested this quest under 311.
wallflower.qst (http://filer.case.edu/dpf4/wallflower.qst)
Note you must pass in the ffc number, the pattern, the attachment, and the speed.
ffc script wallflower {
// PATTERN: The direction that the ffc will move initially.
// Up = 1
// Down = 2
// Left = 3
// Right = 4
// ATTACHED: Specify the side of the ffc which is attached to the wall initially.
// Top = 1
// Bottom = 2
// Left = 3
// Right = 4
// TL corner = 5
// TR corner = 6
// BL corner = 7
// BR corner = 8
// SPEED: The speed must be one of the following values:
// 16, 8, 4, 2, 1, 0.5, 0.25, 0.125, 0.0625
void run(int this_ffc_num, int pattern, int attached, float speed)
{
// "this_ffc->" bug workaround
ffc this_ffc = Screen->LoadFFC(this_ffc_num);
//if I'm stuck or floating
if(!is_walkable(this_ffc->X, this_ffc->Y))
{
//I'm on a solid combo
Quit();
}
if(is_walkable(this_ffc->X, this_ffc->Y - 16) && is_walkable(this_ffc->X, this_ffc->Y + 16) &&
is_walkable(this_ffc->X - 16, this_ffc->Y) && is_walkable(this_ffc->X + 16, this_ffc->Y) &&
is_walkable(this_ffc->X - 16, this_ffc->Y - 16) && is_walkable(this_ffc->X + 16, this_ffc->Y - 16) &&
is_walkable(this_ffc->X - 16, this_ffc->Y + 16) && is_walkable(this_ffc->X + 16, this_ffc->Y + 16))
{
//I'm not near any wall
Quit();
}
//the first move
int dir = 0;
dir = first_move(this_ffc->X, this_ffc->Y, pattern, attached);
while(true) // main loop
{
if(dir == 1)
{
//up
this_ffc->Vx = 0;
this_ffc->Vy = -speed;
}
else if(dir == 2)
{
//down
this_ffc->Vx = 0;
this_ffc->Vy = speed;
}
else if(dir == 3)
{
//left
this_ffc->Vx = -speed;
this_ffc->Vy = 0;
}
else if(dir == 4)
{
//right
this_ffc->Vx = speed;
this_ffc->Vy = 0;
}
else
{
Quit();
}
// only do whole combos
for(int i=0; i<(16/speed); i++)
{
Waitframe();
}
// see if the direction needs to be changed
if(dir == 1) // was moving up
{
if(attached == 3) // L
{
if(is_walkable(this_ffc->X - 16, this_ffc->Y)) // L
{
dir = 3; // L
attached = 7; //BL
}
else if(is_walkable(this_ffc->X, this_ffc->Y - 16)) // U
{
dir = 1; // U
attached = 3; // L
}
else if(is_walkable(this_ffc->X + 16, this_ffc->Y)) // R
{
dir = 4; // R
attached = 1; // T
}
else // D
{
dir = 2; // D
attached = 4; // R
}
}
else if(attached == 4) // R
{
if(is_walkable(this_ffc->X + 16, this_ffc->Y)) // R
{
dir = 4; // R
attached = 8; //BR
}
else if(is_walkable(this_ffc->X, this_ffc->Y - 16)) // U
{
dir = 1; // U
attached = 4; // R
}
else if(is_walkable(this_ffc->X - 16, this_ffc->Y)) // L
{
dir = 3; // L
attached = 1; // T
}
else // D
{
dir = 2; // D
attached = 3; // L
}
}
else if(attached == 5) // TL
{
if(is_walkable(this_ffc->X, this_ffc->Y - 16)) // U
{
dir = 1; // U
attached = 3; // L
}
else if(is_walkable(this_ffc->X + 16, this_ffc->Y)) // R
{
dir = 4; // R
attached = 1; // T
}
else // D
{
dir = 2; // D
attached = 4; // R
}
}
else if(attached == 6) // TR
{
if(is_walkable(this_ffc->X, this_ffc->Y - 16)) // U
{
dir = 1; // U
attached = 4; // R
}
else if(is_walkable(this_ffc->X - 16, this_ffc->Y)) // L
{
dir = 3; // L
attached = 1; // T
}
else // D
{
dir = 2; // D
attached = 3; // L
}
}
else
{
Quit();
}
}
if(dir == 2) // was moving down
{
if(attached == 3) // L
{
if(is_walkable(this_ffc->X - 16, this_ffc->Y)) // L
{
dir = 3; // L
attached = 5; //TL
}
else if(is_walkable(this_ffc->X, this_ffc->Y + 16)) // D
{
dir = 2; // D
attached = 3; // L
}
else if(is_walkable(this_ffc->X + 16, this_ffc->Y)) // R
{
dir = 4; // R
attached = 2; // B
}
else // U
{
dir = 1; // U
attached = 4; // R
}
}
else if(attached == 4) // R
{
if(is_walkable(this_ffc->X + 16, this_ffc->Y)) // R
{
dir = 4; // R
attached = 6; //TR
}
else if(is_walkable(this_ffc->X, this_ffc->Y + 16)) // D
{
dir = 2; // D
attached = 4; // R
}
else if(is_walkable(this_ffc->X - 16, this_ffc->Y)) // L
{
dir = 3; // L
attached = 2; // B
}
else // U
{
dir = 1; // U
attached = 3; // L
}
}
else if(attached == 7) // BL
{
if(is_walkable(this_ffc->X, this_ffc->Y + 16)) // D
{
dir = 2; // D
attached = 3; // L
}
else if(is_walkable(this_ffc->X + 16, this_ffc->Y)) // R
{
dir = 4; // R
attached = 2; // B
}
else // U
{
dir = 1; // U
attached = 4; // R
}
}
else if(attached == 8) // BR
{
if(is_walkable(this_ffc->X, this_ffc->Y + 16)) // D
{
dir = 2; // D
attached = 4; // R
}
else if(is_walkable(this_ffc->X - 16, this_ffc->Y)) // L
{
dir = 3; // L
attached = 2; // B
}
else // U
{
dir = 1; // U
attached = 3; // L
}
}
else
{
Quit();
}
}
if(dir == 3) // was moving left
{
if(attached == 1) // T
{
if(is_walkable(this_ffc->X, this_ffc->Y - 16)) // U
{
dir = 1; // U
attached = 6; // TR
}
else if(is_walkable(this_ffc->X - 16, this_ffc->Y)) // L
{
dir = 3; // L
attached = 1; // T
}
else if(is_walkable(this_ffc->X, this_ffc->Y + 16)) // D
{
dir = 2; // D
attached = 3; // L
}
else
{
dir = 4; // R
attached = 2; // B
}
}
else if(attached == 2) // B
{
if(is_walkable(this_ffc->X, this_ffc->Y + 16)) // D
{
dir = 2; // D
attached = 8; // BR
}
else if(is_walkable(this_ffc->X - 16, this_ffc->Y)) // L
{
dir = 3; // L
attached = 2; // B
}
else if(is_walkable(this_ffc->X, this_ffc->Y - 16)) // U
{
dir = 1; // U
attached = 3; // L
}
else
{
dir = 4; // R
attached = 1; // T
}
}
else if(attached == 5) // TL
{
if(is_walkable(this_ffc->X - 16, this_ffc->Y)) // L
{
dir = 3; // L
attached = 1; // T
}
else if(is_walkable(this_ffc->X, this_ffc->Y + 16)) // D
{
dir = 2; // D
attached = 3; // L
}
else // R
{
dir = 4; // R
attached = 2; // B
}
}
else if(attached == 7) // BL
{
if(is_walkable(this_ffc->X - 16, this_ffc->Y)) // L
{
dir = 3; // L
attached = 2; // B
}
else if(is_walkable(this_ffc->X, this_ffc->Y - 16)) // U
{
dir = 1; // U
attached = 3; // L
}
else // R
{
dir = 4; // R
attached = 1; // T
}
}
else
{
Quit();
}
}
if(dir == 4) // was moving right
{
if(attached == 1) // T
{
if(is_walkable(this_ffc->X, this_ffc->Y - 16)) // U
{
dir = 1; // U
attached = 5; // TL
}
else if(is_walkable(this_ffc->X + 16, this_ffc->Y)) // R
{
dir = 4; // R
attached = 1; // T
}
else if(is_walkable(this_ffc->X, this_ffc->Y + 16)) // D
{
dir = 2; // D
attached = 4; // R
}
else
{
dir = 3; // L
attached = 2; // B
}
}
else if(attached == 2) // B
{
if(is_walkable(this_ffc->X, this_ffc->Y + 16)) // D
{
dir = 2; // D
attached = 7; // BL
}
else if(is_walkable(this_ffc->X + 16, this_ffc->Y)) // R
{
dir = 4; // R
attached = 2; // B
}
else if(is_walkable(this_ffc->X, this_ffc->Y - 16)) // U
{
dir = 1; // U
attached = 4; // R
}
else
{
dir = 3; // L
attached = 1; // T
}
}
else if(attached == 6) // TR
{
if(is_walkable(this_ffc->X + 16, this_ffc->Y)) // R
{
dir = 4; // R
attached = 1; // T
}
else if(is_walkable(this_ffc->X, this_ffc->Y + 16)) // D
{
dir = 2; // D
attached = 4; // R
}
else // L
{
dir = 3; // L
attached = 2; // B
}
}
else if(attached == 8) // BR
{
if(is_walkable(this_ffc->X + 16, this_ffc->Y)) // R
{
dir = 4; // R
attached = 2; // B
}
else if(is_walkable(this_ffc->X, this_ffc->Y - 16)) // U
{
dir = 1; // U
attached = 4; // R
}
else // L
{
dir = 3; // L
attached = 1; // T
}
}
else
{
Quit();
}
}
}// end while true
}
int first_move(int x, int y, int pattern, int attached)
{
if(pattern == 1)
{
//if up is walkable && not attached by B, BL, BR
if(is_walkable(x, y - 16) && attached != 2 && attached != 7 && attached != 8)
{
return 1;
}
return 0;
}
else if(pattern == 2)
{
//if down is walkable && not attached by T, TL, TR
if(is_walkable(x, y + 16) && attached != 1 && attached != 5 && attached != 6)
{
return 2;
}
return 0;
}
else if(pattern == 3)
{
//if left is walkable && not attached by R, TR, BR
if(is_walkable(x - 16, y) && attached != 4 && attached != 6 && attached != 8)
{
return 3;
}
return 0;
}
else if(pattern == 4)
{
//if right is walkable && not attached by L, TL, BL
if(is_walkable(x + 16, y) && attached != 3 && attached != 5 && attached != 7)
{
return 4;
}
return 0;
}
else
{
//you entered an invalid pattern
Quit();
}
}
bool is_walkable(int x, int y)
{
if(x<0 || x>240 || y<0 || y>160)
{
return false;
}
return Screen->ComboS[y+(x>>4)]==0;
}
}//end
So how do you like my first script?
This script allows a freeform combo to follow the contours of a wall, or any other solid construct. The movement pattern is the same as the Sparks in Mario 2, if know what I mean. The ff combos are capable of following dynamic walkability patterns, and have a variety of speeds. You can have as many combos on the screen as ZQuest allows.
In this example quest, I made the combos damage type and they look like traps. (The cheat is "4" if you are impatient or can't get through.) I developed and tested this quest under 311.
wallflower.qst (http://filer.case.edu/dpf4/wallflower.qst)
Note you must pass in the ffc number, the pattern, the attachment, and the speed.
ffc script wallflower {
// PATTERN: The direction that the ffc will move initially.
// Up = 1
// Down = 2
// Left = 3
// Right = 4
// ATTACHED: Specify the side of the ffc which is attached to the wall initially.
// Top = 1
// Bottom = 2
// Left = 3
// Right = 4
// TL corner = 5
// TR corner = 6
// BL corner = 7
// BR corner = 8
// SPEED: The speed must be one of the following values:
// 16, 8, 4, 2, 1, 0.5, 0.25, 0.125, 0.0625
void run(int this_ffc_num, int pattern, int attached, float speed)
{
// "this_ffc->" bug workaround
ffc this_ffc = Screen->LoadFFC(this_ffc_num);
//if I'm stuck or floating
if(!is_walkable(this_ffc->X, this_ffc->Y))
{
//I'm on a solid combo
Quit();
}
if(is_walkable(this_ffc->X, this_ffc->Y - 16) && is_walkable(this_ffc->X, this_ffc->Y + 16) &&
is_walkable(this_ffc->X - 16, this_ffc->Y) && is_walkable(this_ffc->X + 16, this_ffc->Y) &&
is_walkable(this_ffc->X - 16, this_ffc->Y - 16) && is_walkable(this_ffc->X + 16, this_ffc->Y - 16) &&
is_walkable(this_ffc->X - 16, this_ffc->Y + 16) && is_walkable(this_ffc->X + 16, this_ffc->Y + 16))
{
//I'm not near any wall
Quit();
}
//the first move
int dir = 0;
dir = first_move(this_ffc->X, this_ffc->Y, pattern, attached);
while(true) // main loop
{
if(dir == 1)
{
//up
this_ffc->Vx = 0;
this_ffc->Vy = -speed;
}
else if(dir == 2)
{
//down
this_ffc->Vx = 0;
this_ffc->Vy = speed;
}
else if(dir == 3)
{
//left
this_ffc->Vx = -speed;
this_ffc->Vy = 0;
}
else if(dir == 4)
{
//right
this_ffc->Vx = speed;
this_ffc->Vy = 0;
}
else
{
Quit();
}
// only do whole combos
for(int i=0; i<(16/speed); i++)
{
Waitframe();
}
// see if the direction needs to be changed
if(dir == 1) // was moving up
{
if(attached == 3) // L
{
if(is_walkable(this_ffc->X - 16, this_ffc->Y)) // L
{
dir = 3; // L
attached = 7; //BL
}
else if(is_walkable(this_ffc->X, this_ffc->Y - 16)) // U
{
dir = 1; // U
attached = 3; // L
}
else if(is_walkable(this_ffc->X + 16, this_ffc->Y)) // R
{
dir = 4; // R
attached = 1; // T
}
else // D
{
dir = 2; // D
attached = 4; // R
}
}
else if(attached == 4) // R
{
if(is_walkable(this_ffc->X + 16, this_ffc->Y)) // R
{
dir = 4; // R
attached = 8; //BR
}
else if(is_walkable(this_ffc->X, this_ffc->Y - 16)) // U
{
dir = 1; // U
attached = 4; // R
}
else if(is_walkable(this_ffc->X - 16, this_ffc->Y)) // L
{
dir = 3; // L
attached = 1; // T
}
else // D
{
dir = 2; // D
attached = 3; // L
}
}
else if(attached == 5) // TL
{
if(is_walkable(this_ffc->X, this_ffc->Y - 16)) // U
{
dir = 1; // U
attached = 3; // L
}
else if(is_walkable(this_ffc->X + 16, this_ffc->Y)) // R
{
dir = 4; // R
attached = 1; // T
}
else // D
{
dir = 2; // D
attached = 4; // R
}
}
else if(attached == 6) // TR
{
if(is_walkable(this_ffc->X, this_ffc->Y - 16)) // U
{
dir = 1; // U
attached = 4; // R
}
else if(is_walkable(this_ffc->X - 16, this_ffc->Y)) // L
{
dir = 3; // L
attached = 1; // T
}
else // D
{
dir = 2; // D
attached = 3; // L
}
}
else
{
Quit();
}
}
if(dir == 2) // was moving down
{
if(attached == 3) // L
{
if(is_walkable(this_ffc->X - 16, this_ffc->Y)) // L
{
dir = 3; // L
attached = 5; //TL
}
else if(is_walkable(this_ffc->X, this_ffc->Y + 16)) // D
{
dir = 2; // D
attached = 3; // L
}
else if(is_walkable(this_ffc->X + 16, this_ffc->Y)) // R
{
dir = 4; // R
attached = 2; // B
}
else // U
{
dir = 1; // U
attached = 4; // R
}
}
else if(attached == 4) // R
{
if(is_walkable(this_ffc->X + 16, this_ffc->Y)) // R
{
dir = 4; // R
attached = 6; //TR
}
else if(is_walkable(this_ffc->X, this_ffc->Y + 16)) // D
{
dir = 2; // D
attached = 4; // R
}
else if(is_walkable(this_ffc->X - 16, this_ffc->Y)) // L
{
dir = 3; // L
attached = 2; // B
}
else // U
{
dir = 1; // U
attached = 3; // L
}
}
else if(attached == 7) // BL
{
if(is_walkable(this_ffc->X, this_ffc->Y + 16)) // D
{
dir = 2; // D
attached = 3; // L
}
else if(is_walkable(this_ffc->X + 16, this_ffc->Y)) // R
{
dir = 4; // R
attached = 2; // B
}
else // U
{
dir = 1; // U
attached = 4; // R
}
}
else if(attached == 8) // BR
{
if(is_walkable(this_ffc->X, this_ffc->Y + 16)) // D
{
dir = 2; // D
attached = 4; // R
}
else if(is_walkable(this_ffc->X - 16, this_ffc->Y)) // L
{
dir = 3; // L
attached = 2; // B
}
else // U
{
dir = 1; // U
attached = 3; // L
}
}
else
{
Quit();
}
}
if(dir == 3) // was moving left
{
if(attached == 1) // T
{
if(is_walkable(this_ffc->X, this_ffc->Y - 16)) // U
{
dir = 1; // U
attached = 6; // TR
}
else if(is_walkable(this_ffc->X - 16, this_ffc->Y)) // L
{
dir = 3; // L
attached = 1; // T
}
else if(is_walkable(this_ffc->X, this_ffc->Y + 16)) // D
{
dir = 2; // D
attached = 3; // L
}
else
{
dir = 4; // R
attached = 2; // B
}
}
else if(attached == 2) // B
{
if(is_walkable(this_ffc->X, this_ffc->Y + 16)) // D
{
dir = 2; // D
attached = 8; // BR
}
else if(is_walkable(this_ffc->X - 16, this_ffc->Y)) // L
{
dir = 3; // L
attached = 2; // B
}
else if(is_walkable(this_ffc->X, this_ffc->Y - 16)) // U
{
dir = 1; // U
attached = 3; // L
}
else
{
dir = 4; // R
attached = 1; // T
}
}
else if(attached == 5) // TL
{
if(is_walkable(this_ffc->X - 16, this_ffc->Y)) // L
{
dir = 3; // L
attached = 1; // T
}
else if(is_walkable(this_ffc->X, this_ffc->Y + 16)) // D
{
dir = 2; // D
attached = 3; // L
}
else // R
{
dir = 4; // R
attached = 2; // B
}
}
else if(attached == 7) // BL
{
if(is_walkable(this_ffc->X - 16, this_ffc->Y)) // L
{
dir = 3; // L
attached = 2; // B
}
else if(is_walkable(this_ffc->X, this_ffc->Y - 16)) // U
{
dir = 1; // U
attached = 3; // L
}
else // R
{
dir = 4; // R
attached = 1; // T
}
}
else
{
Quit();
}
}
if(dir == 4) // was moving right
{
if(attached == 1) // T
{
if(is_walkable(this_ffc->X, this_ffc->Y - 16)) // U
{
dir = 1; // U
attached = 5; // TL
}
else if(is_walkable(this_ffc->X + 16, this_ffc->Y)) // R
{
dir = 4; // R
attached = 1; // T
}
else if(is_walkable(this_ffc->X, this_ffc->Y + 16)) // D
{
dir = 2; // D
attached = 4; // R
}
else
{
dir = 3; // L
attached = 2; // B
}
}
else if(attached == 2) // B
{
if(is_walkable(this_ffc->X, this_ffc->Y + 16)) // D
{
dir = 2; // D
attached = 7; // BL
}
else if(is_walkable(this_ffc->X + 16, this_ffc->Y)) // R
{
dir = 4; // R
attached = 2; // B
}
else if(is_walkable(this_ffc->X, this_ffc->Y - 16)) // U
{
dir = 1; // U
attached = 4; // R
}
else
{
dir = 3; // L
attached = 1; // T
}
}
else if(attached == 6) // TR
{
if(is_walkable(this_ffc->X + 16, this_ffc->Y)) // R
{
dir = 4; // R
attached = 1; // T
}
else if(is_walkable(this_ffc->X, this_ffc->Y + 16)) // D
{
dir = 2; // D
attached = 4; // R
}
else // L
{
dir = 3; // L
attached = 2; // B
}
}
else if(attached == 8) // BR
{
if(is_walkable(this_ffc->X + 16, this_ffc->Y)) // R
{
dir = 4; // R
attached = 2; // B
}
else if(is_walkable(this_ffc->X, this_ffc->Y - 16)) // U
{
dir = 1; // U
attached = 4; // R
}
else // L
{
dir = 3; // L
attached = 1; // T
}
}
else
{
Quit();
}
}
}// end while true
}
int first_move(int x, int y, int pattern, int attached)
{
if(pattern == 1)
{
//if up is walkable && not attached by B, BL, BR
if(is_walkable(x, y - 16) && attached != 2 && attached != 7 && attached != 8)
{
return 1;
}
return 0;
}
else if(pattern == 2)
{
//if down is walkable && not attached by T, TL, TR
if(is_walkable(x, y + 16) && attached != 1 && attached != 5 && attached != 6)
{
return 2;
}
return 0;
}
else if(pattern == 3)
{
//if left is walkable && not attached by R, TR, BR
if(is_walkable(x - 16, y) && attached != 4 && attached != 6 && attached != 8)
{
return 3;
}
return 0;
}
else if(pattern == 4)
{
//if right is walkable && not attached by L, TL, BL
if(is_walkable(x + 16, y) && attached != 3 && attached != 5 && attached != 7)
{
return 4;
}
return 0;
}
else
{
//you entered an invalid pattern
Quit();
}
}
bool is_walkable(int x, int y)
{
if(x<0 || x>240 || y<0 || y>160)
{
return false;
}
return Screen->ComboS[y+(x>>4)]==0;
}
}//end
So how do you like my first script?