Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ffc script colorkeyblock3{
- void run(int keyID, int dscreen, int pickupid, int pickupcolor){
- //Place this script on a colored key lock, with keyID set to the corresponding key item from the constants above
- //Also place it on any screen with colored key blocks that respond to these keys,
- //and put flags from the constants above based on their color on both the locks and the blocks.
- //Locks, key blocks, and their flags must all go on layer 2.
- //Finally, place a script on any entrance/exit/continue points within the dmap to safeguard against some fringe cases that could cause bugs.
- //The dscreen argument can usually be left blank; it's the screen whose Screen->D[] registers are used to record the information
- //If you are using Screen->D[] on screen 0x00 of your DMap, set it to a screen not in use.
- //pickupid and pickupcolor can usually be left blank, but allow you to use alternate key items in place of those from the constants.
- //Instructions for how to use these can be found below.
- int keyscollected = Game->GetScreenD(dscreen, 0);
- int locksopen = Game->GetScreenD(dscreen, 1);
- int presscounter = 0;
- int redkeybin = 0001b;
- int bluekeybin = 0010b;
- int yellowkeybin = 0100b;
- int greenkeybin = 1000b;
- bool thislockopened;
- UpdateKeyBlocks(dscreen);
- if(keyID == ITM_REDKEY && locksopen&redkeybin
- || keyID == ITM_BLUEKEY && locksopen&bluekeybin
- || keyID == ITM_YELLOWKEY && locksopen&yellowkeybin
- || keyID == ITM_GREENKEY && locksopen&greenkeybin)
- thislockopened = true;
- while(true){
- if(Link->Item[pickupid] && pickupid != 0 && pickupcolor != 0){ //pickup id is a "key" item, and pickupcolor is the lock color it responds to
- if(pickupcolor == ITM_REDKEY) //if you want different colors or appearances to your keys and locks
- Link->Item[ITM_REDKEY] = true; //Such as purple keys, orbs and pedestals, or whatever.
- if(pickupcolor == ITM_BLUEKEY) //These arguments "convert" whatever item to a colored key
- Link->Item[ITM_BLUEKEY] = true;
- if(pickupcolor == ITM_YELLOWKEY)
- Link->Item[ITM_YELLOWKEY] = true;
- if(pickupcolor == ITM_GREENKEY)
- Link->Item[ITM_GREENKEY] = true;
- Link->Item[pickupid] = false;
- }
- if(Link->Item[ITM_REDKEY] && !(keyscollected&redkeybin)){ //When the proper key is collected, remove from inventory and trip the binary flag
- keyscollected += redkeybin;
- Link->Item[ITM_REDKEY] = false;
- }
- if(Link->Item[ITM_BLUEKEY] && !(keyscollected&bluekeybin)){
- keyscollected += bluekeybin;
- Link->Item[ITM_BLUEKEY] = false;
- }
- if(Link->Item[ITM_YELLOWKEY] && !(keyscollected&yellowkeybin)){
- keyscollected += yellowkeybin;
- Link->Item[ITM_YELLOWKEY] = false;
- }
- if(Link->Item[ITM_GREENKEY] && !(keyscollected&greenkeybin)){
- keyscollected += greenkeybin;
- Link->Item[ITM_GREENKEY] = false;
- }
- Game->SetScreenD(dscreen,0,keyscollected);
- int angle = WrapDegrees(Angle(Link->X+8, Link->Y+8, this->X+8, this->Y+8));
- if(Distance(Link->X+8, Link->Y+8, this->X+8, this->Y+8) <= 18 && Link->Dir == AngleDir4(angle) && //Checks for if Link is pressing against a key block
- ((Link->Dir == DIR_UP && Link->InputUp)|| (Link->Dir == DIR_DOWN && Link->InputDown)
- || (Link->Dir == DIR_LEFT && Link->InputLeft)|| (Link->Dir == DIR_RIGHT && Link->InputRight)))
- presscounter++;
- else if(presscounter >0)
- presscounter--;
- if(presscounter >16 && !thislockopened){
- locksopen = Game->GetScreenD(dscreen, 1);
- bool haskey;
- if((keyID == ITM_REDKEY && keyscollected&redkeybin)
- || (keyID == ITM_BLUEKEY && keyscollected&bluekeybin)
- || (keyID == ITM_YELLOWKEY && keyscollected&yellowkeybin)
- || (keyID == ITM_GREENKEY && keyscollected&greenkeybin))
- haskey = true;
- if(haskey){ //Sets the lock state to open, then calls the update function to open the lock
- if(keyID == ITM_REDKEY)
- locksopen += redkeybin;
- if(keyID == ITM_BLUEKEY)
- locksopen += bluekeybin;
- if(keyID == ITM_YELLOWKEY)
- locksopen += yellowkeybin;
- if(keyID == ITM_GREENKEY)
- locksopen += greenkeybin;
- Game->SetScreenD(dscreen,1,locksopen);
- UpdateKeyBlocks(dscreen);
- Game->PlaySound(9);
- thislockopened = true;
- }
- }
- Waitframe();
- }
- }
- void UpdateKeyBlocks(int dscreen){ //Replaces combos with their "opened" versions based on the states of the locks.
- int redkeybin = 0001b;
- int bluekeybin = 0010b;
- int yellowkeybin = 0100b;
- int greenkeybin = 1000b;
- int locksopen = Game->GetScreenD(dscreen, 1);
- for(int i = 0; i <176; i++){
- if(GetLayerComboD(2,i) != CT_SCRIPT1){
- if((GetLayerComboF(2,i) == FLG_REDKEYBLOCK || GetLayerComboI(2,i) == FLG_REDKEYBLOCK) && locksopen&redkeybin){
- SetLayerComboD(2,i,GetLayerComboD(2,i)+1);
- SetLayerComboF(2,i,0);
- }
- if((GetLayerComboF(2,i) == FLG_BLUEKEYBLOCK || GetLayerComboI(2,i) == FLG_BLUEKEYBLOCK) && locksopen&bluekeybin){
- SetLayerComboD(2,i,GetLayerComboD(2,i)+1);
- SetLayerComboF(2,i,0);
- }
- if((GetLayerComboF(2,i) == FLG_YELLOWKEYBLOCK || GetLayerComboI(2,i) == FLG_YELLOWKEYBLOCK) && locksopen&yellowkeybin){
- SetLayerComboD(2,i,GetLayerComboD(2,i)+1);
- SetLayerComboF(2,i,0);
- }
- if((GetLayerComboF(2,i) == FLG_GREENKEYBLOCK || GetLayerComboI(2,i) == FLG_GREENKEYBLOCK) && locksopen&greenkeybin){
- SetLayerComboD(2,i,GetLayerComboD(2,i)+1);
- SetLayerComboF(2,i,0);
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement