import "std.zh"
import "string.zh"
//Other irrelevant code here
const int CF_DASH = 98; //Flag that Link can't dash through if walkable, and will break if solid
const int SFX_DASH = 67; //Dashing SFX
const int SFX_HITWALL = 68; //Hitting a wall
const int SFX_PEGASUSBREAK = 66; //SFX to play when breaking a Pegasus Boot block
const int T_DUST = 27544; //Dust Kick-up tile
const int DustAFrames = 4; //Dust Kick-up animation frames
const int DustASpeed = 4; //Dust Kick-up animation speed
const int DustCSet = 3; //Dust Kick-up CSet
const int DashSFXLength = 9; //Time between repeating Dash SFX
global script globalScript
{
void run()
{
while(true)
{
PegasusBoots();
StoreHP = Link->HP;
Waitdraw();
//Screen->DrawInteger(6, ComboX(48), ComboY(48), FONT_Z1, 0x01, 0x00, 0, 0, StoreInput, 0, OP_OPAQUE);
//Screen->DrawInteger(6, ComboX(64), ComboY(64), FONT_Z1, 0x01, 0x00, 0, 0, DashCounter, 0, OP_OPAQUE);
if (PegasusDash)
{
Screen->DrawInteger(6, ComboX(80), ComboY(80), FONT_Z1, 0x01, 0x00, 0, 0, 100, 0, OP_OPAQUE);
}
Waitframe();
}//!End while(true)
}//!End void run()
}//!End global script globalScript
// Global Variables
bool PegasusDash;
bool PegasusCollision;
int DashCounter;
int StoreInput;
int StoreHP;
int INV_COMBO_ID = 4320;//Combo I'm using for broken Pegasus Blocks
// Pegasus Boots
void PegasusBoots(){
lweapon mysword;
if(PegasusDash){
if(!PegasusCollision){
int loc = ComboAt(Link->X+8,Link->Y+8);
//Check if Link should be dashing
if(((StoreInput == 1 && !Link->InputA)
|| (StoreInput == 2 && !Link->InputB))
|| StoreHP < Link->HP
|| Screen->ComboT[loc] == CT_WATER){
PegasusDash = false;
DashCounter = 0;
}
//Stop all actions
NoAction();
//Movement
if(DashCounter > 10){
if(Link->Dir == 0 && DashCheck(Link->X+8,Link->Y+6,true) != 2){
Link->Y -= 2;
Link->InputUp = true;
}
else if(Link->Dir == 1 && DashCheck(Link->X+8,Link->Y+18,true) != 2){
Link->Y += 2;
Link->InputDown = true;
}
else if(Link->Dir == 2 && DashCheck(Link->X,Link->Y+12,false) != 2){
Link->X -= 2;
Link->InputLeft = true;
}
else if(Link->Dir == 3 && DashCheck(Link->X+16,Link->Y+12,false) != 2){
Link->X += 2;
Link->InputRight = true;
}
else{
PegasusCollision = true;
DashCounter = 0;
}
}
//Break Pegasus Blocks
if(ComboFI(Link->X+8,Link->Y+8,CF_DASH) && Screen->ComboS[loc] == 1111b){
//Screen->ComboD[loc]++;
Screen->ComboD[loc]=INV_COMBO_ID;
if(Screen->ComboF[loc] == CF_DASH) Screen->ComboF[loc] = 0;
Game->PlaySound(SFX_PEGASUSBREAK);
}
//Dust tile animation
lweapon Dust;
if(DashCounter%4 == 0){
for(int j=1;j<=Screen->NumLWeapons();j++){
Dust = Screen->LoadLWeapon(j);
if(Dust->ID != LW_SCRIPT10) continue;
if(Link->Dir < 1) Dust->Y-=3;
else if(Link->Dir < 2) Dust->Y+=3;
else if(Link->Dir < 3) Dust->X-=3;
else if(Link->Dir < 4) Dust->X+=3;
}
Dust = Screen->CreateLWeapon(LW_SCRIPT10);
Dust->OriginalTile = T_DUST;
Dust->CSet = DustCSet;
Dust->Y = Link->Y+8;
Dust->X = Link->X;
Dust->NumFrames = DustAFrames;
Dust->ASpeed = DustASpeed;
Dust->DeadState = DustAFrames*DustASpeed;
}
//Play SFX
if(DashCounter%DashSFXLength == 0) Game->PlaySound(SFX_DASH);
// using sword while running
if((GetEquipmentA()==I_SWORD1 || GetEquipmentB()==I_SWORD1) && DashCounter>10){
mysword = LoadLWeaponOf(LW_SCRIPT3);
if(!mysword->isValid()){
mysword = Screen->CreateLWeapon(LW_SCRIPT3);
mysword->Damage = 8;
}
mysword->UseSprite(0);
mysword->X = Link->X+InFrontX(Link->Dir, 6);
mysword->Y = Link->Y+InFrontY(Link->Dir, 6);
mysword->Dir = Link->Dir;
if(mysword->Dir < 2){
if(mysword->Dir == DIR_DOWN) mysword->Flip = 3;
}
else{
mysword->OriginalTile += 1;
mysword->Tile = mysword->OriginalTile;
if(mysword->Dir == DIR_LEFT) mysword->Flip = 1;
mysword->Y += 3;
}
}
else Remove(mysword);
}
else{
//Bounceback after hitting a wall
NoAction();
if(DashCounter == 1){
Screen->ClearSprites(SL_LWPNS);
Game->PlaySound(SFX_HITWALL);
Screen->Quake = 10;
}
else if(DashCounter == 10){
PegasusDash = false;
PegasusCollision = false;
DashCounter = 0;
}
if(Link->Dir == 0 && DashCheck(Link->X+8,Link->Y+6,true) == 0) Link->Y += 2;
else if(Link->Dir == 1 && DashCheck(Link->X+8,Link->Y+18,true) == 0) Link->Y -= 2;
else if(Link->Dir == 2 && DashCheck(Link->X+18,Link->Y+8,false) == 0) Link->X += 2;
else if(Link->Dir == 3 && DashCheck(Link->X-2,Link->Y+8,false) == 0) Link->X -= 2;
if(DashCounter < 5) Link->Z += 4;
}
DashCounter++;
}
else{
mysword = LoadLWeaponOf(LW_SCRIPT3);
Remove(mysword);
// if(Link->Item[124]) Link->Item[124]=false;
}
}
// Check whether Link can dash onto a combo
int DashCheck(int x, int y, bool xy){
int xoffset; int yoffset;
bool Solid;
if(xy) xoffset = 4;
else yoffset = 3;
if(Screen->isSolid(x-xoffset,y-yoffset) || Screen->isSolid(x+xoffset,y+yoffset)) Solid = true;
if(!Solid && !ComboFI(x-xoffset,y-yoffset,CF_DASH)
&& !ComboFI(x+xoffset,y+yoffset,CF_DASH)) return 0;
else if(Solid && (ComboFI(x-xoffset,y-yoffset,CF_DASH)
|| ComboFI(x+xoffset,y+yoffset,CF_DASH))) return 1;
else return 2;
}
item script PegasusBoots{
void run(){
if(Screen->ComboT[ComboAt(Link->X+8,Link->Y+8)] == CT_WATER
|| ComboFI(Link->X+8,Link->Y+8,CF_DASH)) Quit();
PegasusDash = true;
if(Link->InputB && !Link->InputA) StoreInput = 2;
else if(Link->InputA && !Link->InputB) StoreInput = 1;
}
}