Code:
import "std.zh"
//=========================================================================================
//-----------------------------------------------------------------------------------------
// ~GLOBAL~
//-----------------------------------------------------------------------------------------
//=========================================================================================
bool white = true;
bool black = false;
bool is_white = true;
bool is_black = false;
int blue_charge = 0;
int red_charge = 0;
const int BLUE = 5;
const int RED = 21;
const int BLUE_ENEMY = 254;
const int RED_ENEMY = 255;
global script Ikaruga{
void run(){
ffc ffc1 = Screen->LoadFFC(1);
ffc ffc2 = Screen->LoadFFC(2);
ffc ffc3 = Screen->LoadFFC(3);
ffc ffc4 = Screen->LoadFFC(4);
ffc ffc5 = Screen->LoadFFC(5);
ffc ffc6 = Screen->LoadFFC(6);
int speed = 3.25;
int s = 2;
int w_trig = 1;
int b_trig = 1;
int attack_delay = 0;
npc enemy;
int e_num;
while(true){
int lx = Link->X;
int ly = Link->Y;
Waitframe();
if(attack_delay > 0) attack_delay--;
if(is_white){
if(w_trig != 0){
Link->Item[17]==false;
w_trig = 0;
b_trig = 1;
}
}
if(is_black){
if(b_trig != 0){
Link->Item[17]==true;
w_trig = 1;
b_trig = 0;
}
}
//========================
// ~CHARGE HANDLING~
//========================
if(white){
Link->MP=blue_charge;
if(blue_charge>1&&Link->InputR){
e_num = Screen->NumNPCs();
for(int i = e_num; i>0; i--)
{
enemy = Screen->LoadNPC(i);
int ex = enemy->X;
int ey = enemy->Y;
if(enemy->CSet==0 && enemy->Tile != 0){
Screen->Line(5,lx+8,ly,ex+8,ey+8,BLUE,1,0,0,0,128);
enemy->HP--;blue_charge-=2;
}
}
}
}
if(black){
Link->MP=red_charge;
if(red_charge>1&&Link->InputR){
e_num = Screen->NumNPCs();
for(int i = e_num; i>0; i--)
{
enemy = Screen->LoadNPC(i);
int ex = enemy->X;
int ey = enemy->Y;
if(enemy->CSet==1 && enemy->Tile != 0){
Screen->Line(5,lx+8,ly,ex+8,ey+8,RED,1,0,0,0,128);
enemy->HP--;red_charge-=2;
}
}
}
}
//========================
// ~A BUTTON HANDLING~
//========================
if(Link->InputA && attack_delay ==0){
attack_delay = 7;
if(ffc1->Data != 8){
if(white) ffc1->CSet = 0;
if(black) ffc1->CSet = 1;
ffc1->X = Link->X;
ffc1->Y = Link->Y - 16;
ffc1->Vy = -speed;
ffc1->Vx = 0;
ffc1->Data = 8;
Game->PlaySound(s);
}
else if(ffc2->Data != 8){
if(white) ffc2->CSet = 0;
if(black) ffc2->CSet = 1;
ffc2->X = Link->X;
ffc2->Y = Link->Y - 16;
ffc2->Vy = -speed;
ffc2->Vx = 0;
ffc2->Data = 8;
Game->PlaySound(s);
}
else if(ffc3->Data != 8){
if(white) ffc3->CSet = 0;
if(black) ffc3->CSet = 1;
ffc3->X = Link->X;
ffc3->Y = Link->Y - 16;
ffc3->Vy = -speed;
ffc3->Vx = 0;
ffc3->Data = 8;
Game->PlaySound(s);
}
else if(ffc4->Data != 8){
if(white) ffc4->CSet = 0;
if(black) ffc4->CSet = 1;
ffc4->X = Link->X;
ffc4->Y = Link->Y - 16;
ffc4->Vy = -speed;
ffc4->Vx = 0;
ffc4->Data = 8;
Game->PlaySound(s);
}
else if(ffc5->Data != 8){
if(white) ffc5->CSet = 0;
if(black) ffc5->CSet = 1;
ffc5->X = Link->X;
ffc5->Y = Link->Y - 16;
ffc5->Vy = -speed;
ffc5->Vx = 0;
ffc5->Data = 8;
Game->PlaySound(s);
}
else if(ffc6->Data != 8){
if(white) ffc6->CSet = 0;
if(black) ffc6->CSet = 1;
ffc6->X = Link->X;
ffc6->Y = Link->Y - 16;
ffc6->Vy = -speed;
ffc6->Vx = 0;
ffc6->Data = 8;
Game->PlaySound(s);
}
Link->InputA = false;
}
}
}
// ===================================
// Collision detection function
// ===================================
bool canMove(int x, int y){
// x=23, y=130
// Obviously in range...
if(x<0 || x>255 || y<0 || y>175)
return false;
int mask=1111b;
// x % 16 = 7, so
// mask = 1111 & 0011 = 0011
if(x%16<8)
mask&=0011b;
else
mask&=1100b;
// y % 16 = 2, so
// mask = 0011 & 0101 = 0001
if(y%16<8)
mask&=0101b;
else
mask&=1010b;
// All but the top-right quarter of the combo is solid, so ComboS = 1011
// mask & ComboS = 0001 & 1011 = 0001
// The result wasn't 0, so return false
return ((Screen->ComboS[ComboAt(x, y)]&mask)==0);
}
}
//=========================================================================================
//-----------------------------------------------------------------------------------------
// ~ITEM~
//-----------------------------------------------------------------------------------------
//=========================================================================================
item script shield{
void run(){
if(white){
is_black=true;
is_white=false;
white = false;
black = true;
Game->PlaySound(36);
}
else{
is_white=true;
is_black=false;
white = true;
black = false;
Game->PlaySound(36);
}
}
}
//=========================================================================================
//-----------------------------------------------------------------------------------------
// ~FFC~
//-----------------------------------------------------------------------------------------
//=========================================================================================
ffc script multi_dot{
void run(){
while(true){
Waitframe();
if(this->Y > 160||this->Y < 8||this->X > 240||this->X < 8){
this->X = 0; this->Y = 0; this->Vx = 0; this->Vy = 0;
this->Data = 1;
}
if(!(canMove(this->X+8,this->Y+8))){
this->X = 0; this->Y = 0; this->Vx = 0; this->Vy = 0;
this->Data = 1;
}
//======================================
// ~PLAYER DAMAGE HANDLING~
//======================================
int lx = Link->X;
int ly = Link->Y;
int tx = this->X;
int ty = this->Y;
if(this->Data>1){
if(this->CSet == 0 && white){
if(Abs(tx-lx)<14&&Abs(ty-ly)<14){
this->Data=1;
Game->PlaySound(4);
blue_charge++;
}
}
else if(this->CSet == 1 && black){
if(Abs(tx-lx)<14&&Abs(ty-ly)<14){
this->Data=1;
Game->PlaySound(4);
red_charge++;
}
}
else if(this->CSet == 0 && black){
if(Abs(tx-lx)<9&&Abs(ty-ly)<11){
this->Data=1;
Link->HP-=16;
Game->PlaySound(3);
}
}
else if(this->CSet == 1 && white){
if(Abs(tx-lx)<9&&Abs(ty-ly)<11){
this->Data=1;
Link->HP-=16;
Game->PlaySound(3);
}
}
}
}
}
// ===================================
// Collision detection function
// ===================================
bool canMove(int x, int y){
// x=23, y=130
// Obviously in range...
if(x<0 || x>255 || y<0 || y>175)
return false;
int mask=1111b;
// x % 16 = 7, so
// mask = 1111 & 0011 = 0011
if(x%16<8)
mask&=0011b;
else
mask&=1100b;
// y % 16 = 2, so
// mask = 0011 & 0101 = 0001
if(y%16<8)
mask&=0101b;
else
mask&=1010b;
// All but the top-right quarter of the combo is solid, so ComboS = 1011
// mask & ComboS = 0001 & 1011 = 0001
// The result wasn't 0, so return false
return ((Screen->ComboS[ComboAt(x, y)]&mask)==0);
}
}
ffc script main_gun_1{
void run(){
npc enemy;
int e_num;
while(true){
int lx = Link->X;
int ly = Link->Y;
int tx = this->X;
int ty = this->Y;
if(this->Y > 168||this->Y < 0||this->X > 248||this->X < 0){
this->X = 0; this->Y = 0; this->Vx = 0; this->Vy = 0;
this->Data = 1;
}
if(this->Data==8 && this->CSet==0){
e_num = Screen->NumNPCs();
for(int i = e_num; i>0; i--)
{
enemy = Screen->LoadNPC(i);
int ex = enemy->X;
int ey = enemy->Y;
if(enemy->CSet==0){
if(Abs(tx-ex)<13&&Abs(ty-ey)<13&&enemy->Tile != 0)
{
this->Data = 1;
enemy->HP -= 2;
Game->PlaySound(11);
}
}
else{
if(Abs(tx-ex)<13&&Abs(ty-ey)<13&&enemy->Tile != 0)
{
this->Data = 1;
enemy->HP -= 1;
Game->PlaySound(11);
}
}
}
}
else if(this->Data==8 && this->CSet==1){
e_num = Screen->NumNPCs();
for(int i = e_num; i>0; i--)
{
enemy = Screen->LoadNPC(i);
int ex = enemy->X;
int ey = enemy->Y;
if(enemy->CSet==0){
if(Abs(tx-ex)<13&&Abs(ty-ey)<13&&enemy->Tile != 0)
{
this->Data = 1;
enemy->HP -= 2;
Game->PlaySound(11);
}
}
else{
if(Abs(tx-ex)<13&&Abs(ty-ey)<13&&enemy->Tile != 0)
{
this->Data = 1;
enemy->HP -= 1;
Game->PlaySound(11);
}
}
}
}
Waitframe();
}
}
}
ffc script instill_blue_shooter{
void run(int enemyHP, int shoot_amount, int shoot_delay, int speed){
bool find_weapon = false;
if(enemyHP==0)enemyHP=20;
if(shoot_amount==0)shoot_amount=3;
if(shoot_delay==0)shoot_delay=15;
if(speed==0)speed=2;
npc life;
Waitframe();
life = Screen->CreateNPC(254);Waitframe();
life->HP = enemyHP;
life->X=(Rand(13)+1*16);
life->Y=16;
int ffc_num = 17;
ffc F = Screen->LoadFFC(ffc_num);
int delay = 0;
int burst = 1;
int sa = shoot_amount;
int fd = shoot_delay;
int w = 40; //waitframes
int d = 12; //data
int afterlife;
while(this->Data>0){
Waitframe();
int tx = this->X; int ty = this->Y;
int lx = Link->X; int ly = Link->Y;
while(life->isValid()){
Waitframe();
int tx = this->X; int ty = this->Y;
int lx = Link->X; int ly = Link->Y;
this->X=life->X;this->Y=life->Y;
delay++;
if(delay == fd*burst){
// Find an unused ffc
for(int i=ffc_num;i<32;i++){
if(find_weapon==false){
F=Screen->LoadFFC(i);
if(F->Data==1)find_weapon=true;
}
else i++;
}
burst++;
if(burst==sa)burst=sa*2;
if(burst==sa+sa+1){delay=0;burst=1;}
if(find_weapon){
F->X=tx;F->Y=ty;
F->Data=d;F->CSet=0;
int fspeed = speed;
int dx = lx - tx;
int dy = ly - ty;
float norm = Sqrt(dx*dx+dy*dy);
if(norm > 0)
{
F->Vx = dx/norm*fspeed;
F->Vy = dy/norm*fspeed;
}
find_weapon=false;
}
}
}
//enemy died? ..Resurrect!!!
for(int i=ffc_num;i<32;i++){
if(find_weapon==false){
F=Screen->LoadFFC(i);
if(F->Data==1)find_weapon=true;
}
else i++;
}
if(find_weapon){
F->X=tx;F->Y=ty;
F->Data=d;F->CSet=0;
int fspeed = speed;
int dx = lx - tx;
int dy = ly - ty;
float norm = Sqrt(dx*dx+dy*dy);
if(norm > 0)
{
F->Vx = dx/norm*fspeed;
F->Vy = dy/norm*fspeed;
}
find_weapon=false;
}
int r = Rand(12)+2;
Waitframes(w);
life=Screen->CreateNPC(254);life->HP = enemyHP;
afterlife++;life->X=r*16;life->Y=16;
delay=0;burst=1;
Waitframe();
}
}
}
ffc script instill_red_shooter{
void run(int enemyHP, int shoot_amount, int shoot_delay, int speed){
bool find_weapon = false;
if(enemyHP==0)enemyHP=20;
if(shoot_amount==0)shoot_amount=3;
if(shoot_delay==0)shoot_delay=15;
if(speed==0)speed=2;
npc life;
Waitframe();
life = Screen->CreateNPC(255);Waitframe();
life->HP = enemyHP;
life->X=Rand(218)+16;
life->Y=16;
int ffc_num = 17;
ffc F = Screen->LoadFFC(ffc_num);
int delay = 0;
int burst = 1;
int sa = shoot_amount;
int fd = shoot_delay;
int w = 40; //waitframes
int d = 12; //data
int afterlife;
while(this->Data>0){
Waitframe();
int tx = this->X; int ty = this->Y;
int lx = Link->X; int ly = Link->Y;
while(life->isValid()){
Waitframe();
int tx = this->X; int ty = this->Y;
int lx = Link->X; int ly = Link->Y;
this->X=life->X;this->Y=life->Y;
delay++;
if(delay == fd*burst){
// Find an unused ffc
for(int i=ffc_num;i<32;i++){
if(find_weapon==false){
F=Screen->LoadFFC(i);
if(F->Data==1)find_weapon=true;
}
else i++;
}
burst++;
if(burst==sa)burst=sa*2;
if(burst==sa+sa+1){delay=0;burst=1;}
if(find_weapon){
F->X=tx;F->Y=ty;
F->Data=d;F->CSet=1;
int fspeed = speed;
int dx = lx - tx;
int dy = ly - ty;
float norm = Sqrt(dx*dx+dy*dy);
if(norm > 0)
{
F->Vx = dx/norm*fspeed;
F->Vy = dy/norm*fspeed;
}
find_weapon=false;
}
}
}
//enemy died? ..Resurrect!!!
for(int i=ffc_num;i<32;i++){
if(find_weapon==false){
F=Screen->LoadFFC(i);
if(F->Data==1)find_weapon=true;
}
else i++;
}
if(find_weapon){
F->X=tx;F->Y=ty;
F->Data=d;F->CSet=1;
int fspeed = speed;
int dx = lx - tx;
int dy = ly - ty;
float norm = Sqrt(dx*dx+dy*dy);
if(norm > 0)
{
F->Vx = dx/norm*fspeed;
F->Vy = dy/norm*fspeed;
}
find_weapon=false;
}
int r = Rand(12)+2;
Waitframes(w);
life=Screen->CreateNPC(255);life->HP = enemyHP;
afterlife++;life->X=r*16;life->Y=16;
delay=0;burst=1;
Waitframe();
}
}
}
ffc script blue_fighter{
void run(int enemyHP, int f_delay){
bool find_weapon = false;
if(enemyHP==0)enemyHP=20;
if(f_delay==0)f_delay=60;
int speed = 2;
npc life;
Waitframe();
life = Screen->CreateNPC(254);Waitframe();
life->HP = enemyHP;
life->X=Rand(218)+16;
life->Y=16;
int ffc_num = 17;
ffc F = Screen->LoadFFC(ffc_num);
int delay = 0;
int fd = f_delay;
int burst = 1;
int state=0;
int w = 40; //waitframes
int d = 12; //data
while(true){
Waitframe();
int tx = this->X; int ty = this->Y;
int lx = Link->X; int ly = Link->Y;
this->X=16;this->Y=16;life->X=this->X;life->Y=this->Y;
while(this->Data>1){
Waitframe();
int tx = this->X; int ty = this->Y;
int lx = Link->X; int ly = Link->Y;
life->X=this->X;life->Y=this->Y;
if(state==0){
this->Vy=speed;this->Vx=0;
if(ty>120)state=1;
}
else if(state==1){
for(int i; i<40;i++){
this->Vy-=0.05;this->Vx+=0.05;
life->X=this->X;life->Y=this->Y;Waitframe();
}
state=2;
}
else if(state==2){
Waitframes(10);life->X=this->X;life->Y=this->Y;
Waitframes(10);life->X=this->X;life->Y=this->Y;
Waitframes(10);life->X=this->X;life->Y=this->Y;
Waitframes(10);life->X=this->X;life->Y=this->Y;
Waitframes(10);life->X=this->X;life->Y=this->Y;
Waitframes(10);life->X=this->X;life->Y=this->Y;
for(int i; i<40;i++){
this->Vy-=0.05;this->Vx-=0.05;
life->X=this->X;life->Y=this->Y;Waitframe();
}
state=3;
}
else if(state==3){
this->Vy=-speed;this->Vx=0;
if(ty<64)state=4;
}
else if(state==4){
for(int i; i<40;i++){
this->Vy+=0.05;this->Vx-=0.05;
life->X=this->X;life->Y=this->Y;Waitframe();
}
state=5;
}
else if(state==5){
Waitframes(10);life->X=this->X;life->Y=this->Y;
Waitframes(10);life->X=this->X;life->Y=this->Y;
Waitframes(10);life->X=this->X;life->Y=this->Y;
Waitframes(10);life->X=this->X;life->Y=this->Y;
Waitframes(10);life->X=this->X;life->Y=this->Y;
Waitframes(10);life->X=this->X;life->Y=this->Y;
for(int i; i<40;i++){
this->Vy+=0.05;this->Vx+=0.05;
life->X=this->X;life->Y=this->Y;Waitframe();
}
state=0;delay=0;
}
delay++;
if(delay == fd*burst){
// Find an unused ffc
burst++;
for(int i=ffc_num;i<32;i++){
if(find_weapon==false){
F=Screen->LoadFFC(i);
if(F->Data==1)find_weapon=true;
}
else i++;
}
if(find_weapon){
F->X=tx;F->Y=ty;
F->Data=d;F->CSet=0;
int fspeed = 0.75;
int dx = lx - tx;
int dy = ly - ty;
float norm = Sqrt(dx*dx+dy*dy);
if(norm > 0)
{
F->Vx = dx/norm*fspeed;
F->Vy = dy/norm*fspeed;
}
find_weapon=false;
}
}
if(!(life->isValid())){
this->Data=1;
for(int i=ffc_num;i<32;i++){
if(find_weapon==false){
F=Screen->LoadFFC(i);
if(F->Data==1)find_weapon=true;
}
else i++;
}
if(find_weapon){
F->X=tx;F->Y=ty;
F->Data=d;F->CSet=0;
int fspeed = 0.75;
int dx = lx - tx;
int dy = ly - ty;
float norm = Sqrt(dx*dx+dy*dy);
if(norm > 0)
{
F->Vx = dx/norm*fspeed;
F->Vy = dy/norm*fspeed;
}
find_weapon=false;
}
}
}//while>1
}//true
}
}
ffc script enemy_wave_fighters{
void run(){
int n = 7;int delay=0;
while(true){
Waitframe();
delay++;
if(delay==60||delay==120||delay==180||delay==240||delay==320){
ffc F = Screen->LoadFFC(n);
F->Data=20;n++;
}
if(delay==30||delay==90||delay==150||delay==210||delay==290){
ffc F = Screen->LoadFFC(n);
F->Data=20;n++;
}
}
}
}
//===========================
INCOMPLETE------------->8---------------------------
ffc script blue_stream{
void run(){
bool a_init=false;
int target_ax;int target_ay;
float ax;float ay;
ffc F = Screen->LoadFFC(7);
int blue_dot = 100;
int state=0;
while(true){
Waitframe();
int tx = this->X; int ty = this->Y;
int lx = Link->X; int ly = Link->Y;
if(a_init){
if(white){
//DrawTile(5,ax,ay,blue_dot,1,1,0,0,0,0,0,0,true,128);
if((ax<2||ay<2||ax>238||ay>158)||(ax==target_ax&&ay==target_ay)){ax=tx;ay=ty;a_init=false;}
else if(Abs(ax-lx)<14&&Abs(ay-ly)<14){ax=tx;ay=ty;a_init=false;}
else{
if(ax<target_ax)ax++;if(ay<target_ay)ax++;
if(ax>target_ax)ax--;if(ay>target_ay)ay--;
}
}
else if(black){
//DrawTile(5,ax,ay,blue_dot,1,1,0,0,0,0,0,0,true,128);
if((ax<2||ay<2||ax>238||ay>158)||(ax==target_ax&&ay==target_ay)){ax=tx;ay=ty;a_init=false;}
else if(Abs(ax-lx)<8&&Abs(ay-ly)<8){ax=tx;ay=ty;Link->HP-=16;a_init=false;}
else{
if(ax<target_ax)ax++;if(ay<target_ay)ax++;
if(ax>target_ax)ax--;if(ay>target_ay)ay--;
}
}
}
else{
target_ax=F->X;target_ay=F->Y;ax=tx;ay=ty;a_init=true;
}
}} //while loop
}