int GameVars[65536];

const int PEGASUS_DASH 			= 1;
const int DASH_COUNTER 			= 2;
const int STORE_INPUT  			= 3;
const int STORE_HP	   			= 4;
const int SCRIPT_ACTION			= 5;
const int DRAW_X	   			= 6;
const int DRAW_Y	   			= 7;	
const int DASH_SWORD_TILE		= 8;
const int DASH_SWORD_CSET		= 9;
const int DUST_INDEX			= 10;
const int SCROLL_COUNTER		= 15;
const int SCROLL_DIRECTION		= 16;


const int NUM_DUST					= 4;

const int T_DUST            		= 1222;//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           		= 6;//Dust Kick-up CSet
const int DashSFXLength       		= 9;//Time between repeating Dash SFX
const int CF_DASH            		= 98;//Flag that Link can't dash through if walkable, 

//Set these to proper sprites for any swords you have.
const int SPRITE_SWORD1  	= 46;
const int SPRITE_SWORD2  	= 1;
const int SPRITE_SWORD3  	= 48;
const int SPRITE_SWORD4 	= 3;
const int SPR_ROCK 		 	= 18;
const int SPRITE_BUSH_CUT 	= 52;
const int SPRITE_FLOWER_CUT = 53;
const int SPRITE_GRASS_CUT 	= 54;


const int SFX_DASH           		= 64;//Dashing SFX
const int SFX_HITWALL        		= 9;//Hitting a wall

const int SA_NONE					= 00000000000b;//No special action
const int SA_DASHING				= 10000000000b;//Diving.
const int CAN_DROWN					= 00000000001b;//If you can drown in walkable water;

//Currently performing scripted action
bool GetScriptAction(int action){
	return ((GameVars[SCRIPT_ACTION]&action)!=0);
}

//Set scripted action active
void SetScriptAction(int action){
	if((GameVars[SCRIPT_ACTION]&action)==0)
		GameVars[SCRIPT_ACTION]|=action;
}

//Deactivate script action
void UnSetScriptAction(int action){
	if((GameVars[SCRIPT_ACTION]&action)!=0)
		GameVars[SCRIPT_ACTION]&=~action;
}

global script PegasusActive{
	void run(){
		GameVars[SCRIPT_ACTION]= SA_NONE;
		Link->CollDetection = true;
		GameVars[STORE_INPUT]=0;
		while(true){
            ScrollFix();
			if(GameVars[STORE_INPUT])
				PegasusBoots();
            Waitdraw();
			UpdateLWZH();
			GameVars[STORE_HP]= Link->HP;
            Waitframe();
        }//!End while(true)
	}
}

int BackLinkX(){
   if(Link->Dir == DIR_UP || Link->Dir == DIR_DOWN) 
		return Link->X+8;
   else if(Link->Dir == DIR_LEFT) 
		return Link->X+16;
   else if(Link->Dir == DIR_RIGHT) 
		return Link->X;
   return Link->X;
}
 
int BackLinkY(){
   if(Link->Dir == DIR_LEFT || Link->Dir == DIR_RIGHT) 
		return Link->Y+8;
   else if(Link->Dir == DIR_UP) 
		return Link->Y+16;
   else if(Link->Dir == DIR_DOWN)
		return Link->Y;
   return Link->Y;
}
 
// Pegasus Boots
void PegasusBoots(){
    lweapon mysword;
	int dashSwordTile;
	int dashSwordCSet;
    int loc = ComboAt(Link->X+8,Link->Y+8);
    // this fixes the bug that makes Link dive immediately after dashing into water with flippers
    if(GameVars[DASH_COUNTER] < 0){
        GameVars[DASH_COUNTER]++;
        if(Link->Action == LA_SWIMMING)
			Link->InputA = false;
        else if(Link->Action == LA_DIVING){
            Link->Action == LA_SWIMMING;
            Link->InputA = false;
        }
        else 
			GameVars[DASH_COUNTER] = 0;
    }
    // fixs a bug with drownable water and diagonal movement off
    if(GetScriptAction(CAN_DROWN) && IsWater(loc) 
       && Link->Action != LA_SWIMMING && Link->Action != LA_DROWNING && Link->Action != LA_DIVING){
        if(Link->Dir == DIR_UP) 
			Link->InputUp = true;
        else if(Link->Dir == DIR_DOWN) 
			Link->InputDown = true;
        else if(Link->Dir == DIR_LEFT) 
			Link->InputLeft = true;
        else if(Link->Dir == DIR_RIGHT) 
			Link->InputRight = true;
    }
	//Handles events if you should be using the Pegasus Boots.
    if(GameVars[PEGASUS_DASH] >= 0){
	    //If you haven't collided with something.
        if(!GetScriptAction(SA_DASHING)){
		    //Check for things that should stop them from working.
            if( (Link->Action != LA_SCROLLING 
				&& ((GameVars[STORE_INPUT] == 1 && !Link->InputA) 
				|| (GameVars[STORE_INPUT] == 2 && !Link->InputB)))
                || GameVars[STORE_HP] > Link->HP || Link->Action == LA_RAFTING
                || Link->Action == LA_DROWNING || Link->Action == LA_SWIMMING 
				|| Link->Action == LA_DIVING
                || (!GetScriptAction(CAN_DROWN) && IsWater(TouchedComboLoc())) 
				|| (GetScriptAction(CAN_DROWN) && IsWater(loc)) ){
                    StopDash();
                    // this fixes the bug that makes Link dive immediately 
					// after dashing into water with flippers
                    if(Link->Action == LA_SWIMMING) 
						GameVars[DASH_COUNTER] = -20;
            }
 
			//If you're not scrolling and using Pegasus Boots
            if(Link->Action != LA_SCROLLING && GameVars[DASH_COUNTER] > 10){
                if(GameVars[PEGASUS_DASH] == DIR_UP && DashCheck(Link->X+8,Link->Y+6,true) != 2){
                    Link->Y--;
                    Link->InputUp = true;
					Link->InputA= false;
                }
                else if(GameVars[PEGASUS_DASH]  == DIR_DOWN 
						&& DashCheck(Link->X+8,Link->Y+18,true) != 2){
                    Link->Y++;
                    Link->InputDown = true;
					Link->InputA= false;
                }
                else if(GameVars[PEGASUS_DASH]  == DIR_LEFT 
						&& DashCheck(Link->X,Link->Y+12,false) != 2){
                    Link->X--;
                    Link->InputLeft = true;
					Link->InputA= false;
                }
                else if(GameVars[PEGASUS_DASH]  == DIR_RIGHT 
						&& DashCheck(Link->X+16,Link->Y+12,false) != 2){
                    Link->X++;
                    Link->InputRight = true;
					Link->InputA= false;
                }
                else{
                    UnSetScriptAction(SA_DASHING);
                    GameVars[DASH_COUNTER]= 0;
                }
            }//end DashCounter if
            // do stuff if not jumping
            if( !IsJumping() ){
               if(ComboFI(loc,CF_DASH) && Screen->ComboS[loc] == 1111b){
                   Screen->ComboD[loc]=Screen->UnderCombo; 
				   // comment out if using above method instead of under combo
                   if(Screen->ComboF[loc] == CF_DASH) 
						Screen->ComboF[loc] = 0;
				   lweapon rock = FireLWeapon(LW_SCRIPT1,Link->X+8, Link->Y+8,
												DegtoRad(0),150, 0,SPR_NULL, 0,0);
				   SetLWeaponLifespan(rock,LWL_TIMER,1);
				   SetLWeaponDeathEffect(rock,LWD_LOB_DIAGONAL,SPR_ROCK);
				    if(ComboFI(loc,CF_ARMOSITEM)){
						item theitem = Screen->CreateItem(Screen->RoomData);
						theitem->X= ComboX(loc);
						theitem->Y= ComboY(loc);
						theitem->Pickup |= IP_HOLDUP;
						theitem->Pickup |= IP_ST_SPECIALITEM;
						Screen->ComboF[loc]= 0;
						Screen->ComboI[loc]= 0;
					}
               }
               DustDrawTile();  // use new dust draw code that works while scrolling
               if(GameVars[DASH_COUNTER]%DashSFXLength == 0) 
					Game->PlaySound(SFX_DASH);
            }
            // draws dashSword when scrolling
            if(Link->Action == LA_SCROLLING 
				&& GameVars[DASH_SWORD_TILE] > 0){
				dashSwordTile = GameVars[DASH_SWORD_TILE];
				dashSwordCSet = GameVars[DASH_SWORD_CSET];
                 if(GameVars[PEGASUS_DASH] == DIR_UP)
                    Screen->DrawTile(2,GameVars[DRAW_X]+InFrontX(GameVars[SCROLL_DIRECTION],6),
									 GameVars[DRAW_Y]+InFrontY(GameVars[SCROLL_DIRECTION],6),
                                     dashSwordTile,1,1,dashSwordCSet,-1,-1,0,0,0,0,true,128);
                 else if(GameVars[PEGASUS_DASH] == DIR_DOWN)
                    Screen->DrawTile(2,GameVars[DRAW_X]+InFrontX(GameVars[SCROLL_DIRECTION],6),
										GameVars[DRAW_Y]+InFrontY(GameVars[SCROLL_DIRECTION],6),
                                     dashSwordTile,1,1,dashSwordCSet,-1,-1,0,0,0,3,true,128);
                 else if(GameVars[PEGASUS_DASH] == DIR_LEFT)
                    Screen->DrawTile(2,GameVars[DRAW_X]+InFrontX(GameVars[SCROLL_DIRECTION],6),
										GameVars[DRAW_Y]+InFrontY(GameVars[SCROLL_DIRECTION],6)+3,
										dashSwordTile,1,1,dashSwordCSet,-1,-1,0,0,0,1,true,128);
                 else if(GameVars[PEGASUS_DASH] == DIR_RIGHT)
                    Screen->DrawTile(2,GameVars[DRAW_X]+InFrontX(GameVars[SCROLL_DIRECTION],6),
										GameVars[DRAW_Y]+InFrontY(GameVars[SCROLL_DIRECTION],6),
										dashSwordTile,1,1,dashSwordCSet,-1,-1,0,0,0,0,true,128);
            }
            int swordEquip = LinkSwordEquip();
			//Handles assignment of sword sprite.
            if(swordEquip > -1 && GameVars[DASH_COUNTER]>10){
                mysword = LoadLWeaponOf(LW_SCRIPT3);
                if(!mysword->isValid()){
                     mysword = Screen->CreateLWeapon(LW_SCRIPT3);
                     //if(LinkSwordEquip()==I_SWORD5)
						//mysword->Damage = 16;
					 //else if(LinkSwordEquip()==I_SWORD4)
						//mysword->Damage = 8;
					 if(LinkSwordEquip()==I_SWORD4)
						mysword->Damage = 8;	
					 else if(LinkSwordEquip()==I_SWORD3)
						mysword->Damage = 4;
					 else if(LinkSwordEquip()==I_SWORD2)
						mysword->Damage = 2;
					 else 
						mysword->Damage = 1;
                }
                //f(LinkSwordEquip()==I_SWORD5)
					//mysword->UseSprite(SPRITE_SWORD5);
                //else if(LinkSwordEquip()==I_SWORD4)
					//mysword->UseSprite(SPRITE_SWORD4);
				if(LinkSwordEquip()==I_SWORD4)
					mysword->UseSprite(SPRITE_SWORD4);	
                else if(LinkSwordEquip()==I_SWORD3)
					mysword->UseSprite(SPRITE_SWORD3);
                else if(LinkSwordEquip()==I_SWORD2)
					mysword->UseSprite(SPRITE_SWORD2);
                else 
					mysword->UseSprite(SPRITE_SWORD1);
                //end sprite if
                mysword->X = GameVars[DRAW_X]+InFrontX(GameVars[PEGASUS_DASH], 6);
                mysword->Y = GameVars[DRAW_Y]+InFrontY(GameVars[PEGASUS_DASH], 6);
                mysword->Dir = GameVars[PEGASUS_DASH];
                if ( mysword->Dir == DIR_DOWN )
					mysword->Flip = FLIP_B;
				else if ( mysword->Dir == DIR_LEFT ){
					mysword->OriginalTile++;
					mysword->Y += 3;
					mysword->Tile = mysword->OriginalTile;
					mysword->Flip = FLIP_H;
				}
				else if ( mysword->Dir == DIR_RIGHT ){
					mysword->OriginalTile++;
					mysword->Tile = mysword->OriginalTile;
				} 
                GameVars[DASH_SWORD_TILE] = mysword->Tile;
                GameVars[DASH_SWORD_CSET] = mysword->OriginalCSet;
                DoDashSlash(ComboAt(TouchedX()+InFrontX(mysword->Dir,4),
							TouchedY()+InFrontY(mysword->Dir,4)));
            }
			//Takes away sword sprite.
            else{
                mysword = LoadLWeaponOf(LW_SCRIPT3);
                Remove(mysword);
                GameVars[DASH_SWORD_TILE] = 0;
                GameVars[DASH_SWORD_CSET] = 0;
            }//end mysword if
        }//end !PegasusCollision if
        else{ //is PegasusCollision so stop the effect.
            NoAction();
            if(GameVars[PEGASUS_DASH] == 0 && DashCheck(Link->X+8,Link->Y+6,true) == 0) 
				Link->Y++;
            else if(GameVars[PEGASUS_DASH] == 1 && DashCheck(Link->X+8,Link->Y+18,true) == 0) 
				Link->Y--;
            else if(GameVars[PEGASUS_DASH] == 2 && DashCheck(Link->X+18,Link->Y+8,false) == 0)
				Link->X++;
            else if(GameVars[PEGASUS_DASH] == 3 && DashCheck(Link->X-2,Link->Y+8,false) == 0)
				Link->X--;
            if(GameVars[DASH_COUNTER] == 1){
                 Screen->ClearSprites(SL_LWPNS);
                 Game->PlaySound(SFX_HITWALL);
                 Screen->Quake = 10;
            }
            else if(GameVars[DASH_COUNTER] == 10){
                 StopDash();
                 UnSetScriptAction(SA_DASHING);
            }
            if(GameVars[DASH_COUNTER] < 5) 
				Link->Z++;
        }// end PegasusCollision if/else
        GameVars[DASH_COUNTER]++; 
     }// end PegasusDash if
     else{ // !PegasusDash
        mysword = LoadLWeaponOf(LW_SCRIPT3);
        Remove(mysword);
        GameVars[DASH_SWORD_TILE] = 0;
        GameVars[DASH_SWORD_CSET] = 0;
     }//end PegasusDash if/else
     GameVars[STORE_HP] = Link->HP;
}//end function

//Draws dust behind Link. 
void DustDrawTile(){
   //You've got to be using the Pegasus Boots for this to work.
   if(GameVars[PEGASUS_DASH] < 0)
		return;
   int dX;
   int dY;
   int i;
   //You have to have been dashing for a certain amount of time.
   if(GameVars[DASH_COUNTER]%4 == 0){
      for(i = 0; i < NUM_DUST; i++){
         if(GameVars[DUST_INDEX+i] == 0){
            GameVars[DUST_INDEX+i] = 1;
            break;   
         }
      }
   }
	//Handles coordinates for drawing the dust.
   for(i = 0; i < NUM_DUST; i++){
      if(GameVars[DUST_INDEX+i]==0) 
		continue;
      if(GameVars[PEGASUS_DASH] == DIR_UP){                        
         dX = GameVars[DRAW_X];
         if(GameVars[DUST_INDEX+i] < 4) 
			dY = GameVars[DRAW_Y]+8;
         else 
			dY = GameVars[DRAW_Y]+8+3+(GameVars[DUST_INDEX+i]-1);
      }
      else if(GameVars[PEGASUS_DASH] == DIR_DOWN){
         dX = GameVars[DRAW_X];
         if(GameVars[DUST_INDEX+i] < 4) 
			dY = GameVars[DRAW_Y]+8;
         else 
			dY = GameVars[DRAW_Y]+8-3-(GameVars[DUST_INDEX+i]-1);
      }
      else if(GameVars[PEGASUS_DASH] == DIR_LEFT){
         if(GameVars[DUST_INDEX+i] < 4) 
			dX = GameVars[DRAW_X];
         else 
			dX = GameVars[DRAW_X]+3+(GameVars[DUST_INDEX+i]-1);
         dY = GameVars[DRAW_Y]+8;
      }
      else if(GameVars[PEGASUS_DASH] == DIR_RIGHT){
         if(GameVars[DUST_INDEX+i] < 4) 
			dX = GameVars[DRAW_X];
         else 
			dX = GameVars[DRAW_Y]-3-(GameVars[DUST_INDEX+i]-1);
         dY = GameVars[DRAW_Y]+8;
      }
	  //Draw the dust.
      Screen->FastTile(2, dX, dY, T_DUST+ Floor(GameVars[DUST_INDEX+i]/DustASpeed), DustCSet, 128);
      if(GameVars[DUST_INDEX+i] == DustAFrames*DustASpeed) 
		 GameVars[DUST_INDEX+i] = 0;
      else 
		 GameVars[DUST_INDEX+i]++;
   }
}

