Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const int CMB_FFC_INVIS = 1; //Combo higher than ID 0 with an invisible tile.
- // ID's of barrier-related combos
- // Barriers in raised state
- const int BARRIER_A_RAISED = 15036;
- const int BARRIER_B_RAISED = 15038;
- // Barriers in lowered state
- const int BARRIER_A_LOWERED = 15037;
- const int BARRIER_B_LOWERED = 15039;
- // Barriers animating to raised state
- const int BARRIER_A_ANIMRAISE = 15041;
- const int BARRIER_B_ANIMRAISE = 15043;
- // Barriers animating to lowered state
- const int BARRIER_A_ANIMLOWER = 15040;
- const int BARRIER_B_ANIMLOWER = 15042;
- // Raised barriers that Link can walk on
- const int BARRIER_A_WALKABLE = 15044;
- const int BARRIER_B_WALKABLE = 15045;
- // Barrier switches
- const int BARRIER_A_SWITCH = 15046;
- const int BARRIER_B_SWITCH = 15047;
- const int BARRIER_SWITCH_DUMMY = 191; // ID of a switch hit detection dummy enemy
- const int BARRIER_SWITCH_DUMMY_HP = 32767;
- // Global array to store the state of barriers per dmap
- // If you have more than 16 dmaps you can change the capacity in the []'s
- // You may change the states in other scripts, but the changes will not be visible
- // until there is a new screen, so set them before Barriers_NewScreen() is called.
- bool barriers[255]; // false = blue barriers raised, true = red barriers raised
- const int ffcNumber = 32; //The number of the FFC used. This script will "hijack" this one, so don't use it for anything else on screens when you expect the player to have a follower.
- const int firstFollowerCombo = 23568; //combo of the first combo. In order, the concecutive combos must be "still up", "still down", "still left", "still right", "moving up", "moving down", "moving left", "moving right".
- const int csetOfFollower = 11;
- const int reqItem = 158; //Item that makes the FFC follower follow you
- const int BAR_PASTX = 14;
- const int BAR_PASTY = 14;
- global script slot2 {
- void run() {
- // Initialize variables used to listen on screen changes
- int curscreen = -1;
- bool firstCheck = false; //leave this alone
- ffc follower;
- int followerX[15];
- int followerY[15];
- int switch_index;
- while (true) {
- // Keep track of screen changes
- // Run a Barrier script on every screen change
- if (Game->GetCurScreen() != curscreen) {
- curscreen = Game->GetCurScreen();
- Barriers_NewScreen();}
- if(Link->Item[reqItem] == true){
- if(Link->Action != LA_SCROLLING && follower->Data==0){
- follower = Screen->LoadFFC(ffcNumber);
- follower->Data = firstFollowerCombo;
- follower->CSet = csetOfFollower;
- followerX[BAR_PASTX] = Link->X;
- follower->X = Link->X;
- followerY[BAR_PASTY] = Link->Y;
- follower->Y = Link->Y;
- for ( int i = 0; i < 13; i++ ){
- followerX[i] = Link->X;
- followerY[i] = Link->Y;
- }
- firstCheck = true;
- }
- if(Link->Action != LA_SCROLLING){
- if((Link->InputUp || Link->InputDown || Link->InputRight || Link->InputLeft)&&(!(Link->InputA || Link->InputB))){
- followerX[BAR_PASTX] = follower->X;
- follower->X = followerX[0];
- for(switch_index=0; switch_index<12; switch_index++){
- followerX[switch_index] = followerX[switch_index + 1];
- }
- followerX[12] = Link->X;
- followerY[BAR_PASTY] = follower->Y;
- follower->Y = followerY[0];
- for(switch_index=0; switch_index<12; switch_index++){
- followerY[switch_index] = followerY[switch_index + 1];
- }
- followerY[12] = Link->Y;
- }
- if(follower->Y > followerY[BAR_PASTY]){
- follower->Data = firstFollowerCombo + 5;
- }
- else if(follower->Y < followerY[BAR_PASTY]){
- follower->Data = firstFollowerCombo + 4;
- }
- else if(follower->X > followerX[BAR_PASTX]){
- follower->Data = firstFollowerCombo + 7;
- }
- else if(follower->X < followerX[BAR_PASTX]){
- follower->Data = firstFollowerCombo + 6;
- }
- if(!(Link->InputUp || Link->InputDown || Link->InputRight || Link->InputLeft)){
- if((follower->Data == (firstFollowerCombo + 4))||(follower->Data == (firstFollowerCombo + 5))||(follower->Data == (firstFollowerCombo + 6))||(follower->Data == (firstFollowerCombo + 7))){
- follower->Data = follower->Data - 4;
- }
- else if((follower->Data == (firstFollowerCombo + 3))||(follower->Data == (firstFollowerCombo + 2))||(follower->Data == (firstFollowerCombo + 1))||(follower->Data == (firstFollowerCombo))){
- }
- else{
- follower->Data = firstFollowerCombo;
- }
- }
- }
- if(Link->Action == LA_SCROLLING){
- firstCheck = false;
- }}
- Waitframe();}}}
- // Function that makes preparations for barriers on each screen and starts an FFC script
- void Barriers_NewScreen() {
- // Search for a barrier-related combo
- for (int i = 0; i <= 175; i++) {
- int cd = Screen->ComboD[i];
- if (cd == BARRIER_A_RAISED || cd == BARRIER_A_LOWERED || cd == BARRIER_A_SWITCH ||
- cd == BARRIER_B_RAISED || cd == BARRIER_B_LOWERED || cd == BARRIER_B_SWITCH) {
- // A barrier-related combo was found
- // Make initial changes to combos
- if (barriers[Game->GetCurLevel()]) {
- for (int j = i; j <= 175; j++) {
- int cd = Screen->ComboD[j];
- if (cd == BARRIER_A_RAISED) Screen->ComboD[j] = BARRIER_A_LOWERED;
- else if (cd == BARRIER_B_LOWERED) Screen->ComboD[j] = BARRIER_B_RAISED;
- else if (cd == BARRIER_A_SWITCH) Screen->ComboD[j] = BARRIER_B_SWITCH;}}
- else {
- for (int j = i; j <= 175; j++) {
- int cd = Screen->ComboD[j];
- if (cd == BARRIER_B_RAISED) Screen->ComboD[j] = BARRIER_B_LOWERED;
- else if (cd == BARRIER_A_LOWERED) Screen->ComboD[j] = BARRIER_A_RAISED;
- else if (cd == BARRIER_B_SWITCH) Screen->ComboD[j] = BARRIER_A_SWITCH;}}
- // So run FFCscript to control barriers
- int fif[]="Barriers";
- ffc f = Screen->LoadFFC(ffcNumber);
- f->Script = Game->GetFFCScript(fif);
- f->Data = CMB_FFC_INVIS;
- f->X = -100;
- f->Y = -100;
- f->Flags[FFCF_PRELOAD] = true;
- break;}
- }}
- // This lets you toggle barriers on any dmap
- bool ToggleBarriers(int dmap) {
- if (dmap == Game->GetCurLevel()) ToggleBarriers();
- else barriers[dmap] = !barriers[dmap];
- return barriers[dmap];}
- // This toggles barriers on the current dmap
- bool ToggleBarriers() {
- int curdmap = Game->GetCurLevel();
- if (!barriers[curdmap]) {
- barriers[curdmap] = true;
- for (int i = 0; i <= 175; i++) {
- int cd = Screen->ComboD[i];
- if (cd == BARRIER_A_RAISED || cd == BARRIER_A_WALKABLE || cd == BARRIER_A_ANIMRAISE) {
- Screen->ComboD[i] = BARRIER_A_ANIMLOWER;}
- else if (cd == BARRIER_B_LOWERED || cd == BARRIER_B_ANIMLOWER) {
- Screen->ComboD[i] = BARRIER_B_ANIMRAISE;}
- else if (cd == BARRIER_A_SWITCH) {Screen->ComboD[i] = BARRIER_B_SWITCH;}}}
- else {
- barriers[curdmap] = false;
- for (int i = 0; i <= 175; i++) {
- int cd = Screen->ComboD[i];
- if (cd == BARRIER_B_RAISED || cd == BARRIER_B_WALKABLE || cd == BARRIER_B_ANIMRAISE) {
- Screen->ComboD[i] = BARRIER_B_ANIMLOWER;}
- else if (cd == BARRIER_A_LOWERED || cd == BARRIER_A_ANIMLOWER) {
- Screen->ComboD[i] = BARRIER_A_ANIMRAISE;}
- else if (cd == BARRIER_B_SWITCH) {Screen->ComboD[i] = BARRIER_A_SWITCH;}}}
- return barriers[curdmap];
- }
- // This script controls barriers on the screen
- // The FFC is automatically created by Barriers_NewScreen()
- ffc script Barriers {
- void run() {
- // Initialize storage for bswitch hit dummies
- int bswitch_count;
- npc bswitch[8];
- for (int i = 0; i <= 175; i++) {
- if (Screen->ComboD[i] == BARRIER_A_SWITCH || Screen->ComboD[i] == BARRIER_B_SWITCH) {
- npc bs = CreateNPCAt(BARRIER_SWITCH_DUMMY, ComboX(i), ComboY(i));
- bs->HitWidth = 8; // Smaller hit box to avoid annoying collisions with Link
- bs->HitHeight = 8;
- bs->HP = BARRIER_SWITCH_DUMMY_HP;
- bswitch[bswitch_count++] = bs;}}
- // Change raised barriers to walkable ones if Link enters screen on a raised barrier
- int lcombo = LinkOnComboD();
- bool onbarrier = (lcombo == BARRIER_A_RAISED || lcombo == BARRIER_B_RAISED);
- if (onbarrier) for (int i = 0; i < 176; i++) {
- if (Screen->ComboD[i] == BARRIER_A_RAISED) {Screen->ComboD[i] = BARRIER_A_WALKABLE;}
- else if (Screen->ComboD[i] == BARRIER_B_RAISED) {Screen->ComboD[i] = BARRIER_B_WALKABLE;}}
- while (true) {
- // Detect hits on bswitches, and change combos accordingly
- for (int j = 0; j < bswitch_count; j++) {
- if (bswitch[j]->HP < BARRIER_SWITCH_DUMMY_HP) {
- bswitch[j]->HP = BARRIER_SWITCH_DUMMY_HP;
- ToggleBarriers();
- break;}} //break so that only one bswitch hit may register per frame
- // Make barriers walkable if Link is on raised barriers, or unwalkable if not
- lcombo = LinkOnComboD();
- if (!onbarrier && (lcombo == BARRIER_A_RAISED || lcombo == BARRIER_B_RAISED)) {
- onbarrier = true;
- for (int i = 0; i <= 175; i++) {
- if (Screen->ComboD[i] == BARRIER_A_RAISED) {Screen->ComboD[i] = BARRIER_A_WALKABLE;}
- else if (Screen->ComboD[i] == BARRIER_B_RAISED) {Screen->ComboD[i] = BARRIER_B_WALKABLE;}}}
- else if (onbarrier && !(lcombo == BARRIER_A_WALKABLE || lcombo == BARRIER_B_WALKABLE)) {
- onbarrier = false;
- for (int i = 0; i <= 175; i++) {
- if (Screen->ComboD[i] == BARRIER_A_WALKABLE) {Screen->ComboD[i] = BARRIER_A_RAISED;}
- else if (Screen->ComboD[i] == BARRIER_B_WALKABLE) {Screen->ComboD[i] = BARRIER_B_RAISED;}}}
- Waitframe();}
- }}
- // A utility function that returns the ID of the combo that Link appears to stand on
- int LinkOnComboD() {
- return Screen->ComboD[ComboAt(Link->X+8, Link->Y+13)];
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement