C-Dawg
01-03-2007, 10:07 AM
I'll check this out when I get home, but just coded up a gun script.
// ===================================
// gun - This FFC will act as a gun. The user
// specifies which direction the gun will fire. When
// the player is lined up with the proper direction,
// the gun will briefly switch to the next combo.
// It will move the projectile FFC to its location, and
// send it outwards in the proper direction. Projectiles will
// be blocked by solid combos on layer 0.
// D0 = delay between shots.
// D1 = FFC number of the projectile combo
// D2 = speed of the projectile
// D3 = 1 if the gun can shoot north
// D4 = 1 if the gun can shoot south
// D5 = 1 if the gun can shoot east
// D6 = 1 if the gun can shoot west
// D7 = 1 if the gun is omnidirectional (meaning it will
// fire at angles, regardless of where the player is.)
// NOTE - If you make the projectile move too fast, it may zip off
// of the screen before the script can save it. Keep the speed under
// 16 to prevent this.
// ==========================================
ffc script gun{
void run(int shot_delay, int projectile_ffc_number, int projectile_speed, int shoots_north,
int shoots_south, int shoots_east, int shoots_west, int omnidirectional){
int gun_state = 0; // 0 = primed and waiting for the player to come in range.
// 1 = firing
// 2 = waiting
int firing_delay = 20; // Hard-coded delay while gun animation plays. Counter for state 1.
int delay_counter = shot_delay; // Counter for state 2.
int side_A; int side_B; int side_C; // Used to calculate the angle in an omnidirectional gun.
projectile = ffc Screen->LoadFFC(projectile_ffc_number);
while (true){
if (gun_state == 0){
if ( (shoots_north == 1) && (Link->X < this->X+16) && (Link->X > this->X-1) && (Link->Y < this->Y)){
projectile->X = this->X;
projectile->Y = this->Y;
projectile->Vy = -projectile_speed;
projectile->Vx = 0;
gun_state = 1;
this->Data++;
}
if ( (shoots_south == 1) && (Link->X < this->X+16) && (Link->X > this->X-1) && (Link->Y > this->Y)){
projectile->X = this->X;
projectile->Y = this->Y;
projectile->Vy = projectile_speed;
projectile->Vx = 0;
gun_state = 1;
this->Data++;
}
if ( (shoots_east == 1) && (Link->Y < this->Y+16) && (Link->Y > this->Y-1) && (Link->X > this->X)){
projectile->X = this->X;
projectile->Y = this->Y;
projectile->Vx = projectile_speed;
projectile->Vy = 0;
gun_state = 1;
this->Data++;
}
if ( (shoots_west == 1) && (Link->Y < this->Y+16) && (Link->Y > this->Y-1) && (Link->X < this->X)){
projectile->X = this->X;
projectile->Y = this->Y;
projectile->Vx = -projectile_speed;
projectile->Vy = 0;
gun_state = 1;
this->Data++;
}
if(omnidirectional == 1){
// First, check to see if the player is linked up vertically with the gun. Need to do this
// because, otherwise, the angle checking code will divide by zero OH SHI
if(Link->X = this->X){
if ( Link->Y > this->Y){
projectile->X = this->X;
projectile->Y = this->Y;
projectile->Vy = projectile_speed;
projectile->Vx = 0;
gun_state = 1;
this->Data++;
}
if ( Link->Y < this->Y){
projectile->X = this->X;
projectile->Y = this->Y;
projectile->Vy = -projectile_speed;
projectile->Vx = 0;
gun_state = 1;
this->Data++;
}
// If not, calculate the angle to move the shooter.
else{
side_A = this->Y - Link->y; // length of side of right triangle parallel to X axis
side_B = this->X; // length of side of right triangle perpendicular to X axis
side_C = Sqrt( (side_A*sideA) + (sideB*sideB) ); // length of hypotenuse
projectile->X = this->X;
projectile->Y = this->Y;
projectile->Vy = speed * (side_A / side_C); // Sin of the angle is opp/hyp
projectile->Vx = speed * (side_B / side_C); // Cos of the angle is adj/hyp
gun_state = 1;
this->Data++;
}
}
} // end of state 0
if ( gun_state == 1){
if(firing_delay >= 0){
firing_delay--;
}
else{
firing_delay = 20;
this->Data--;
gun_state = 2;
}
} // end of state 1
if ( gun_state == 2){
if(delay_counter >= 0){
delay_counter--;
}
else{
delay_counter = shot_delay;
gun_state = 0;
}
} // end of state 2
if ( projectile is off the screen) {
projectile->Vx = 0;
projectile->Vy = 0;
projectile->X = 0;
projectile->Y = -16;
}
Waitframe();
} // end of while loop
} // end of void run
} // end of ffc script
// ===================================
// gun - This FFC will act as a gun. The user
// specifies which direction the gun will fire. When
// the player is lined up with the proper direction,
// the gun will briefly switch to the next combo.
// It will move the projectile FFC to its location, and
// send it outwards in the proper direction. Projectiles will
// be blocked by solid combos on layer 0.
// D0 = delay between shots.
// D1 = FFC number of the projectile combo
// D2 = speed of the projectile
// D3 = 1 if the gun can shoot north
// D4 = 1 if the gun can shoot south
// D5 = 1 if the gun can shoot east
// D6 = 1 if the gun can shoot west
// D7 = 1 if the gun is omnidirectional (meaning it will
// fire at angles, regardless of where the player is.)
// NOTE - If you make the projectile move too fast, it may zip off
// of the screen before the script can save it. Keep the speed under
// 16 to prevent this.
// ==========================================
ffc script gun{
void run(int shot_delay, int projectile_ffc_number, int projectile_speed, int shoots_north,
int shoots_south, int shoots_east, int shoots_west, int omnidirectional){
int gun_state = 0; // 0 = primed and waiting for the player to come in range.
// 1 = firing
// 2 = waiting
int firing_delay = 20; // Hard-coded delay while gun animation plays. Counter for state 1.
int delay_counter = shot_delay; // Counter for state 2.
int side_A; int side_B; int side_C; // Used to calculate the angle in an omnidirectional gun.
projectile = ffc Screen->LoadFFC(projectile_ffc_number);
while (true){
if (gun_state == 0){
if ( (shoots_north == 1) && (Link->X < this->X+16) && (Link->X > this->X-1) && (Link->Y < this->Y)){
projectile->X = this->X;
projectile->Y = this->Y;
projectile->Vy = -projectile_speed;
projectile->Vx = 0;
gun_state = 1;
this->Data++;
}
if ( (shoots_south == 1) && (Link->X < this->X+16) && (Link->X > this->X-1) && (Link->Y > this->Y)){
projectile->X = this->X;
projectile->Y = this->Y;
projectile->Vy = projectile_speed;
projectile->Vx = 0;
gun_state = 1;
this->Data++;
}
if ( (shoots_east == 1) && (Link->Y < this->Y+16) && (Link->Y > this->Y-1) && (Link->X > this->X)){
projectile->X = this->X;
projectile->Y = this->Y;
projectile->Vx = projectile_speed;
projectile->Vy = 0;
gun_state = 1;
this->Data++;
}
if ( (shoots_west == 1) && (Link->Y < this->Y+16) && (Link->Y > this->Y-1) && (Link->X < this->X)){
projectile->X = this->X;
projectile->Y = this->Y;
projectile->Vx = -projectile_speed;
projectile->Vy = 0;
gun_state = 1;
this->Data++;
}
if(omnidirectional == 1){
// First, check to see if the player is linked up vertically with the gun. Need to do this
// because, otherwise, the angle checking code will divide by zero OH SHI
if(Link->X = this->X){
if ( Link->Y > this->Y){
projectile->X = this->X;
projectile->Y = this->Y;
projectile->Vy = projectile_speed;
projectile->Vx = 0;
gun_state = 1;
this->Data++;
}
if ( Link->Y < this->Y){
projectile->X = this->X;
projectile->Y = this->Y;
projectile->Vy = -projectile_speed;
projectile->Vx = 0;
gun_state = 1;
this->Data++;
}
// If not, calculate the angle to move the shooter.
else{
side_A = this->Y - Link->y; // length of side of right triangle parallel to X axis
side_B = this->X; // length of side of right triangle perpendicular to X axis
side_C = Sqrt( (side_A*sideA) + (sideB*sideB) ); // length of hypotenuse
projectile->X = this->X;
projectile->Y = this->Y;
projectile->Vy = speed * (side_A / side_C); // Sin of the angle is opp/hyp
projectile->Vx = speed * (side_B / side_C); // Cos of the angle is adj/hyp
gun_state = 1;
this->Data++;
}
}
} // end of state 0
if ( gun_state == 1){
if(firing_delay >= 0){
firing_delay--;
}
else{
firing_delay = 20;
this->Data--;
gun_state = 2;
}
} // end of state 1
if ( gun_state == 2){
if(delay_counter >= 0){
delay_counter--;
}
else{
delay_counter = shot_delay;
gun_state = 0;
}
} // end of state 2
if ( projectile is off the screen) {
projectile->Vx = 0;
projectile->Vy = 0;
projectile->X = 0;
projectile->Y = -16;
}
Waitframe();
} // end of while loop
} // end of void run
} // end of ffc script