PDA

View Full Version : SideScroller Pegasus Boots



CJC
01-10-2007, 12:26 AM
Well... sort of...

In The Legend of Zelda, Four Swords Adventures, the level 2 Pegasus boots let you run in the air. After hours of tedious work modifying a jump script that C-Dawg had compiled, I've recreated this bizarre item.



import "std.zh"

// ==========================================
// Dash - This script handles the dash boots.
// ==========================================

ffc script Dash{

int dashforce_maximum; // The maximum force of the player's Dash.
int dashforce_current = 0; // The current force
int i = 0; // This counter slows the rate at which
// dashforce decays, to smooth the dash.

int dash_pause = 0; // This counter prevents the player from
// holding down R for continuous dashing.

void run(){

int savedLinkX;

while(true){



if(Link->Dir==DIR_RIGHT || Link->Dir==DIR_LEFT){

dashforce_maximum = 7;

}

else{

dashforce_maximum = 0;

}




if( (Link->InputR) && (dash_pause == 0) &&


(!canMove(Link->X+17, Link->Y+16)) ||
(!canMove(Link->X+17, Link->Y)) ||
(!canMove(Link->X+17, Link->Y+8)));


{

dashforce_current = dashforce_maximum;
dash_pause = 10;

}

if(Link->Dir==DIR_LEFT){
if(dashforce_current > 0){


if(!canMove(Link->X+4, Link->Y+8)) {
dashforce_current = 0;
}
else {
Link->X = Link->X - dashforce_current;
savedLinkX = Link->X;
if(i == 2){
i = 0;
}
else{
dashforce_current--;
i++;
}
}
}
}
if(Link->Dir==DIR_RIGHT){
if(dashforce_current > 0){
if(!canMove(Link->X+4, Link->Y+8)) {
dashforce_current = 0;
}
else {
Link->X = Link->X + dashforce_current;
savedLinkX = Link->X;
if(i == 2){
i = 0;
}
else{
dashforce_current--;
i++;
}
}
}
}


Link->InputR = false; // This is necessary to stop R from
// flipping your selected item.


// Decrement dash_pause as long as you're on the ground.

if ((!canMove(Link->X+17, Link->Y+16)) ||
(!canMove(Link->X+17, Link->Y)) ||
(!canMove(Link->X+17, Link->Y+8))) {

dash_pause--;
if (dash_pause < 1) { dash_pause = 0; }

}

Waitframe();
} // end of while loop
} // end of void run


// ===================================
// Collision detection function
// ===================================
bool canMove(int x, int y){

if(Link->InputR){
if(Link->Dir==DIR_LEFT){

// 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);

}

if(Link->Dir==DIR_RIGHT){

// 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&=1100b;
else
mask&=0011b;

// 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);
}
}
}// end of canMove

}// end of ffc script



It's got about a 3 to 4 pixel descrepancy on walkability, but if the FFC is on the screen, when you press 'R' Link will run horizontally ignoring gravity until he hits something (Or you let go of R). Usually he'll get partially stuck in a wall, but not far enough to trap you.

It's only for side scroller rooms, I haven't worked out a horizontal/vertical function yet (Though it should be fairly simple, in fact I'll get to work on it right away.


Well, that's my first custom script... what do you think?

EDIT: These actually work, unlike the fullscreen pegasus script. If you're doing a side-scroller quest and you like the sound of this feature, this code is all you'll need.