Advertisement
Venrob

Gale Boomerang

Jan 13th, 2020
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.81 KB | None | 0 0
  1. #option SHORT_CIRCUIT on
  2. #option HEADER_GUARD on
  3. #option BINARY_32BIT off
  4. #include "std.zh"
  5.  
  6. /**
  7. * Setup:
  8. * REQUIRES: `ZScript>>Quest Script Settings>>Objects` - `Weapons Live One Extra Frame With WDS_DEAD` must be checked.
  9. * InitD[]:
  10. * -d0 = turn rate (degrees per frame)
  11. * -d1 = wind drop rate (every x frames, drop wind visual effect)
  12. * Sprites[]:
  13. * -0 = sprite for the weapon
  14. * -1 = sprite for the wind visual effect
  15. */
  16. lweapon script GaleBRang
  17. {
  18. typedef const int DEFINE;
  19. typedef const int CONFIG;
  20. typedef const bool CONFIGB;
  21. CONFIG CF_BRANG_BOUNCE = CF_SCRIPT20;
  22. CONFIGB BOUNCE_OFF_FLAGS_ON_LAYERS_1_AND_2 = true;
  23. CONFIGB STOPS_WHEN_GRABBING_ITEMS = true;
  24. CONFIG DEFAULT_SPRITE = 5;
  25. CONFIG DEFAULT_WIND_SPRITE = 13;
  26. CONFIG DEFAULT_SFX = 4;
  27. DEFINE ROTATION_RATE = 20; //degrees
  28. CONFIG SFX_DELAY = 5;
  29.  
  30. void run(int turnRate, int wind_drop_rate)
  31. {
  32. itemdata parent;
  33. int wind_sprite;
  34. int wind_clk;
  35. int sfx_clk;
  36. int sfx;
  37. if(this->Parent > -1) //Initialize with data from the item that created this.
  38. {
  39. parent = Game->LoadItemData(this->Parent);
  40. this->UseSprite(parent->Sprites[0]);
  41. wind_sprite = parent->Sprites[1];
  42. sfx = parent->UseSound;
  43. }
  44. else //If this weapon was created by a script, instead of an item, initialize with defaults.
  45. {
  46. parent = NULL;
  47. this->UseSprite(DEFAULT_SPRITE);
  48. wind_sprite = DEFAULT_WIND_SPRITE;
  49. sfx = DEFAULT_SFX;
  50. }
  51. this->Angular = true;
  52. this->Angle = DirRad(this->Dir);
  53. int radTurnRate = DegtoRad(turnRate);
  54. bool controlling = (Input->Button[CB_A] || Input->Button[CB_B]);
  55. itemsprite dragging = NULL;
  56. bool collided = false;
  57. until(this->DeadState == WDS_DEAD || collided)
  58. {
  59. if(dragging)
  60. {
  61. dragging->X = this->X;
  62. dragging->Y = this->Y;
  63. }
  64. if(controlling)
  65. {
  66. if(Input->Button[CB_LEFT])
  67. {
  68. this->Angle -= radTurnRate;
  69. }
  70. else if(Input->Button[CB_RIGHT])
  71. {
  72. this->Angle += radTurnRate;
  73. }
  74. }
  75. int pos = ComboAt(this->X + 8, this->Y + 8);
  76. for(int q = 0; q <= (BOUNCE_OFF_FLAGS_ON_LAYERS_1_AND_2 ? 2 : 0); ++q)
  77. {
  78. mapdata m = Game->LoadTempScreen(q);
  79. if(m->ComboF[pos] == CF_BRANG_BOUNCE || m->ComboI[pos] == CF_BRANG_BOUNCE)
  80. {
  81. collided = true;
  82. }
  83. }
  84. for(int q = Screen->NumItems(); q > 0; --q)
  85. {
  86. itemsprite it = Screen->LoadItem(q);
  87. unless(it->Pickup & IP_TIMEOUT) continue;
  88. if(Collision(it, this))
  89. {
  90. dragging = it;
  91. collided = STOPS_WHEN_GRABBING_ITEMS;
  92. }
  93. }
  94. if(controlling)
  95. ++Hero->Stun;
  96. wind_clk = (wind_clk + 1) % wind_drop_rate;
  97. sfx_clk = (sfx_clk + 1) % SFX_DELAY;
  98. unless(wind_clk) drop_sparkle(this->X, this->Y, wind_sprite);
  99. unless(sfx_clk) Audio->PlaySound(sfx);
  100. this->Rotation = WrapDegrees(this->Rotation + ROTATION_RATE);
  101. Waitframe();
  102. if(controlling) controlling = (Input->Button[CB_A] || Input->Button[CB_B]);
  103. }
  104. while(true)
  105. {
  106. this->DeadState = WDS_ALIVE;
  107. this->Angle = TurnTowards(this->X, this->Y, Hero->X, Hero->Y, this->Angle, 1); //Turn directly towards the Hero.
  108. if(Collision(this)) //touching the Hero
  109. {
  110. this->DeadState = WDS_DEAD;
  111. if(dragging)
  112. {
  113. dragging->X = Hero->X;
  114. dragging->Y = Hero->Y;
  115. }
  116. return;
  117. }
  118. if(dragging)
  119. {
  120. dragging->X = this->X;
  121. dragging->Y = this->Y;
  122. }
  123. wind_clk = (wind_clk + 1) % wind_drop_rate;
  124. sfx_clk = (sfx_clk + 1) % SFX_DELAY;
  125. unless(wind_clk) drop_sparkle(this->X, this->Y, wind_sprite);
  126. unless(sfx_clk) Audio->PlaySound(sfx);
  127. this->Rotation = WrapDegrees(this->Rotation + ROTATION_RATE);
  128. Waitframe();
  129. }
  130. }
  131.  
  132. void drop_sparkle(int x, int y, int sprite)
  133. {
  134. lweapon sparkle = Screen->CreateLWeapon(LW_SPARKLE);
  135. sparkle->X = x;
  136. sparkle->Y = y;
  137. sparkle->UseSprite(sprite);
  138. }
  139. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement