PDA

View Full Version : Bridge Generator



pkmnfrk
08-19-2010, 01:48 AM
http://www.youtube.com/watch?v=NV5_CT1ENvY


ffc script BridgeGenerator {
void run(int D, int delay, int snd) {
int origD = this->Data;
this->Data = 0;

int myPos = ComboAt(this->X, this->Y);

if(Screen->D[D] != 0) {
int dir = GetDir(myPos);

while(Screen->ComboF[myPos] != CF_SCRIPT2) {

Screen->ComboD[myPos] = origD;

if(dir == DIR_UP) {
this->Y -= 16;
} else if(dir == DIR_DOWN) {
this->Y += 16;
} else if(dir == DIR_LEFT) {
this->X -= 16;
} else if(dir == DIR_RIGHT) {
this->X += 16;
}

if(this->X < 0 || this->X >= 256 || this-> Y < 0 || this->Y >= 176) break;

myPos = ComboAt(this->X, this->Y);
}

return;
}

while(Screen->D[D] == 0) {
Waitframe();
}


int dir = GetDir(myPos);

while(Screen->ComboF[myPos] != CF_SCRIPT2) {

Screen->ComboD[myPos] = origD;

if(dir == DIR_UP) {
this->Y -= 16;
} else if(dir == DIR_DOWN) {
this->Y += 16;
} else if(dir == DIR_LEFT) {
this->X -= 16;
} else if(dir == DIR_RIGHT) {
this->X += 16;
}

if(this->X < 0 || this->X >= 256 || this-> Y < 0 || this->Y >= 176) break;

myPos = ComboAt(this->X, this->Y);

if(snd != 0) Game->PlaySound(snd);

Waitframes(delay);
}

return;

}

int GetDir(int pos) {
if(Screen->ComboF[pos - 16] == CF_SCRIPT1) return DIR_UP;
if(Screen->ComboF[pos + 16] == CF_SCRIPT1) return DIR_DOWN;
if(Screen->ComboF[pos - 1] == CF_SCRIPT1) return DIR_LEFT;
if(Screen->ComboF[pos + 1] == CF_SCRIPT1) return DIR_RIGHT;

int s[] = "Hey idiot, try setting the flags on the bridge you just made!";
TraceS(s);
return DIR_UP;
}
}

This script allows you to create bridges like those found in the Gameboy Zelda games that create themselves one tile at a time (eg, the bridge in Oracle of Ages just to the West of Lynna City). It is triggered by "listening" to one of the Screen->D variables, and properly handles the case where it's already been triggered before (eg, if Link leaves the screen, but comes back).

Arguments:
D0 - The Screen->D slot to listen to. It will activate the moment Screen->D[D] becomes non-zero
D1 - How long to wait between bridge segments appearing.
D2 - The sound effect to play when a bridge segment appears.

Usage:
This ranks a MEDIUM on the complexity scale.

First, place an FFC on the spot where the bridge should start. Make its combo the combo of the bridge. Also, enable the "Run script at screen init" option to avoid graphical glitches.

Next, you need to place two flags on the map. The first one should be "General Purpose 1", and should be placed immediately next to the FFC, in the direction you want the bridge to go. The second flag should be "General Purpose 2", and should be placed where you want the bridge to end. It should be placed just AFTER the last bridge tile (eg, one tile past). (imaging the bridge as a beam of light, and the flag as a wall blocking the beam of light)

Check the video for details.

When the bridge creates itself, it first looks for the first flag to know what direction to build in. If it doesn't find it, it will trace an error to Allegro.log, and default to UP. Then, it will build until it finds the second flag. If it doesn't find that, it will stop at the edge of the screen.

Christian
07-05-2011, 04:31 AM
For some reason this doesn't seem to be working for me in Build 1346 do you mind fixing it?