Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Button script
- //This will allow you to make a sequential button pressing puzzle!
- //Each button will need to be an FFC you place on the screen.
- //Set the combo of each button FFC as the combo you'd like it to be
- //when the button isn't pressed.
- //The next in the combo list should be a combo for the button when
- //is pressed down
- //D0-7 are the FFC numbers of the other buttons, in the order you'd
- //like them to be pressed
- ffc script buttonOrder{
- void run(int b1, int b2, int b3, int b4,int b5, int b6, int b7, int b8){
- //These values can be modified to fit your needs
- //Sound used for the button being pressed
- int BUTTON_CLICK = 6;
- //Sound used to indicate that the button pressed was wrong
- int BUTTON_WRONG = 18;
- ffc buttons[7];
- int upCombo[7];
- int totalButtons;
- int pressedButtons;
- bool buttonResetSound;
- bool buttonPressSound;
- bool doNotPlaySound;
- //Used for ffc->Misc[] to indicate if a button has been pressed
- int BUTTON_PRESSED = 0;
- int UP_COMBO = 1;
- int LINK_ON_BUTTON = 2;
- //Load the FFCs into an array
- for(int i; i < 8; i++){
- if(this->InitD[i] != -1){
- //If it's not -1, load it up
- //We also want to store it's original combo
- buttons[i] = Screen->LoadFFC(this->InitD[i]);
- buttons[i]->Misc[UP_COMBO] = buttons[i]->Data;
- }
- else{
- //If it isn't we end the loop
- totalButtons = i;
- break;
- }
- }
- while(true){
- //Scan through the FFCs loaded and see if Link is on any of them
- for(int i; i <= totalButtons; i++){
- if(Abs(Link->X - buttons[i]->X) <= 8 && Abs(Link->Y - buttons[i]->Y) <= 8){
- //Check to see if Link was on the button last frame
- //If he wasn't, play a sound
- if(buttons[i]->Misc[LINK_ON_BUTTON] == 0){
- buttons[i]->Misc[LINK_ON_BUTTON] = 1;
- if(buttons[i]->Misc[BUTTON_PRESSED] == 0) buttonPressSound = true;
- }
- //Check to see if this is the first button.
- //If it is, we can safely press it
- if(i == 0) buttons[i]->Misc[BUTTON_PRESSED] = 1;
- //If it isn't, see if the previous one has been pressed.
- else if(buttons[i-1]->Misc[BUTTON_PRESSED] == 1) buttons[i]->Misc[BUTTON_PRESSED] = 1;
- //This is the wrong button in the order
- else{
- //Reset everything
- for(int j; j <= totalButtons; j++){
- buttons[j]->Misc[BUTTON_PRESSED] = 0;
- }
- buttonResetSound = true;
- }
- }
- //He wasn't on the button, so change the misc value
- else buttons[i]->Misc[LINK_ON_BUTTON] = 0;
- //Check to see if this button has been pressed
- //If it has, add 1 to the total buttons pressed
- if(buttons[i]->Misc[BUTTON_PRESSED] == 1) pressedButtons++;
- //Before moving on to the next combo, find what the combo of the FFC should be
- if(buttons[i]->Misc[BUTTON_PRESSED] == 1) buttons[i]->Data = buttons[i]->Misc[UP_COMBO] + 1;
- else buttons[i]->Data = buttons[i]->Misc[UP_COMBO];
- }
- //If the button had to be reset, we play the sound for it
- if(buttonResetSound){
- if(!doNotPlaySound)Game->PlaySound(BUTTON_WRONG);
- doNotPlaySound = true;
- buttonPressSound = false;
- }
- else doNotPlaySound = false;
- if(buttonPressSound) Game->PlaySound(BUTTON_CLICK);
- //If the pressed buttons equal the total, then we can trigger the secrets
- if(pressedButtons == totalButtons){
- Game->PlaySound(SFX_SECRET);
- Screen->TriggerSecrets();
- Quit();
- }
- //Minor clean up
- buttonResetSound = false;
- buttonPressSound = false;
- pressedButtons = 0;
- Waitframe();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement