Advertisement
Venrob

TorchPuzzle.zs

Sep 12th, 2020
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.18 KB | None | 0 0
  1. ffc script TorchPuzzle
  2. {
  3. /**
  4. * Args:
  5. * D0: Screen->D[] register to use. Should be a number 0 to 7.
  6. * D1: Unlit torch combo. The 'next' combo should be the lit torch combo.
  7. * D2: Error SFX for when wrong answer is put in.
  8. * D3: If set to 0, the puzzle remains solved forever. Otherwise, the puzzle resets when you leave the room.
  9. * D4 - D7: Positions of correct torches. These 4 combo positions (0-175) must all be lit, in order.
  10. * Make sure `Run Script at Screen Init` is checked on the FFC.
  11. */
  12. void run(int reg, int unlitCombo, int error_sfx, bool temp, int pos1, int pos2, int pos3, int pos4)
  13. {
  14. int litCombo = unlitCombo+1;
  15. if(Screen->D[reg] & 1b) //start Already solved
  16. {
  17. for(int q = 0; q < 176; ++q) //Light all torches onscreen
  18. {
  19. if(Screen->ComboD[q] == unlitCombo)
  20. Screen->ComboD[q] = litCombo;
  21. }
  22. return; //exit script
  23. } //end Already solved
  24. int trchs[176];
  25. int num_trchs = 0;
  26. //start find torches
  27. {
  28. for(int q = 0; q < 176; ++q)
  29. {
  30. if(Screen->ComboD[q] == unlitCombo)
  31. trchs[num_trchs++] = q;
  32. }
  33. } //end
  34. int cur_trchs[4];
  35. int cur_lit = 0;
  36. while(true)
  37. {
  38. for(int q = Screen->NumLWeapons(); q > 0; --q)
  39. {
  40. lweapon weap = Screen->LoadLWeapon(q);
  41. if(weap->Type != LW_FIRE) continue;
  42. for(int t = 0; t < num_trchs; ++t) //start check torch collision
  43. {
  44. int loc = trchs[t];
  45. for(int p = 0; p < cur_lit; ++p)
  46. {
  47. if(loc == cur_trchs[p])
  48. {
  49. loc = -1;
  50. break;
  51. }
  52. }
  53. if(loc < 0) continue;
  54. if(RectCollision(ComboX(loc), ComboY(loc), ComboX(loc)+15, ComboY(loc)+15,
  55. weap->X + weap->HitXOffset, weap->Y + weap->HitYOffset,
  56. weap->X+weap->HitXOffset+weap->HitWidth-1, weap->Y+weap->HitYOffset+weap->HitHeight-1)
  57. )
  58. {
  59. cur_trchs[cur_lit++] = loc;
  60. Screen->ComboD[loc] = litCombo;
  61. break;
  62. }
  63. } //end check torch collision
  64. if(cur_lit == 4)
  65. break;
  66. }
  67. Waitframe();
  68. if(cur_lit == 4) //start If 4 have been lit
  69. {
  70. //start If they were correct...
  71. if(cur_trchs[0] == pos1 && cur_trchs[1] == pos2 && cur_trchs[2] == pos3 && cur_trchs[3] == pos4)
  72. {
  73. if(!temp)
  74. {
  75. Screen->State[ST_SECRET] = true;
  76. Screen->D[reg] |= 1b;
  77. }
  78. Game->PlaySound(SFX_SECRET);
  79. for(int q = 0; q < num_trchs; ++q) //Light all torches onscreen
  80. {
  81. Screen->ComboD[trchs[q]] = litCombo;
  82. }
  83. Screen->TriggerSecrets();
  84. return; //Quit script
  85. } //end If they were correct...
  86. else //start If they were wrong...
  87. {
  88. Game->PlaySound(error_sfx);
  89. for(int q = 0; q < num_trchs; ++q)
  90. {
  91. Screen->ComboD[trchs[q]] = unlitCombo;
  92. }
  93. for(int q = 0; q < 4; ++q)
  94. {
  95. cur_trchs[q] = 0;
  96. }
  97. cur_lit = 0;
  98. for(int q = Screen->NumLWeapons(); q > 0; --q) //start Delete all fire weapons
  99. {
  100. lweapon weap = Screen->LoadLWeapon(q);
  101. if(weap->Type == LW_FIRE)
  102. {
  103. Remove(weap);
  104. continue;
  105. }
  106. } //end Delete all fire weapons
  107. Waitframe();
  108. } //end If they were wrong...
  109. } //end If 4 have been lit
  110. }
  111. }
  112. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement