Advertisement
Guest User

Untitled

a guest
Jul 21st, 2017
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.22 KB | None | 0 0
  1.  
  2. //Button script
  3. //This will allow you to make a sequential button pressing puzzle!
  4. //Each button will need to be an FFC you place on the screen.
  5. //Set the combo of each button FFC as the combo you'd like it to be
  6. //when the button isn't pressed.
  7. //The next in the combo list should be a combo for the button when
  8. //is pressed down
  9. //D0-7 are the FFC numbers of the other buttons, in the order you'd
  10. //like them to be pressed
  11.  
  12. ffc script buttonOrder{
  13. void run(int b1, int b2, int b3, int b4,int b5, int b6, int b7, int b8){
  14. //These values can be modified to fit your needs
  15. //Sound used for the button being pressed
  16. int BUTTON_CLICK = 6;
  17. //Sound used to indicate that the button pressed was wrong
  18. int BUTTON_WRONG = 18;
  19.  
  20. ffc buttons[7];
  21. int upCombo[7];
  22. int totalButtons;
  23. int pressedButtons;
  24. bool buttonResetSound;
  25. bool buttonPressSound;
  26. bool doNotPlaySound;
  27.  
  28. //Used for ffc->Misc[] to indicate if a button has been pressed
  29. int BUTTON_PRESSED = 0;
  30. int UP_COMBO = 1;
  31. int LINK_ON_BUTTON = 2;
  32.  
  33. //Load the FFCs into an array
  34. for(int i; i < 8; i++){
  35. if(this->InitD[i] != -1){
  36. //If it's not -1, load it up
  37. //We also want to store it's original combo
  38. buttons[i] = Screen->LoadFFC(this->InitD[i]);
  39. buttons[i]->Misc[UP_COMBO] = buttons[i]->Data;
  40. }
  41. else{
  42. //If it isn't we end the loop
  43. totalButtons = i;
  44. break;
  45. }
  46. }
  47.  
  48. while(true){
  49. //Scan through the FFCs loaded and see if Link is on any of them
  50. for(int i; i <= totalButtons; i++){
  51. if(Abs(Link->X - buttons[i]->X) <= 8 && Abs(Link->Y - buttons[i]->Y) <= 8){
  52.  
  53. //Check to see if Link was on the button last frame
  54. //If he wasn't, play a sound
  55. if(buttons[i]->Misc[LINK_ON_BUTTON] == 0){
  56. buttons[i]->Misc[LINK_ON_BUTTON] = 1;
  57. if(buttons[i]->Misc[BUTTON_PRESSED] == 0) buttonPressSound = true;
  58. }
  59.  
  60. //Check to see if this is the first button.
  61. //If it is, we can safely press it
  62. if(i == 0) buttons[i]->Misc[BUTTON_PRESSED] = 1;
  63. //If it isn't, see if the previous one has been pressed.
  64. else if(buttons[i-1]->Misc[BUTTON_PRESSED] == 1) buttons[i]->Misc[BUTTON_PRESSED] = 1;
  65. //This is the wrong button in the order
  66. else{
  67. //Reset everything
  68. for(int j; j <= totalButtons; j++){
  69. buttons[j]->Misc[BUTTON_PRESSED] = 0;
  70. }
  71. buttonResetSound = true;
  72. }
  73. }
  74. //He wasn't on the button, so change the misc value
  75. else buttons[i]->Misc[LINK_ON_BUTTON] = 0;
  76.  
  77. //Check to see if this button has been pressed
  78. //If it has, add 1 to the total buttons pressed
  79. if(buttons[i]->Misc[BUTTON_PRESSED] == 1) pressedButtons++;
  80.  
  81. //Before moving on to the next combo, find what the combo of the FFC should be
  82. if(buttons[i]->Misc[BUTTON_PRESSED] == 1) buttons[i]->Data = buttons[i]->Misc[UP_COMBO] + 1;
  83. else buttons[i]->Data = buttons[i]->Misc[UP_COMBO];
  84. }
  85. //If the button had to be reset, we play the sound for it
  86. if(buttonResetSound){
  87. if(!doNotPlaySound)Game->PlaySound(BUTTON_WRONG);
  88. doNotPlaySound = true;
  89. buttonPressSound = false;
  90. }
  91. else doNotPlaySound = false;
  92.  
  93. if(buttonPressSound) Game->PlaySound(BUTTON_CLICK);
  94.  
  95. //If the pressed buttons equal the total, then we can trigger the secrets
  96. if(pressedButtons == totalButtons){
  97. Game->PlaySound(SFX_SECRET);
  98. Screen->TriggerSecrets();
  99. Quit();
  100. }
  101. //Minor clean up
  102. buttonResetSound = false;
  103. buttonPressSound = false;
  104. pressedButtons = 0;
  105. Waitframe();
  106. }
  107. }
  108. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement