Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2018
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.46 KB | None | 0 0
  1. ffc script colorkeyblock3{
  2. void run(int keyID, int dscreen, int pickupid, int pickupcolor){
  3. //Place this script on a colored key lock, with keyID set to the corresponding key item from the constants above
  4. //Also place it on any screen with colored key blocks that respond to these keys,
  5. //and put flags from the constants above based on their color on both the locks and the blocks.
  6. //Locks, key blocks, and their flags must all go on layer 2.
  7. //Finally, place a script on any entrance/exit/continue points within the dmap to safeguard against some fringe cases that could cause bugs.
  8. //The dscreen argument can usually be left blank; it's the screen whose Screen->D[] registers are used to record the information
  9. //If you are using Screen->D[] on screen 0x00 of your DMap, set it to a screen not in use.
  10. //pickupid and pickupcolor can usually be left blank, but allow you to use alternate key items in place of those from the constants.
  11. //Instructions for how to use these can be found below.
  12.  
  13. int keyscollected = Game->GetScreenD(dscreen, 0);
  14. int locksopen = Game->GetScreenD(dscreen, 1);
  15. int presscounter = 0;
  16. int redkeybin = 0001b;
  17. int bluekeybin = 0010b;
  18. int yellowkeybin = 0100b;
  19. int greenkeybin = 1000b;
  20. bool thislockopened;
  21.  
  22. UpdateKeyBlocks(dscreen);
  23. if(keyID == ITM_REDKEY && locksopen&redkeybin
  24. || keyID == ITM_BLUEKEY && locksopen&bluekeybin
  25. || keyID == ITM_YELLOWKEY && locksopen&yellowkeybin
  26. || keyID == ITM_GREENKEY && locksopen&greenkeybin)
  27. thislockopened = true;
  28. while(true){
  29. if(Link->Item[pickupid] && pickupid != 0 && pickupcolor != 0){ //pickup id is a "key" item, and pickupcolor is the lock color it responds to
  30. if(pickupcolor == ITM_REDKEY) //if you want different colors or appearances to your keys and locks
  31. Link->Item[ITM_REDKEY] = true; //Such as purple keys, orbs and pedestals, or whatever.
  32. if(pickupcolor == ITM_BLUEKEY) //These arguments "convert" whatever item to a colored key
  33. Link->Item[ITM_BLUEKEY] = true;
  34. if(pickupcolor == ITM_YELLOWKEY)
  35. Link->Item[ITM_YELLOWKEY] = true;
  36. if(pickupcolor == ITM_GREENKEY)
  37. Link->Item[ITM_GREENKEY] = true;
  38. Link->Item[pickupid] = false;
  39. }
  40.  
  41. if(Link->Item[ITM_REDKEY] && !(keyscollected&redkeybin)){ //When the proper key is collected, remove from inventory and trip the binary flag
  42. keyscollected += redkeybin;
  43. Link->Item[ITM_REDKEY] = false;
  44. }
  45. if(Link->Item[ITM_BLUEKEY] && !(keyscollected&bluekeybin)){
  46. keyscollected += bluekeybin;
  47. Link->Item[ITM_BLUEKEY] = false;
  48. }
  49. if(Link->Item[ITM_YELLOWKEY] && !(keyscollected&yellowkeybin)){
  50. keyscollected += yellowkeybin;
  51. Link->Item[ITM_YELLOWKEY] = false;
  52. }
  53. if(Link->Item[ITM_GREENKEY] && !(keyscollected&greenkeybin)){
  54. keyscollected += greenkeybin;
  55. Link->Item[ITM_GREENKEY] = false;
  56. }
  57. Game->SetScreenD(dscreen,0,keyscollected);
  58. int angle = WrapDegrees(Angle(Link->X+8, Link->Y+8, this->X+8, this->Y+8));
  59. if(Distance(Link->X+8, Link->Y+8, this->X+8, this->Y+8) <= 18 && Link->Dir == AngleDir4(angle) && //Checks for if Link is pressing against a key block
  60. ((Link->Dir == DIR_UP && Link->InputUp)|| (Link->Dir == DIR_DOWN && Link->InputDown)
  61. || (Link->Dir == DIR_LEFT && Link->InputLeft)|| (Link->Dir == DIR_RIGHT && Link->InputRight)))
  62. presscounter++;
  63. else if(presscounter >0)
  64. presscounter--;
  65. if(presscounter >16 && !thislockopened){
  66. locksopen = Game->GetScreenD(dscreen, 1);
  67. bool haskey;
  68. if((keyID == ITM_REDKEY && keyscollected&redkeybin)
  69. || (keyID == ITM_BLUEKEY && keyscollected&bluekeybin)
  70. || (keyID == ITM_YELLOWKEY && keyscollected&yellowkeybin)
  71. || (keyID == ITM_GREENKEY && keyscollected&greenkeybin))
  72. haskey = true;
  73. if(haskey){ //Sets the lock state to open, then calls the update function to open the lock
  74. if(keyID == ITM_REDKEY)
  75. locksopen += redkeybin;
  76. if(keyID == ITM_BLUEKEY)
  77. locksopen += bluekeybin;
  78. if(keyID == ITM_YELLOWKEY)
  79. locksopen += yellowkeybin;
  80. if(keyID == ITM_GREENKEY)
  81. locksopen += greenkeybin;
  82. Game->SetScreenD(dscreen,1,locksopen);
  83. UpdateKeyBlocks(dscreen);
  84. Game->PlaySound(9);
  85. thislockopened = true;
  86. }
  87. }
  88. Waitframe();
  89. }
  90. }
  91. void UpdateKeyBlocks(int dscreen){ //Replaces combos with their "opened" versions based on the states of the locks.
  92. int redkeybin = 0001b;
  93. int bluekeybin = 0010b;
  94. int yellowkeybin = 0100b;
  95. int greenkeybin = 1000b;
  96. int locksopen = Game->GetScreenD(dscreen, 1);
  97. for(int i = 0; i <176; i++){
  98. if(GetLayerComboD(2,i) != CT_SCRIPT1){
  99. if((GetLayerComboF(2,i) == FLG_REDKEYBLOCK || GetLayerComboI(2,i) == FLG_REDKEYBLOCK) && locksopen&redkeybin){
  100. SetLayerComboD(2,i,GetLayerComboD(2,i)+1);
  101. SetLayerComboF(2,i,0);
  102. }
  103. if((GetLayerComboF(2,i) == FLG_BLUEKEYBLOCK || GetLayerComboI(2,i) == FLG_BLUEKEYBLOCK) && locksopen&bluekeybin){
  104. SetLayerComboD(2,i,GetLayerComboD(2,i)+1);
  105. SetLayerComboF(2,i,0);
  106. }
  107. if((GetLayerComboF(2,i) == FLG_YELLOWKEYBLOCK || GetLayerComboI(2,i) == FLG_YELLOWKEYBLOCK) && locksopen&yellowkeybin){
  108. SetLayerComboD(2,i,GetLayerComboD(2,i)+1);
  109. SetLayerComboF(2,i,0);
  110. }
  111. if((GetLayerComboF(2,i) == FLG_GREENKEYBLOCK || GetLayerComboI(2,i) == FLG_GREENKEYBLOCK) && locksopen&greenkeybin){
  112. SetLayerComboD(2,i,GetLayerComboD(2,i)+1);
  113. SetLayerComboF(2,i,0);
  114. }
  115. }
  116. }
  117. }
  118. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement