C-Dawg
10-26-2006, 01:18 PM
Hey,
I've coded up this script, which should mimic the behavior of Helmstar's tail from LttP. But it doesn't work. At runtime, the tail end stays where it was placed, one of the segments moves a little bit, and then nothing else happens. I can't tell whether this is a continuing bug where there are multiple FFCs on the screen, or a runtime error. Maybe someone else can take a look at it.
I tried to avoid problems by putting all the code in ONE FFC. So FFC 7, the spikey end of the tail, has all the code; the rest of the FFCs run no script whatsoever.
import "std.zh"
int distancesq(int x1, int x2, int y1, int y2)
{
return (x1-x2)*(x1-x2)+(y1-y2)*(y1-y2);
}
// ===============================================
// TAIL_WHIP : This ffc will move slowly back and forth horizontally
// over four tiles, centered on it's original location. After a set amount
// of time, it will lash out towards link' s location at a high speed. It
// will pause breifly after reaching link's old location, and then return
// to it's starting point to continue wagging. Will use FFCs 1,2, 3, 4, and 5
// as tail segments, and FFC 6 as the base of the tail. Accordingly,
// the Tail_Whip FFC should be FFC 7.
// ===============================================
ffc script tail_whip{
// CONSTANTS
int wait = 60; // How long the tail waits
float pi = 3.14; // It's pi!
int delay = 10; // How much warning Link gets before
// the tail strikes
// VARIABLES
int i = 0; // Counter
int x_origin = 0;
int y_origin = 0;
int x_target = 0;
int y_target = 0;
int x; // working variables
int y;
int dist;
int state = 0; // The state of the tail_whip.
// 0 = wagging right
// 1 = wagging left
// 2 = pulling back to strike
// 3 = striking at link
// 4 = pausing after striking
// 5 = returning to wagging mode
// RUN FUNCTION
void run(){
// POINTERS
ffc segment_1 = Screen->LoadFFC(1);
ffc segment_2 = Screen->LoadFFC(2);
ffc segment_3 = Screen->LoadFFC(3);
ffc segment_4 = Screen->LoadFFC(4);
ffc segment_5 = Screen->LoadFFC(5);
ffc base = Screen->LoadFFC(6);
x_origin = this->X;
y_origin = this->Y;
while (true){
// Wagging right
if (state ==0){
if (this->X >= x_origin + 32){ state = 1; }
else{
this->Vx = Sin( ( 2 * pi) / 32) * (this->X - x_origin);
}
if (i >= wait) { i = 0; state = 2;}
else{ i = i + 1;}
}
// Wagging left
if (state ==1){
if (this->X >= x_origin - 32){ state = 0; }
else{
this->Vx = -Sin( ( 2 * pi) / 32) * (this->X - x_origin);
}
if (i >= wait) { i = 0; state = 2;}
else{ i = i + 1;}
}
// Targeting and pulling back to strike
if (state ==2){
x_target = Link->X;
y_target = Link->Y;
if ( i >= delay ){ i = 0; state = 3; }
else {
this -> Vx = 0;
this->Vy = -0.1;
}
}
if (state == 3){
if ( (this->X >= x_target - 16) && (this->X <= x_target + 16) &&
(this->Y >= y_target - 16) && (this->Y <= y_target + 16) ){
state = 4;
}
else{
dist = distancesq(x_target, this->X, y_target, this->Y);
x = this->X;
y = this->Y;
this->Vx = 2* ((x_target - x)*Abs((x_target - x))/dist);
this->Vy = 2 * ((y_target - y)*Abs((y_target - y))/dist);
}
}
if (state == 4){
if ( i >= delay/2 ) { i = 0; state = 5;}
else{ i = i++; }
}
if (state == 5){
if ( (this->X >= x_origin - 16) && (this->X <= x_origin + 16) && (this->Y >= y_origin - 16) && (this->Y <= y_origin + 16) ){
state = 0;
}
else{
dist = distancesq(x_origin, this->X, y_origin, this->Y);
x = this->X;
y = this->Y;
this->Vx = ((x_origin - x)*Abs((x_origin - x))/dist);
this->Vy = ((x_origin - y)*Abs((x_origin - y))/dist);
}
}
// After moving the tail end, next the tail segments are moved into position.
// First, put the third segment at the midpoint.
segment_3->X = ( (this->X - base->X) / 2);
segment_3->Y= ( (this->Y - base->Y) / 2);
// Next, place the other segments by finding the midpoint between 3 and the
// base, and between 3 and the tail whip, and placing two segments
// around it.
x = ( (segment_3->X - base->X) / 2);
y = ( (segment_3->Y - base->Y) / 2);
segment_1->X = ( ( x - base->X) / 2);
segment_1->Y = ( ( y - base->Y) / 2);
segment_2->X = ( ( x - segment_3->X) / 2);
segment_2->Y = ( ( y - segment_3->Y) / 2);
x = ( (segment_3->X - this->X) / 2);
y = ( (segment_3->Y - this->Y) / 2);
segment_4->X = ( ( x - segment_3->X) / 2);
segment_4->Y = ( ( y - segment_3->Y) / 2);
segment_5->X = ( ( x - this->X) / 2);
segment_5->Y = ( ( y - this->Y) / 2);
Waitframe();
} // end of while loop
} // end of void run()
} // end of ffc script
I've coded up this script, which should mimic the behavior of Helmstar's tail from LttP. But it doesn't work. At runtime, the tail end stays where it was placed, one of the segments moves a little bit, and then nothing else happens. I can't tell whether this is a continuing bug where there are multiple FFCs on the screen, or a runtime error. Maybe someone else can take a look at it.
I tried to avoid problems by putting all the code in ONE FFC. So FFC 7, the spikey end of the tail, has all the code; the rest of the FFCs run no script whatsoever.
import "std.zh"
int distancesq(int x1, int x2, int y1, int y2)
{
return (x1-x2)*(x1-x2)+(y1-y2)*(y1-y2);
}
// ===============================================
// TAIL_WHIP : This ffc will move slowly back and forth horizontally
// over four tiles, centered on it's original location. After a set amount
// of time, it will lash out towards link' s location at a high speed. It
// will pause breifly after reaching link's old location, and then return
// to it's starting point to continue wagging. Will use FFCs 1,2, 3, 4, and 5
// as tail segments, and FFC 6 as the base of the tail. Accordingly,
// the Tail_Whip FFC should be FFC 7.
// ===============================================
ffc script tail_whip{
// CONSTANTS
int wait = 60; // How long the tail waits
float pi = 3.14; // It's pi!
int delay = 10; // How much warning Link gets before
// the tail strikes
// VARIABLES
int i = 0; // Counter
int x_origin = 0;
int y_origin = 0;
int x_target = 0;
int y_target = 0;
int x; // working variables
int y;
int dist;
int state = 0; // The state of the tail_whip.
// 0 = wagging right
// 1 = wagging left
// 2 = pulling back to strike
// 3 = striking at link
// 4 = pausing after striking
// 5 = returning to wagging mode
// RUN FUNCTION
void run(){
// POINTERS
ffc segment_1 = Screen->LoadFFC(1);
ffc segment_2 = Screen->LoadFFC(2);
ffc segment_3 = Screen->LoadFFC(3);
ffc segment_4 = Screen->LoadFFC(4);
ffc segment_5 = Screen->LoadFFC(5);
ffc base = Screen->LoadFFC(6);
x_origin = this->X;
y_origin = this->Y;
while (true){
// Wagging right
if (state ==0){
if (this->X >= x_origin + 32){ state = 1; }
else{
this->Vx = Sin( ( 2 * pi) / 32) * (this->X - x_origin);
}
if (i >= wait) { i = 0; state = 2;}
else{ i = i + 1;}
}
// Wagging left
if (state ==1){
if (this->X >= x_origin - 32){ state = 0; }
else{
this->Vx = -Sin( ( 2 * pi) / 32) * (this->X - x_origin);
}
if (i >= wait) { i = 0; state = 2;}
else{ i = i + 1;}
}
// Targeting and pulling back to strike
if (state ==2){
x_target = Link->X;
y_target = Link->Y;
if ( i >= delay ){ i = 0; state = 3; }
else {
this -> Vx = 0;
this->Vy = -0.1;
}
}
if (state == 3){
if ( (this->X >= x_target - 16) && (this->X <= x_target + 16) &&
(this->Y >= y_target - 16) && (this->Y <= y_target + 16) ){
state = 4;
}
else{
dist = distancesq(x_target, this->X, y_target, this->Y);
x = this->X;
y = this->Y;
this->Vx = 2* ((x_target - x)*Abs((x_target - x))/dist);
this->Vy = 2 * ((y_target - y)*Abs((y_target - y))/dist);
}
}
if (state == 4){
if ( i >= delay/2 ) { i = 0; state = 5;}
else{ i = i++; }
}
if (state == 5){
if ( (this->X >= x_origin - 16) && (this->X <= x_origin + 16) && (this->Y >= y_origin - 16) && (this->Y <= y_origin + 16) ){
state = 0;
}
else{
dist = distancesq(x_origin, this->X, y_origin, this->Y);
x = this->X;
y = this->Y;
this->Vx = ((x_origin - x)*Abs((x_origin - x))/dist);
this->Vy = ((x_origin - y)*Abs((x_origin - y))/dist);
}
}
// After moving the tail end, next the tail segments are moved into position.
// First, put the third segment at the midpoint.
segment_3->X = ( (this->X - base->X) / 2);
segment_3->Y= ( (this->Y - base->Y) / 2);
// Next, place the other segments by finding the midpoint between 3 and the
// base, and between 3 and the tail whip, and placing two segments
// around it.
x = ( (segment_3->X - base->X) / 2);
y = ( (segment_3->Y - base->Y) / 2);
segment_1->X = ( ( x - base->X) / 2);
segment_1->Y = ( ( y - base->Y) / 2);
segment_2->X = ( ( x - segment_3->X) / 2);
segment_2->Y = ( ( y - segment_3->Y) / 2);
x = ( (segment_3->X - this->X) / 2);
y = ( (segment_3->Y - this->Y) / 2);
segment_4->X = ( ( x - segment_3->X) / 2);
segment_4->Y = ( ( y - segment_3->Y) / 2);
segment_5->X = ( ( x - this->X) / 2);
segment_5->Y = ( ( y - this->Y) / 2);
Waitframe();
} // end of while loop
} // end of void run()
} // end of ffc script