//An alternate method for drawing the dust. 
void DustDrawLW(){
   lweapon Dust;
   if(GameVars[DASH_COUNTER]%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;
      }//end for loop
      Dust = Screen->CreateLWeapon(LW_SCRIPT10);
      Dust->OriginalTile = T_DUST;
      Dust->CSet = DustCSet;
      Dust->Y = GameVars[DRAW_Y]+8;
      Dust->X = GameVars[DRAW_X];
      Dust->NumFrames = DustAFrames;
      Dust->ASpeed = DustASpeed;
	  SetLWeaponLifespan(Dust,LWL_TIMER,DustAFrames*DustASpeed);
      SetLWeaponDeathEffect(Dust,LWD_VANISH,0);
   }//end dust if
}
 
 
// 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 && CanDashSlash(x,y) ) 
		Solid = false;
     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;
}
 
//fixes a bug where you can't initiate a dash next to a slashable solid combo
bool CanDashSlash(int x, int y){
    if(LinkSwordEquip() == -1) 
		return false;
    int loc;
    loc = ComboAt(x, y);
    // can add more combo types here by adding     || Screen->ComboT[loc] == CT_ 
    // CT_ types you might consider CT_SLASH, CT_SLASHNEXT, 
	// CT_SLASHNEXTITEM if those are solid in your quest
    if(Screen->ComboT[loc] == CT_BUSH
		|| Screen->ComboT[loc] == CT_BUSHNEXT 
		|| Screen->ComboT[loc] == CT_SLASHNEXTITEM 
		|| Screen->ComboT[loc] == CT_FLOWERS ) 
         return true;
    return false;
}
 
