const int SFX_HIT=19;
const int CMR_OFFSET = 32; // 64/2.
const int CMR_NUM_POINTS = 32; // 64/2.
int sp[64]; // - this must be global:
// x values are 0-31,
// y values are 32-63.
// you can set these differently if you like.
float CatMullRom( int current_point, float t )
{
int p = current_point;
float ret = 0.5 * ( (2 * sp[p+1]) + (sp[p+2] - sp[p]) * t +
(2 * sp[p] - 5 * sp[p+1] + 4 * sp[p+2] - sp[p+3]) * t * t +
(3 * sp[p+1] + sp[p+3] - sp[p] - 3 * sp[p+2]) * t * t * t );
return ret;
}
float CatMullRom( int current_point, float t, int num_points, bool use_offset )
{
int p = current_point;
int n1 = ( p + 1 ) % num_points;
int n2 = ( p + 2 ) % num_points;
int n3 = ( p + 3 ) % num_points;
if( use_offset )
{
n1 += CMR_OFFSET;
n2 += CMR_OFFSET;
n3 += CMR_OFFSET;
}
float ret = 0.5 * ( (2 * sp[n1]) + (sp[n2] - sp[p]) * t +
(2 * sp[p] - 5 * sp[n1] + 4 * sp[n2] - sp[n3]) * t * t +
(3 * sp[n1] + sp[n3] - sp[p] - 3 * sp[n2]) * t * t * t );
return ret;
}
void FFC_CMR( ffc f, int current_point, float t )
{
f->X = CatMullRom( current_point, t );
f->Y = CatMullRom( current_point+ CMR_OFFSET, t );
}
void FFC_CMR( ffc f, int current_point, float t, int num_points )
{
f->X = CatMullRom( current_point, t, num_points, false );
f->Y = CatMullRom( current_point+ CMR_OFFSET, t, num_points, true );
}
ffc FFC_CMR( int ffc_num, int current_point, float t )
{
ffc f = Screen->LoadFFC( ffc_num );
f->X = CatMullRom( current_point, t );
f->Y = CatMullRom( current_point+ CMR_OFFSET , t );
return f;
}
ffc FFC_CMR( int ffc_num, int current_point, float t, int num_points )
{
ffc f = Screen->LoadFFC( ffc_num );
f->X = CatMullRom( current_point, t, num_points, false );
f->Y = CatMullRom( current_point+ CMR_OFFSET, t, num_points, true );
return f;
}
const int SOUNDKILL=10; //SET THE SOUND YOU WANT TO PLAY WHEN THE ENEMY IS KILLED
ffc script splineenemy
{
void run()
{
float t;
int segment;
// randomly generate the vectors
for(int i = 0; i < 32; i++ ) sp[i] = Rand( 16)+Rand( 224 ); // x
for(int i = 32; i < 64; i++ ) sp[i] = Rand( 16)+Rand( 144 ); // y
//Movement Generation using Catmull
int conx;
int cony;
int hittime=400;
while(true )
{
Waitframe();
// now compute the location based off current segment
// ( -a segment is a collection of current tangents- )
//FFC_CMR( this, segment, t, CMR_NUM_POINTS );
this->X = CatMullRom( segment, t );
this->Y = CatMullRom( segment+32, t );
t += 0.0167;
if( t >= 1 )
{
t -= 1;
segment++;
segment %= 32;
}
//Enemy Behaviour
int xL=Link->X;
int yL=Link->Y;
int xT=this->X;
int yT=this->Y;
if(Distance(xL,yL,xT,yT)<10){
Link->HP-=15;
Game->PlaySound(SFX_HIT);
//MOVE LINK AFTER BEING HIT WHILE MAKING SURE NOT TO END UP IN A SOLID COMBO
if((Link->Dir == DIR_UP||Link->Dir == DIR_DOWN) && yL<=yT){
for(int i=0;i<30;i++){
if(Screen->isSolid(Link->X,Link->Y)){
}else{
Link->Y-=1;
}
}
}
if((Link->Dir == DIR_UP||Link->Dir == DIR_DOWN) && yL>=yT){
for(int i=0;i<30;i++){
if(Screen->isSolid(Link->X,Link->Y)){
}else{
Link->Y+=1;
}
}
}
if((Link->Dir == DIR_LEFT||Link->Dir == DIR_RIGHT) && xL<=xT){
for(int i=0;i<30;i++){
if(Screen->isSolid(Link->X,Link->Y)){
}else{
Link->X-=1;
}
}
}
//If Link is left of the enemy
if((Link->Dir == DIR_LEFT||Link->Dir == DIR_RIGHT) && xL>=xT){
for(int i=0;i<30;i++){
if(Screen->isSolid(Link->X,Link->Y)){
}else{
Link->X+=1;
}
}
}
}
for(int i=Screen->NumLWeapons();i>0;i--){
lweapon wpn = Screen->LoadLWeapon(i);
if(Collision(this, wpn)&&wpn->ID==LW_HOOKSHOT) {
Game->PlaySound(SOUNDKILL);
Waitframes(20);
this->Data+=1;
Quit();
}
}
}
}
}
|