Code:
import "std.zh"
const int bombchuflag = 98; //Flag the bombchu can pass through (even if solid)
const int bombchutile = 21752; //Set the tile for your weapon here. Up, Down, Left, Right it should be on the tilepage.
const int bombchuframes = 2; //Set the number of animation frames here.
const int bombchuaspeed = 10;//Set the animation speed here
const int bombchucset = 7; //Set the CSet here
const int bombchudmg = 2; //Set the damage here
const int bombchuspeed = 1; //Set the speed of the bombchu here
int bombchuattack = 0;
int bombchux = 0;
int bombchuy = 0;
int bdir = 0;
bool isSolid(int x,int y){
if(x<0 || x>255 || y<0 || y>175) return false;
int mask=1111b;
if(x%16<8) mask&=0011b;
else mask&=1100b;
if(y%16<8) mask&=0101b;
else mask&=1010b;
int v = Screen->ComboS[ComboAt(x,y)]&mask;
return v != 0;
}
bool bombchucheck(int x, int y){
if((isSolid(x,y) && Screen->ComboF[ComboAt(x,y)] != bombchuflag && Screen->ComboI[ComboAt(x,y)] != bombchuflag)
|| (Screen->ComboF[ComboAt(x,y)] == 6 || Screen->ComboI[ComboAt(x,y)] == 6 ||Screen->ComboF[ComboAt(x,y)] == 11 || Screen->ComboI[ComboAt(x,y)] == 11)) return true;
}
void noaction(){
Link->InputR = false;
Link->InputL = false;
Link->InputA = false;
Link->InputB = false;
Link->InputUp = false;
Link->InputDown = false;
Link->InputRight = false;
Link->InputLeft = false;
}
global script slot_2{
void run(){
while(true){
if(bombchuattack == 2) run_bombchu();
if(bombchuattack == 1) start_bombchu();
Waitframe();
}
}
void run_bombchu() {
lweapon bombchu;
lweapon explosion;
int HP = 0;
bool found = false;
for(int i = 1; i <= Screen->NumLWeapons(); i+= 1) {
bombchu = Screen->LoadLWeapon(i);
if(bombchu->ID == LW_SCRIPT1) {
found = true;
HP = Link->HP;
if(Link->InputUp) bdir = 0;
if(Link->InputDown) bdir = 1;
if(Link->InputLeft) bdir = 2;
if(Link->InputRight) bdir = 3;
if(bdir == 0 && bombchucheck(bombchu->X+8,bombchu->Y+4)
|| (bdir == 1 && bombchucheck(bombchu->X+8,bombchu->Y+12))
|| (bdir == 2 && bombchucheck(bombchu->X+4,bombchu->Y+8))
|| (bdir == 3 && bombchucheck(bombchu->X+12,bombchu->Y+8))) bombchu->DeadState = 0;
bombchu->Dir = bdir;
bombchu->Tile = bombchutile+(bdir*bombchuframes);
bombchu->OriginalTile = bombchutile+(bdir*bombchuframes);
bombchux = bombchu->X;
bombchuy = bombchu->Y;
noaction();
if(Link->HP < HP) bombchu->DeadState = 0;
break;
}
}
if(found == false) {
explosion = Screen->CreateLWeapon(LW_SBOMB);
explosion->Damage = bombchudmg;
explosion->X = bombchux;
explosion->Y = bombchuy;
Link->Action = 0;
bombchuattack = 0;
}
}
void start_bombchu() {
if(Link->X > 15 && Link->X < 241 && Link->Y > 15 && Link->Y < 153){
lweapon bombchu = Screen->CreateLWeapon(LW_SCRIPT1);
bdir = Link->Dir;
bombchu->OriginalTile = bombchutile+(bdir*bombchuframes);
bombchu->Tile = bombchutile+(bdir*bombchuframes);
bombchu->NumFrames = bombchuframes;
bombchu->ASpeed = bombchuaspeed;
bombchu->CSet = bombchucset;
bombchux = 0; bombchuy = 0;
if(bdir>1) bombchux = (((bdir-2)*2)-1)*16;
if(bdir<2) bombchuy = ((bdir*2)-1)*16;
bombchu->X = Link->X+bombchux;
bombchu->Y = Link->Y+bombchuy;
bombchu->Step = bombchuspeed;
Link->Action = LA_ATTACKING;
Game->Counter[6]--;
bombchuattack = 2;
}else{
bdir = Link->Dir;
bombchux = 0; bombchuy = 0;
if(bdir>1) bombchux = (((bdir-2)*2)-1)*16;
if(bdir<2) bombchuy = ((bdir*2)-1)*16;
lweapon explosion = Screen->CreateLWeapon(LW_SBOMB);
explosion->X = Link->X+bombchux;
explosion->Y = Link->Y+bombchuy;
explosion->Damage = bombchudmg;
Link->Action = 0;
bombchuattack = 0;
}
}
}
global script slot_3{
void run(){
bombchuattack = 0;
}
}
item script bombchu{
void run(){
if(Game->Counter[6] > 0) bombchuattack = 1;
}
}
I changed a few things:
* I turned all the variables you didn't want to be globals into globals, and made them constant. That's how you should do it.
* For the ones I didn't make constant, I still had to move them out. There's no two ways about it.
* I split the main script into two different scripts: start_bombchu(), which creates the bombchu, and run_bombchu() which handles its movement and death.
* I changed bombchuattack from a bool to an int, so that the main loop knows which script to call. Check run() to see what I did.
* I also made use of the LW_SCRIPT1 constant.