//returns the item# of an equipped sword.  checks and returns A button first, then B button.  
//returns -1 if no sword equipped.
int LinkSwordEquip(){
    itemdata itm = Game->LoadItemData( GetEquipmentA() );
    if(itm->Family==IC_SWORD) 
		return GetEquipmentA();
    itm = Game->LoadItemData(GetEquipmentB());
    if(itm->Family==IC_SWORD) 
		return GetEquipmentB();
    return -1;
}
 
// replaces the code in old Pegasus boots function for dash cutting through slashable combos.
// allows easier customization to suit your needs.
void __DoDashSlash(int loc){
   int ctype = Screen->ComboT[loc];
   int sprite;
   int itmset = IS_COMBOS; // item set 12 (tall grass by default)
   bool playsound = false;
   // add sprites to certain types
   if(ctype == CT_BUSH || ctype == CT_BUSHNEXT) 
		sprite = SPRITE_BUSH_CUT;
   else if(ctype == CT_TALLGRASS || ctype == CT_TALLGRASSNEXT) 
		sprite = SPRITE_GRASS_CUT;
   else if(ctype == CT_FLOWERS) 
		sprite = SPRITE_FLOWER_CUT;
   // no sprite is typically associated with Slash type combos, but it could be added.
   // itemset is changed here to the default for these types.  could add more item sets based on type
   if(ctype == CT_SLASHITEM || ctype == CT_SLASHNEXTITEM) 
		itmset = 10; // default for these combo types
   //these types default to undercombo
   if(ctype == CT_BUSH || ctype == CT_TALLGRASS 
		|| ctype == CT_FLOWERS || ctype == CT_SLASH || ctype == CT_SLASHITEM){
      Screen->ComboD[loc] = Screen->UnderCombo;
      playsound = true;
   }
   //these types default to next combo
   if(ctype == CT_BUSHNEXT || ctype == CT_TALLGRASSNEXT
		|| ctype == CT_FLOWERS || ctype == CT_SLASHNEXT || ctype == CT_SLASHNEXTITEM){
      Screen->ComboD[loc] += 1;
      playsound = true;
   }
   //no functionality added for Continuous type combos.
   if(playsound){
      CreateGraphicAt(sprite,ComboX(loc),ComboY(loc));
      Game->PlaySound(SFX_GRASSCUT);
      ItemSetAt(itmset,loc);
   }//end playsound if					
}
 
//Handles combo interaction.
int TouchedComboLoc(){
    int loc;
    loc = ComboAt( TouchedX(), TouchedY() );
    return loc;
}
 
 
int TouchedX(){
    int x;
    if(Link->Dir == DIR_UP || Link->Dir == DIR_DOWN) 
		x = Link->X+8; 
    else if(Link->Dir == DIR_LEFT)  
		x = Link->X-1;
    else if(Link->Dir == DIR_RIGHT) 
		x = Link->X+17;
    return x;
}
 
 
int TouchedY(){
    int y;
    if(Link->Dir == DIR_UP)         
		y = Link->Y+7;
    else if(Link->Dir == DIR_DOWN) 
		y = Link->Y+17;
    else if(Link->Dir == DIR_LEFT || Link->Dir == DIR_RIGHT)  
		y = Link->Y+8;
    return y;
}
 
//Handles scrolling while using Pegasus Boots. 
void ScrollFix(){
   //function by Saffith
   if(Link->Action==LA_SCROLLING){
       if(GameVars[SCROLL_DIRECTION]==-1){
           if(Link->Y>160){
               GameVars[SCROLL_DIRECTION]=DIR_UP;
               GameVars[SCROLL_COUNTER]=45;
           }
           else if(Link->Y<0){
               GameVars[SCROLL_DIRECTION]=DIR_DOWN;
               GameVars[SCROLL_COUNTER]=45;
           }
           else if(Link->X>240){
               GameVars[SCROLL_DIRECTION]=DIR_LEFT;
               GameVars[SCROLL_COUNTER]=65;
           }
           else{
               GameVars[SCROLL_DIRECTION]=DIR_RIGHT;
               GameVars[SCROLL_COUNTER]=65;
           }
       }
       if(GameVars[SCROLL_DIRECTION]==DIR_UP && GameVars[SCROLL_COUNTER]<45 
			&& GameVars[SCROLL_COUNTER]>4)
				GameVars[DRAW_Y]+=4;
       else if(GameVars[SCROLL_DIRECTION]==DIR_DOWN && GameVars[SCROLL_COUNTER]<45
			&& GameVars[SCROLL_COUNTER]>4)
				GameVars[DRAW_Y]-=4;
       else if(GameVars[SCROLL_DIRECTION]==DIR_LEFT && GameVars[SCROLL_COUNTER]<65 
			&& GameVars[SCROLL_COUNTER]>4)
				GameVars[DRAW_X]+=4;
       else if(GameVars[SCROLL_DIRECTION]==DIR_RIGHT && GameVars[SCROLL_COUNTER]<65 
			&& GameVars[SCROLL_COUNTER]>4)
				GameVars[DRAW_X]-=4;
       GameVars[SCROLL_COUNTER]--;
   }
   else{
       GameVars[DRAW_X]=Link->X;
       GameVars[DRAW_Y]=Link->Y-Link->Z;
       if(GameVars[SCROLL_DIRECTION]!=-1)
           GameVars[SCROLL_DIRECTION]=-1;
   }
}

//Checks to see if you're jumping.
bool IsJumping(){
  if(IsSideview()){
     if(isSVLadder(Link->X+8,Link->Y+16) ) 
		return false;   //!!!!!!! remove if not using sideview ladder
     if(Link->Action == LA_SWIMMING || Link->Action == LA_DIVING || Link->Action == LA_DROWNING) 
		return false;
     if(Link->Jump != 0) 
		return true;
     if(!OnSidePlatform(Link->X,Link->Y))
		return true;
  }
  else if(Link->Z > 0) 
	return true;
  return false;
}

// Section 12. Sideview Ladder Script

// Sideview Ladder constant
const int CF_SVLADDER               = 161;      // ComboFlag for Sideview Ladder
                                                // This ComboFlags can be reused since this script requires both the ComboType and Flag.
                                                // If reusing, that script should check that it isn't the SV ComboType.

// Returns true if x,y is both the SV Ladder flag and type
bool isSVLadder(int x, int y){
   int loc = ComboAt(x,y);
   return(ComboFI(loc,CF_SVLADDER));
}

bool isSVLadder(int loc){
   return(ComboFI(loc, CF_SVLADDER) );
}


//Pegasus Boots Item Script.
item script PegasusBoots{
   void run(){
      //Check for all conditions that could stop them from working first.
      if(ComboFI(Link->X+8,Link->Y+8,CF_DASH))
			Quit();
      if(!GetScriptAction(CAN_DROWN)&& IsWater(TouchedComboLoc()) ) 
			Quit();
      if(Link->Action == LA_SWIMMING || Link->Action == LA_DROWNING) 
			Quit();;
      GameVars[PEGASUS_DASH] = Link->Dir; 
      if(Link->InputB && !Link->InputA) 
		 GameVars[STORE_INPUT] = 2;
      else if(Link->InputA && !Link->InputB) 
		 GameVars[STORE_INPUT] = 1;
   }
}

//Stops the Pegasus Boots code.
void StopDash(){
   GameVars[PEGASUS_DASH] = -1;
   GameVars[DASH_COUNTER] = 0;
}
