PDA

View Full Version : Diving Orbit Custom Boss Movement Pattern



C-Dawg
01-05-2007, 07:33 PM
Oh hay it's another untested, uncompiled script.



// ========================================
// orbit_diver - This FFC script makes the FFC behave as an
// orbit diver. At rest, the FFC will orbit the player at a certain
// distance. If the player attacks, the FFC distance of the
// orbit will double for a short period of time, then it will
// immediately counterattck. At regular
// intervals, the FFC will dive towards the player and then return
// to it's circular path.
//
// D0 - Speed of the orbit diver's normal behavior. Must be
// between 0 and about 6.28 for proper behavior.
// D1 - Speed of the orbit diver's attack
// D2 - Radius of the orbit diver's normal behavior
// D3 - Delay between orbit diver's diving attack. Make it longer
// than 30, because that's how long the attack will last.
// D4 - The time the orbit diver spends in a larger orbit after an attack
// =======================================

ffc script orbit_diver{

void run(int orbit_speed, int diving_speed, int radius, int delay, int dodge_time){

int state = 0; // 0 = At rest, not dodging
// 1 = Dodging away from player attack
// 2 = Diving towards player

int i = 0; // Used to keep track of the
int orbit_x; // orbit of the ffc.
int orbit_y;

int delay_counter = delay; // Countdown to attack

int dodge_counter = dodge_time; // Countdown to dodging

int dive_counter = 30; // Duration of attack

// We need to scale

while(true){

// First, calculate the idea orbit of this ffc and put it into orbit_x, orbit_y

orbit_x = Sin(i) + Link->X;
orbit_y = Cos(i) + Link->Y;

// Next, increase the value of i for the next loop.

i = i + orbit_speed;

// ============= State 0 Behavior ==============

if (state == 0){

// The FFC should get close to the ideal orbit (kept track of
// by orbit_x, orbit_y) if it is not already.

if ( ((this->X - orbit_x) > 8) || ((this->X - orbit_x) < -8) ||
((this->Y - orbit_y) > 8) || ((this->Y - orbit_y) < -8) ){

if (this->X >= orbit_x) { this->Vx = orbit_speed; }
else { this->Vx = -orbit_speed; }

if (this->Y >= orbit_y) { this->Vy = orbit_speed; }
else { this->Vy = -orbit_speed; }
}

// If the FFC is already close to the ideal orbit, just follow it around.

else{

this->X = orbit_x;
this->Y = orbit_y;
}

// Countdown to diving attack

if (delay_counter <= 0){

state = 2;
dive_counter = 30;
delay_counter = delay;
}
else{
delay_counter--;
}

// Detect whether the player is attacking or using an item
if ( (Link->InputB) || (Link->InputA)){

state = 1;
}

} // end of state 0

// ============= State 1 Behavior ==============
if ( state == 1 ){

// Shift the ideal orbit to farther away from player
orbit_x = orbit_x * 2;
orbit_y = orbit_y * 2;

// The FFC should get close to the ideal orbit (kept track of
// by orbit_x, orbit_y) if it is not already.

if ( ((this->X - orbit_x) > 8) || ((this->X - orbit_x) < -8) ||
((this->Y - orbit_y) > 8) || ((this->Y - orbit_y) < -8) ){

if (this->X >= orbit_x) { this->Vx = orbit_speed; }
else { this->Vx = -orbit_speed; }

if (this->Y >= orbit_y) { this->Vy = orbit_speed; }
else { this->Vy = -orbit_speed; }
}

// If the FFC is already close to the ideal orbit, just follow it around.
else{

this->X = orbit_x;
this->Y = orbit_y;
}

// Countdown to diving attack
if (delay_counter <= 0){

state = 2;
dive_counter = 30;
delay_counter = delay;
}
else{
delay_counter--;
}

// Countdown to counterattack
if (dodge_counter <= 0){
state = 2;
dive_counter = 30;
dodge_counter = dodge_time;
}
else{
dodge_counter--;
}
} // end of state 1

// ============= State 2 Behavior ==============
if (state == 2){

if (this->X <= Link->X){
this->Vx = this->Vx + (diving_speed/10);
if ( this->Vx > diving_speed ) { this->Vx = diving_speed; }
else{
this->Vx = this->Vx - (diving_speed/10);
if ( this->Vx < -diving_speed ) { this->Vx = -diving_speed; }
}

if (this->Y <= Link->Y){
this->Vy = this->Vy + (diving_speed/10);
if ( this->Vy > diving_speed ) { this->Vy = diving_speed; }
else{
this->Vy = this->Vy - (diving_speed/10);
if ( this->Vy < -diving_speed ) { this->Vy = -diving_speed; }
}

// Duration of attack
if (dive_counter <= 0){
state = 0;
}
else{
dive_counter--;
}

} end of state 2

Waitframe();
} // end of while loop
} // end of void run
}// end of ffc script

jman2050
01-05-2007, 08:09 PM
I'm getting a P00 error. After I put the comments on line 171 to get rid of that error, it gives me an unexpected $end, on token error at the very last line in the file :/

C-Dawg
01-05-2007, 08:13 PM
Yea, raw code'll do that. I post here to let people borrow from what I'm working on, and serve as a little online saved version of what I'm doing. When it comes to scripting, my philosophy is to script in the open. It's the only way other people are going to learn.

jman2050
01-05-2007, 09:35 PM
Just because I felt like it, here's my version, based off this raw code ;)


// ========================================
// orbit_diver - This FFC script makes the FFC behave as an
// orbit diver. At rest, the FFC will orbit the player at a certain
// distance. If the player attacks, the FFC distance of the
// orbit will double for a short period of time, then it will
// immediately counterattck. At regular
// intervals, the FFC will dive towards the player and then return
// to it's circular path.
//
// D0 - Speed of the orbit diver's normal behavior. Must be
// between 0 and about 6.28 for proper behavior.
// D1 - Speed of the orbit diver's attack
// D2 - Radius of the orbit diver's normal behavior
// D3 - Delay between orbit diver's diving attack. Make it longer
// than 30, because that's how long the attack will last.
// D4 - The time the orbit diver spends in a larger orbit after an attack
// =======================================

ffc script orbit_diver{

void run(int orbit_speed, int diving_speed, int radius, int delay, int dodge_time) {

int state = 0; // 0 = At rest, not dodging
// 1 = Dodging away from player attack
// 2 = Diving towards player

int i = 0; // Used to keep track of the
int orbit_x; // orbit of the ffc.
int orbit_y;
int orig_radius = radius;

int delay_counter = delay; // Countdown to attack

int dodge_counter = dodge_time; // Countdown to dodging

int dive_counter = 30; // Duration of attack

bool ontrack = true;

// We need to scale

while(true) {

// First, calculate the idea orbit of this ffc and put it into orbit_x, orbit_y

orbit_x = ((Sin(i)*radius) + Link->X+8)-(this->EffectWidth/2);
orbit_y = ((Cos(i)*radius) + Link->Y+8)-(this->EffectWidth/2);

// Next, increase the value of i for the next loop.

i = i + orbit_speed;

// ============= State 0 Behavior ==============

if (state == 0) {

// The FFC should get close to the ideal orbit (kept track of
// by orbit_x, orbit_y) if it is not already.

if(!ontrack)
{
if ( ((this->X - orbit_x) > diving_speed) || ((this->X - orbit_x) < -diving_speed) ||
((this->Y - orbit_y) > diving_speed) || ((this->Y - orbit_y) < -diving_speed) )
{

if (this->X >= orbit_x)
{
this->X -= diving_speed;
}
else
{
this->X += diving_speed;
}

if (this->Y >= orbit_y)
{
this->Y -= diving_speed;
}
else
{
this->Y += diving_speed;
}
}
else
{
ontrack=true;
}
}

// If the FFC is already close to the ideal orbit, just follow it around.

else{

this->X = orbit_x;
this->Y = orbit_y;
}

// Countdown to diving attack

if (delay_counter <= 0){

state = 2;
dive_counter = 30;
delay_counter = delay;
}
else{
delay_counter--;
}

// Detect whether the player is attacking or using an item
if ( (Link->InputB) || (Link->InputA)){

state = 1;
}

} // end of state 0

// ============= State 1 Behavior ==============
if ( state == 1 ) {

// Increase the radius incrementally until it reaches double the radius;
if(radius >= orig_radius*2) { radius = orig_radius*2; }
else { radius += 1; }

// The FFC should get close to the ideal orbit (kept track of
// by orbit_x2, orbit_y2) if it is not already.

if(!ontrack)
{
if ( ((this->X - orbit_x) > orbit_speed) || ((this->X - orbit_x) < -orbit_speed) ||
((this->Y - orbit_y) > orbit_speed) || ((this->Y - orbit_y) < -orbit_speed) ){

if (this->X >= orbit_x) { this->X -= diving_speed; }
else { this->X += diving_speed; }

if (this->Y >= orbit_y) { this->Y -= diving_speed; }
else { this->Y += diving_speed; }
}
else
{
ontrack=true;
}
}

// If the FFC is already close to the ideal orbit, just follow it around.
else{

this->X = orbit_x;
this->Y = orbit_y;
}

// Countdown to diving attack
if (delay_counter <= 0){

state = 2;
dive_counter = 30;
delay_counter = delay;
}
else{
delay_counter--;
}

// Countdown to counterattack
if (dodge_counter <= 0){
state = 2;
dive_counter = 30;
dodge_counter = dodge_time;
}
else{
dodge_counter--;
}
} // end of state 1

// ============= State 2 Behavior ==============
if (state == 2) {

if (this->X <= Link->X){
this->Vx = this->Vx + (diving_speed/10);
if ( this->Vx > diving_speed ) { this->Vx = diving_speed; }
}
else{
this->Vx = this->Vx - (diving_speed/10);
if ( this->Vx < -diving_speed ) { this->Vx = -diving_speed; }
}

if (this->Y <= Link->Y){
this->Vy = this->Vy + (diving_speed/10);
if ( this->Vy > diving_speed ) { this->Vy = diving_speed; }
}
else{
this->Vy = this->Vy - (diving_speed/10);
if ( this->Vy < -diving_speed ) { this->Vy = -diving_speed; }
}

// Duration of attack
if (dive_counter <= 0){
state = 0;
this->Vx = 0;
this->Vy = 0;
ontrack = false;
delay_counter = delay;
dodge_counter = dodge_time;
radius = orig_radius;
}
else{
dive_counter--;
}

} //end of state 2

Waitframe();
} // end of while loop
} // end of void run
} // end of ffc script