PDA

View Full Version : Multiblock Trigger



C-Dawg
10-30-2006, 11:53 PM
Thanks to Saffith for helping finalize and debug this one.

This is utility script, pretty well described by the in-code comments.

NOTE: You must specify locations for your blocks using the upper-left corner of the tile.



// ===============================================
// multiblock_trigger - This FFC will change combo
// depending on whether certain combos on Layer 0
// are unwalkable. As input, this FFC takes eight
// integers which represent four (X,Y) pairs that the
// multiblock checks for walkability. When all are
// unwalkable, the combo of this FFC will increase by
// one and a secret noise will chime. When any are
// walkable, they will revert back to their original
// combo and not make a chime. By default, the original
// combo used by this FFC mimics unwalkability.
//
// USE - You can use the multiblock trigger to require
// Link to push up to four blocks into position. For
// less than four, just set all of the inputs to permanently
// unwalkable combos, like a dungeon wall, or set them
// all to the same location. Because this FFC reverts
// when the tiles are not walkable, it can also be used
// to create "pressure-sensitive" triggers that must be
// held down by a block and will deactive when the block
// moves away.
// ===============================================

ffc script multiblock_trigger{

// CONSTANTS - Change to change this FFC's behavior

int walkable = 1; // Whether or not the starting
// combo for this FFC is walkable
// or not. For instance, a closed
// door should start unwalkable.
// 0 = walkable
// 1 = unwalkable

// VARIABLES - Do not change!

int state = 0; // Current state of the FFC.
// 0 = untriggered
// 1 = triggered

void run (int block1_x, int block1_y, int block2_x, int block2_y,
int block3_x, int block3_y,int block4_x, int block4_y){

state = 0;

while(true){

if(state == 0){


// Check to see if all blocks in position
if (!canMove(block1_x, block1_y) &&
!canMove(block2_x, block2_y) &&
!canMove(block3_x, block3_y) &&
!canMove(block4_x, block4_y)){

this->Data = this->Data + 1;
Game->PlaySound(27);
state = 1;
}

// Simulate unwalkability
if(walkable == 1){

if( (Link->InputUp) && (Link->Y < this->Y + 16) &&
(Abs(Link->X - this->X) < 16) &&
(Link->Y > this->Y)){Link->InputUp = false;}

if( (Link->InputDown) && (Link->Y > this->Y - 16) &&
(Abs(Link->X - this->X) < 16) &&
(Link->Y < this->Y)){Link->InputDown = false;}


if( (Link->InputLeft) && (Link->X < this->X + 16) &&
(Abs(Link->Y - this->Y) < 16) &&
(Link->X > this->X)){Link->InputLeft = false;}

if( (Link->InputRight) && (Link->X > this->X - 16) &&
(Abs(Link->Y - this->Y) < 16) &&
(Link->X < this->X)){Link->InputRight = false;}
}

} // end of state 0

if (state == 1){

// Check to see if a block has moved
if (canMove(block1_x, block1_y) ||
canMove(block2_x, block2_y) ||
canMove(block3_x, block3_y) ||
canMove(block4_x, block4_y)){

this->Data = this->Data - 1;
state = 0;
}

} // end of state 1

Waitframe();

} // end of while loop

} // end of void run

// Collision Detection Function (Thanks Saffith!)
bool canMove(int x, int y)
{
if(x<0 || x>240 || y<0 || y>160)
return false;

return Screen->ComboS[y+(x>>4)]==0;
}

} // end of ffc script

_L_
10-31-2006, 07:18 AM
This doesn't seem to do anything that can't already be done using the current secret tile system. See room [9,33] in NeoFirst for an example that not only uses four blocks, but also requires that they be pushed in a certain order.

C-Dawg
10-31-2006, 09:15 AM
This doesn't seem to do anything that can't already be done using the current secret tile system. See room [9,33] in NeoFirst for an example that not only uses four blocks, but also requires that they be pushed in a certain order.

The script is more versitile than tiered secrets. Using the script, you don't have to require that the player push the blocks in a particular order, you can allow the player to push blocks over triggers to reach other triggers (ala soboken puzzles) and the door opens only as long as all blocks are in position.

Unless I'm missing something about singular flags and their uses, this script is necessary to create certain kinds of block puzzles.

_L_
10-31-2006, 10:47 AM
Very well then. I suppose I'll endorse it. (Though I'm not entirely unsure that unordered four-block gates are possible with secrets.)

C-Dawg
10-31-2006, 11:56 AM
Additionally, L, once they get multiple FFC + scripts working together instead of going apeshit, you can set different blocks to different doors. For instance, you push the block onto the blue trigger, the blue blocks go down. On the red trigger, red blocks go down. I can imagine puzzles having to do with switching the block back and forth like this, or getting two blocks so they can both get down. Ya dig?

Saffith
11-01-2006, 05:21 PM
Something I just realized: the canMove function is a bit out of date. It would be more versatile like this:

bool canMove(int x, int y)
{
if(x<0 || x>240 || y<0 || y>160)
return false;

return Screen->ComboS[ComboAt(x, y)]==0;
}
You'd have to import std.zh, but it should fix the problem of having to specify the top-left corner.


Nice work, by the way. Should be quite useful.