Advertisement
DarkSoul144

Minigame Bull's Eye

Jun 1st, 2021
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.92 KB | None | 0 0
  1. #===============================================================================
  2. #
  3. # Shanghai Simple Script - Minigame Bull's Eye
  4. # Last Date Updated: 2021.06.01
  5. # Level: Normal
  6. #
  7. # This is a minigame script. It's easy to play. Press X (Keyboard A) when the cursor is right
  8. # above the bull's eye or within the red region.
  9. #===============================================================================
  10. # Instructions
  11. # -----------------------------------------------------------------------------
  12. # To install this script, open up your script editor and copy/paste this script
  13. # to an open slot below ▼ Materials but above ▼ Main. Remember to save.
  14. #
  15. # Do a script call for
  16. # $game_variables[1] = bulls_eye(x, y)
  17. #
  18. # x is the percentage range allowed for error and y is the cursor speed.
  19. # Works with Battle Engine Melody.
  20. #===============================================================================
  21.  
  22. $imported = {} if $imported == nil
  23. $imported["MinigameBullsEye"] = true
  24.  
  25. module SSS
  26. # This is the filename for the bull's eye mini game spritesheet. Place it
  27. # inside of Graphics\System to work.
  28. BULLS_EYE_SHEET = "MiniGameBullseye"
  29. # These are the sound effects used for the bull's eye mini game.
  30. BULLS_EYE_SHOOT = RPG::SE.new("Bow1", 80, 100)
  31. BULLS_EYE_CLICK = RPG::SE.new("Cursor1", 40, 150)
  32. BULLS_EYE_PERFECT = RPG::SE.new("Chime2", 80, 120)
  33. BULLS_EYE_VERY_CLOSE = RPG::SE.new("Absorb2", 80, 100)
  34. BULLS_EYE_ALMOST = RPG::SE.new("Decision2", 80, 100)
  35. BULLS_EYE_MISSED = RPG::SE.new("Buzzer2", 80, 100)
  36.  
  37. VERY_CLOSE_TEXT = "damage_hp"
  38. VERY_CLOSE_OFFSET = 28
  39.  
  40. module SPRITESET
  41. #--------------------------------------------------------------------------
  42. # * Bulls Eye Game
  43. #--------------------------------------------------------------------------
  44. def bulls_eye_game(percent = 15, speed = 10)
  45. @bulls_eye_percent = percent
  46. @bulls_eye_speed = speed
  47. create_bulls_eye_sprites
  48. end
  49. #--------------------------------------------------------------------------
  50. # * Create Bulls Eye Sprites
  51. #--------------------------------------------------------------------------
  52. def create_bulls_eye_sprites
  53. @bulls_eye_sprite = Sprite_Base.new(@viewport3)
  54. bitmap1 = Bitmap.new(512, 72)
  55. bitmap2 = Cache.system(SSS::BULLS_EYE_SHEET)
  56. # Make the Main Body
  57. rect = Rect.new(0, 0, 512, 24)
  58. bitmap1.blt(0, 24, bitmap2, rect)
  59. # Make the Target Safe Zone
  60. rect = Rect.new(0, 24, 0, 24)
  61. rect.width = @bulls_eye_percent * 512 / 100
  62. rect.x = (512 - rect.width) / 2
  63. bitmap1.blt(rect.x, 24, bitmap2, rect)
  64. # Make the Target Center
  65. rect = Rect.new(488, 48, 24, 24)
  66. bitmap1.blt(244, 24, bitmap2, rect)
  67. # Make the Instructions
  68. rect = Rect.new(312, 48, 176, 24)
  69. bitmap1.blt(168, 48, bitmap2, rect)
  70. # Apply Sprite
  71. @bulls_eye_sprite.bitmap = bitmap1
  72. @bulls_eye_sprite.x = (Graphics.width - 512) / 2
  73. @bulls_eye_sprite.y = Graphics.height - 200
  74. # Arrow Sprite
  75. @arrow_shoot_sprite = Sprite_Base.new(@viewport3)
  76. @arrow_shoot_sprite.bitmap = Bitmap.new(24, 24)
  77. rect = Rect.new(0, 48, 24, 24)
  78. @arrow_shoot_sprite.bitmap.blt(0, 0, bitmap2, rect)
  79. @arrow_shoot_sprite.ox = 12
  80. @arrow_shoot_sprite.oy = 24
  81. @arrow_shoot_sprite.x = @bulls_eye_sprite.x
  82. @arrow_shoot_sprite.y = @bulls_eye_sprite.y + 24
  83. # Make Sounds
  84. @shoot_sound = SSS::BULLS_EYE_SHOOT
  85. @click_sound = SSS::BULLS_EYE_CLICK
  86. @bulls_eye_direction = 0
  87. end
  88. #--------------------------------------------------------------------------
  89. # * Dispose Bulls Eye Sprites
  90. #--------------------------------------------------------------------------
  91. def dispose_bulls_eye_sprites
  92. unless @bulls_eye_sprite.nil?
  93. @bulls_eye_sprite.dispose
  94. @bulls_eye_sprite = nil
  95. end
  96. unless @arrow_shoot_sprite.nil?
  97. @arrow_shoot_sprite.dispose
  98. @arrow_shoot_sprite = nil
  99. end
  100. unless @results_sprite.nil?
  101. @results_sprite.dispose
  102. @results_sprite = nil
  103. end
  104. end
  105. #--------------------------------------------------------------------------
  106. # * Update Bulls Eye Sprites
  107. #--------------------------------------------------------------------------
  108. def update_bulls_eye_sprites
  109. @bulls_eye_sprite.update
  110. if @bulls_eye_direction == 0
  111. m = Graphics.width - @bulls_eye_sprite.x
  112. @arrow_shoot_sprite.x = [@arrow_shoot_sprite.x + @bulls_eye_speed, m].min
  113. @bulls_eye_direction = 1 if @arrow_shoot_sprite.x >= m
  114. else
  115. m = @bulls_eye_sprite.x
  116. @arrow_shoot_sprite.x = [@arrow_shoot_sprite.x - @bulls_eye_speed, m].max
  117. @bulls_eye_direction = 0 if @arrow_shoot_sprite.x <= m
  118. end
  119. @click_sound.play if @bulls_eye_speed >= 0
  120. @arrow_shoot_sprite.update
  121. end
  122. #--------------------------------------------------------------------------
  123. # * Create Bulls Eye Results
  124. #--------------------------------------------------------------------------
  125. def create_bulls_eye_results
  126. @results_sprite = Sprite_Base.new(@viewport3)
  127. @results_sprite.bitmap = Bitmap.new(96, 24)
  128. bitmap = Cache.system(SSS::BULLS_EYE_SHEET)
  129. mx = @bulls_eye_sprite.x
  130. perfect_location = (mx+244)..(mx+268)
  131. almost_percent = (@bulls_eye_percent * 512 / 100) / 2
  132. almost_location1 = 512/2 - almost_percent
  133. almost_location2 = 512/2 + almost_percent
  134.  
  135. very_close_percent = (@bulls_eye_percent * 512 / 100) / 2 - VERY_CLOSE_OFFSET
  136. very_close_location1 = 512/2 - very_close_percent
  137. very_close_location2 = 512/2 + very_close_percent
  138. if (mx+244..mx+268) === @arrow_shoot_sprite.x
  139. SSS::BULLS_EYE_PERFECT.play
  140. @result = 3
  141. rect = Rect.new(24, 48, 96, 24)
  142. elsif (mx+very_close_location1..mx+very_close_location2) === @arrow_shoot_sprite.x
  143. SSS::BULLS_EYE_VERY_CLOSE.play
  144. @result = 2
  145. bitmap = Cache.system(SSS::VERY_CLOSE_TEXT)
  146. rect = Rect.new(0, 0, bitmap.width, bitmap.height)
  147. elsif (mx+almost_location1..mx+almost_location2) === @arrow_shoot_sprite.x
  148. SSS::BULLS_EYE_ALMOST.play
  149. @result = 1
  150. rect = Rect.new(120, 48, 96, 24)
  151. else
  152. SSS::BULLS_EYE_MISSED.play
  153. @result = 0
  154. rect = Rect.new(216, 48, 96, 24)
  155. end
  156. @results_sprite.bitmap.blt(0, 0, bitmap, rect)
  157. @results_sprite.ox = 48
  158. @results_sprite.x = Graphics.width / 2
  159. @results_sprite.y = @bulls_eye_sprite.y - 24
  160. end
  161. #--------------------------------------------------------------------------
  162. # * Stop Bulls Eye Sprites
  163. #--------------------------------------------------------------------------
  164. def stop_bulls_eye_sprites
  165. @bulls_eye_speed = 0
  166. @shoot_sound.play
  167. wait = 60
  168. loop do
  169. wait -= 1
  170. SceneManager.scene.update_basic
  171. @results_sprite.update unless @results_sprite.nil?#update
  172. case wait
  173. when 40
  174. create_bulls_eye_results
  175. when 0
  176. break
  177. end
  178. end
  179. dispose_bulls_eye_sprites
  180. return @result
  181. end
  182. end
  183. end
  184.  
  185. #==============================================================================
  186. # ** Game_Interpreter
  187. #==============================================================================
  188.  
  189. class Game_Interpreter
  190. #--------------------------------------------------------------------------
  191. # * Bulls Eye Game
  192. #--------------------------------------------------------------------------
  193. def bulls_eye(percent = 15, speed = 10)
  194. return false unless SceneManager.scene.is_a?(Scene_Map) or SceneManager.scene.is_a?(Scene_Battle)
  195. return SceneManager.scene.bulls_eye(percent, speed)
  196. end
  197. end
  198.  
  199. #==============================================================================
  200. # ** Spriteset_Map
  201. #==============================================================================
  202.  
  203. class Spriteset_Map
  204. include SSS::SPRITESET
  205. #--------------------------------------------------------------------------
  206. # * Dispose
  207. #--------------------------------------------------------------------------
  208. alias dispose_sss_spriteset_map_bulls_eye dispose unless $@
  209. def dispose
  210. dispose_sss_spriteset_map_bulls_eye
  211. dispose_bulls_eye_sprites
  212. end
  213. end
  214.  
  215. #==============================================================================
  216. # ** Spriteset_Battle
  217. #==============================================================================
  218.  
  219. class Spriteset_Battle
  220. include SSS::SPRITESET
  221. #--------------------------------------------------------------------------
  222. # * Dispose
  223. #--------------------------------------------------------------------------
  224. alias dispose_sss_spriteset_battle_bulls_eye dispose unless $@
  225. def dispose
  226. dispose_sss_spriteset_battle_bulls_eye
  227. dispose_bulls_eye_sprites
  228. end
  229. end
  230.  
  231. #==============================================================================
  232. # ** Scene_Map
  233. #==============================================================================
  234.  
  235. class Scene_Map < Scene_Base
  236. #--------------------------------------------------------------------------
  237. # * Public Instance Variables
  238. #--------------------------------------------------------------------------
  239. attr_accessor :spriteset
  240. #--------------------------------------------------------------------------
  241. # * Bulls Eye Game
  242. #--------------------------------------------------------------------------
  243. def bulls_eye(percent = 15, speed = 10)
  244. @spriteset.bulls_eye_game(percent, speed)
  245. loop do
  246. update_basic
  247. @spriteset.update_bulls_eye_sprites
  248. break if Input.trigger?(Input::X)
  249. end
  250. return @spriteset.stop_bulls_eye_sprites
  251. end
  252. end
  253.  
  254. #==============================================================================
  255. # ** Scene_Battle
  256. #==============================================================================
  257.  
  258. class Scene_Battle < Scene_Base
  259. #--------------------------------------------------------------------------
  260. # * Public Instance Variables
  261. #--------------------------------------------------------------------------
  262. attr_accessor :spriteset
  263. #--------------------------------------------------------------------------
  264. # * Bulls Eye Game
  265. #--------------------------------------------------------------------------
  266. def bulls_eye(percent = 15, speed = 10)
  267. @spriteset.bulls_eye_game(percent, speed)
  268. $sv_camera.event = false
  269. @actor_command_window.deactivate
  270. loop do
  271. update_basic
  272. @spriteset.update_bulls_eye_sprites
  273. break if Input.trigger?(Input::X)
  274. end
  275. return @spriteset.stop_bulls_eye_sprites
  276. end
  277. end
  278.  
  279. class SideView
  280. def bulls_eye(percent = 15, speed = 10)
  281. return false unless SceneManager.scene.is_a?(Scene_Map) or SceneManager.scene.is_a?(Scene_Battle)
  282. @event_fix = true
  283. return SceneManager.scene.bulls_eye(percent, speed)
  284. end
  285. end
  286.  
  287. #===============================================================================
  288. #
  289. # END OF FILE
  290. #
  291. #===============================================================================
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement