Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Deku Stick Script
- #option SHORT_CIRCUIT on
- #option BINARY_32BIT off
- typedef const int DEFINE; //Don't change DEFINE constants
- typedef const int CONFIG; //Change CONFIG constants however you like
- typedef const bool CONFIGB; //CONFIGB are only true/false
- CONFIG LW_DEKUSTICK = LW_SCRIPT1;
- CONFIG CT_TORCH_UNLIT = CT_SCRIPT1;
- CONFIG CT_TORCH_LIT = CT_SCRIPT2;
- CONFIG DEFAULT_LIT_SECONDS = 20;
- CONFIG DEFAULT_TORCH_LIGHT_SFX = 0; //Default SFX if the unlit torch combo has none specified
- CONFIG MIN_STAB_FRAMES = 10; //A stab will last at least this many frames
- CONFIG TORCH_MAX_LAYER = 2;
- CONFIG ENERGYBAR_WIDTH = 30; //1px border added to both sides
- CONFIG ENERGYBAR_HEIGHT = 6; //1px border added to both sides
- CONFIGB ENERGYBAR_RELATIVE_TO_PLAYER = true;
- CONFIG ENERGYBAR_X = -8; //If 'ENERGYBAR_RELATIVE_TO_PLAYER', this is an offset; otherwise it's absolute
- CONFIG ENERGYBAR_Y = -8; //If 'ENERGYBAR_RELATIVE_TO_PLAYER', this is an offset; otherwise it's absolute
- CONFIG ENERGYBAR_LAYER = 7;
- CONFIGB ENERGYBAR_ONLY_WHEN_DEKUSTICK_EQUIPPED = false; //Only show while stick is on A or B
- CONFIG COLOR_ENERGYBAR_BORDER = 0x01;
- CONFIG COLOR_ENERGYBAR_FILLED = 0x05;
- CONFIG COLOR_ENERGYBAR_EMPTY = 0x0F;
- untyped torch_data[TD_SZ];
- enum
- {
- TD_TIMER, //Current timer for the torch
- TD_MAX_TIMER, //Last amount the torch was lit for, for drawing the bar
- TD_SCRIPTSLOT, //Script slot, stored in buffer
- TD_WEAPSCRIPTSLOT, //Script slot, stored in buffer
- TD_SZ
- };
- /** start Combo setup instructions
- * Torch Combos (Lit):
- * Type: CT_TORCH_LIT
- * Attribyte 1: Seconds for stick to be lit by torch. 0 to use default.
- *
- * Torch Combos (Unlit):
- * Type: CT_TORCH_UNLIT
- * Attribyte 1: SFX for lighting
- * The next combo in the combo list should be the lit combo
- */
- //end Combo setup instructions
- /**
- * Sprite: 'Sprites[0]'
- * Up-facing, then right-facing. Will be flipped.
- * On fire tiles exactly one row below the normal tiles.
- * Damage, and default weapon defense, are set in the editor.
- */
- itemdata script DekuStick //start
- {
- void run(int light_sfx) //start
- {
- int btn = (this->ID == GetEquipmentA()) ? CB_A : CB_B;
- int cntr = 0;
- bool held = true;
- int dir = Hero->Dir;
- bool lit = torch_data[TD_TIMER] > 0;
- lweapon weap = CreateDekuStick(this, dir, lit);
- Hero->Action = LA_ATTACKING;
- Waitdraw();
- while(true)
- {
- if(weap->isValid())
- {
- weap->X = Hero->X;
- weap->Y = Hero->Y;
- checkTorchCombos(weap);
- if(lit ^^ torch_data[TD_TIMER] > 0)
- {
- lit = torch_data[TD_TIMER] > 0;
- if(lit) Audio->PlaySound(light_sfx);
- weap->OriginalTile += (lit ? 20 : -20);
- weap->Tile = weap->OriginalTile;
- }
- }
- stopQuickSwap();
- Hero->Dir = dir;
- Waitframe();
- held = held && Input->Button[btn];
- unless(++cntr < MIN_STAB_FRAMES || held)
- {
- weap->Misc[0] = 0;
- Remove(weap);
- return;
- }
- unless(weap->isValid())
- {
- weap = CreateDekuStick(this, dir, lit);
- }
- else if(weap->DeadState == WDS_DEAD)
- {
- weap->Misc[0] = 0;
- Remove(weap);
- weap = CreateDekuStick(this, dir, lit);
- }
- Waitdraw();
- }
- } //end
- void checkTorchCombos(lweapon weap) //start
- {
- int x = weap->X + weap->HitXOffset;
- int y = weap->Y + weap->HitYOffset;
- int combos[4] = {ComboAt(x, y), ComboAt(x + 15, y),
- ComboAt(x, y + 15), ComboAt(x + 15, y + 15)};
- if(x < 0 || x > 255)
- {
- combos[0] = -1;
- combos[2] = -1;
- }
- if(x+15 < 0 || x+15 > 255)
- {
- combos[1] = -1;
- combos[3] = -1;
- }
- if(y < 0 || y > 175)
- {
- combos[0] = -1;
- combos[1] = -1;
- }
- if(y+15 < 0 || y+15 > 175)
- {
- combos[2] = -1;
- combos[3] = -1;
- }
- for(int lyr = 0; lyr <= (TORCH_MAX_LAYER <= 6 ? TORCH_MAX_LAYER : 6); ++lyr)
- {
- mapdata md = Game->LoadTempScreen(lyr);
- for(int q = 0; q < 4; ++q)
- {
- if(combos[q] < 0) continue;
- combodata cd = Game->LoadComboData(md->ComboD[combos[q]]);
- switch(cd->Type)
- {
- case CT_TORCH_LIT:
- {
- int dur = cd->Attribytes[0];
- unless(dur) dur = DEFAULT_LIT_SECONDS;
- dur *= 60;
- if(torch_data[TD_TIMER] < dur)
- {
- torch_data[TD_TIMER] = dur;
- torch_data[TD_MAX_TIMER] = dur;
- }
- break;
- }
- case CT_TORCH_UNLIT:
- {
- if(torch_data[TD_TIMER])
- {
- ++md->ComboD[combos[q]];
- Audio->PlaySound(cd->Attribytes[0] ? cd->Attribytes[0] : DEFAULT_TORCH_LIGHT_SFX);
- }
- break;
- }
- }
- }
- }
- } //end
- void stopQuickSwap() //start
- {
- unless(Game->FFRules[qr_NO_L_R_BUTTON_INVENTORY_SWAP])
- {
- Input->Press[CB_L] = false;
- Input->Button[CB_L] = false;
- Input->Press[CB_R] = false;
- Input->Button[CB_R] = false;
- }
- if(Game->FFRules[qr_USE_EX1_EX2_INVENTORYSWAP])
- {
- Input->Press[CB_EX1] = false;
- Input->Button[CB_EX1] = false;
- Input->Press[CB_EX2] = false;
- Input->Button[CB_EX2] = false;
- }
- } //end
- int WeapX(int dir)
- {
- switch(dir)
- {
- case DIR_UP: return -1;
- case DIR_DOWN: return 1;
- case DIR_LEFT: return -9;
- default: case DIR_RIGHT: return 9;
- }
- }
- int WeapY(int dir)
- {
- switch(dir)
- {
- case DIR_UP: return -6;
- case DIR_DOWN: return 11;
- case DIR_LEFT: return 3;
- default: case DIR_RIGHT: return 3;
- }
- }
- lweapon CreateDekuStick(itemdata id, int dir, bool lit)
- {
- lweapon weap = Screen->CreateLWeapon(LW_DEKUSTICK);
- weap->UseSprite(id->Sprites[0]);
- weap->Dir = Hero->Dir;
- weap->Defense = id->Defense;
- weap->Damage = id->Power * 2;
- unless(weap->NumFrames) weap->NumFrames = 1;
- weap->DrawXOffset = WeapX(dir);
- weap->DrawYOffset = WeapY(dir);
- weap->HitXOffset = weap->DrawXOffset;
- weap->HitYOffset = weap->DrawYOffset;
- switch(dir)
- {
- case DIR_DOWN: weap->Flip = FLIP_VERTICAL; break;
- case DIR_LEFT: weap->Flip = FLIP_HORIZONTAL; //Fallthrough
- case DIR_RIGHT: weap->OriginalTile += weap->NumFrames; break;
- }
- if(lit) weap->OriginalTile += 20;
- weap->Tile = weap->OriginalTile;
- weap->X = Hero->X;
- weap->Y = Hero->Y;
- weap->Script = torch_data[TD_WEAPSCRIPTSLOT];
- return weap;
- }
- } //end DekuStick
- lweapon script undying_lw
- {
- void run()
- {
- this->Misc[0] = 1;
- while(this->Misc[0])
- {
- this->DeadState = WDS_ALIVE;
- Waitframe();
- }
- }
- }
- void DekuStick_Init()
- {
- torch_data[TD_TIMER] = 0;
- torch_data[TD_MAX_TIMER] = 0;
- torch_data[TD_SCRIPTSLOT] = Game->GetItemScript("DekuStick");
- torch_data[TD_WEAPSCRIPTSLOT] = Game->GetLWeaponScript("undying_lw");
- }
- void DekuStick_Update()
- {
- if(torch_data[TD_TIMER] > 0)
- {
- --torch_data[TD_TIMER];
- if(ENERGYBAR_ONLY_WHEN_DEKUSTICK_EQUIPPED)
- {
- itemdata a = Game->LoadItemData(GetEquipmentA());
- itemdata b = Game->LoadItemData(GetEquipmentB());
- unless(a->Script == torch_data[TD_SCRIPTSLOT] || b->Script == torch_data[TD_SCRIPTSLOT]) return;
- }
- int x = (ENERGYBAR_RELATIVE_TO_PLAYER ? Hero->X + Game->Scrolling[SCROLL_NX] : 0) + ENERGYBAR_X;
- int y = (ENERGYBAR_RELATIVE_TO_PLAYER ? Hero->Y + Game->Scrolling[SCROLL_NY] : 0) + ENERGYBAR_Y;
- float perc = torch_data[TD_TIMER] / torch_data[TD_MAX_TIMER];
- int litwid = Ceiling(ENERGYBAR_WIDTH * perc);
- Screen->Rectangle(ENERGYBAR_LAYER, x, y, x+ENERGYBAR_WIDTH+1, y+ENERGYBAR_HEIGHT+1, COLOR_ENERGYBAR_BORDER, 1, 0, 0, 0, true, OP_OPAQUE);
- Screen->Rectangle(ENERGYBAR_LAYER, x+1, y+1, x+ENERGYBAR_WIDTH, y+ENERGYBAR_HEIGHT, COLOR_ENERGYBAR_EMPTY, 1, 0, 0, 0, true, OP_OPAQUE);
- Screen->Rectangle(ENERGYBAR_LAYER, x+1, y+1, x+litwid, y+ENERGYBAR_HEIGHT, COLOR_ENERGYBAR_FILLED, 1, 0, 0, 0, true, OP_OPAQUE);
- }
- }
- global script ExampleDekuStickActive
- {
- void run()
- {
- DekuStick_Init();
- while(true)
- {
- Waitdraw();
- DekuStick_Update();
- Waitframe();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement