Advertisement
dsiver144

Dark's Dowsing Machine

May 31st, 2016
324
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.59 KB | None | 0 0
  1. #===============================================================================
  2. # Name: Dark's Dowsing Machine (Pokemon)
  3. # Author: Nhat Nguyen (Dark Sky)
  4. # Released on: May 31st 2016
  5. #-------------------------------------------------------------------------------
  6. # Version 1.0: Released!
  7. #-------------------------------------------------------------------------------
  8. # Plug and play!
  9. #-------------------------------------------------------------------------------
  10. # Event's Comment Tag: <hidden_object>
  11. #===============================================================================
  12. module DarkCreation
  13. module HiddenObjects
  14. ACTIVE_RANGE = 5 #Find it out yourself!
  15. ACTIVE_SWITCH = 15 #Set this switch to true to activate the machine
  16. WIN_X = 32*6
  17. WIN_Y = 32*7
  18. TOKEN = /<hidden_object>/i #Just leave it alone!
  19. end
  20. end
  21. include DarkCreation::HiddenObjects
  22. class Spriteset_Map
  23. #--------------------------------------------------------------------------
  24. # * Aliasing Methods
  25. #--------------------------------------------------------------------------
  26. alias d1init initialize
  27. alias d1upd update
  28. alias d1dis dispose
  29. #--------------------------------------------------------------------------
  30. # * Initialize
  31. #--------------------------------------------------------------------------
  32. def initialize
  33. init_hidden_objects
  34. @dowsing_machine = Window_DowsingMachine.new(WIN_X,WIN_Y)
  35. @dowsing_machine.targets = @_hidden_objects
  36. d1init
  37. end
  38. #--------------------------------------------------------------------------
  39. # * Initialize Hidden Objects
  40. #--------------------------------------------------------------------------
  41. def init_hidden_objects
  42. @_hidden_objects ||= []
  43. @_hidden_objects.clear
  44. $game_map.events.values.each do |event|
  45. next if event.list.nil?
  46. event.list.each do |command|
  47. next if command.code != 108
  48. if command.parameters[0] =~ TOKEN
  49. @_hidden_objects.push(event)
  50. end
  51. end
  52. end
  53. end
  54. #--------------------------------------------------------------------------
  55. # * Update
  56. #--------------------------------------------------------------------------
  57. def update
  58. d1upd
  59. if $game_switches[ACTIVE_SWITCH]
  60. @dowsing_machine.update
  61. else
  62. @dowsing_machine.visible = false if @dowsing_machine.visible == true
  63. end
  64. end
  65. #--------------------------------------------------------------------------
  66. # * Dispose
  67. #--------------------------------------------------------------------------
  68. def dispose
  69. d1dis
  70. @dowsing_machine.dispose
  71. end
  72. end
  73.  
  74. class Window_DowsingMachine < Window_Base
  75. attr_accessor :targets
  76. DELAY_TIME = 20
  77. #--------------------------------------------------------------------------
  78. # * Initialize
  79. #--------------------------------------------------------------------------
  80. def initialize(x,y)
  81. super(x,y,5*32,3*32)
  82. self.opacity = 0
  83. @current_tar = nil
  84. @viewport = Viewport.new(0,0,Graphics.width,Graphics.height)
  85. @viewport.z = 100
  86. self.viewport = @viewport
  87. self.back_opacity = 0
  88. self.z = 100
  89. @contents = Sprite.new
  90. @contents.bitmap = Bitmap.new(5*32,3*32)
  91. @contents.bitmap.fill_rect(0,0,5*32,3*32,Color.new(0,0,0,120))
  92. @contents.viewport = @viewport
  93. @contents.z = 50
  94. @contents.x = self.x
  95. @contents.y = self.y
  96. @bg = Sprite.new
  97. @bg.bitmap = Cache.picture("Downsing_BG")
  98. @outline = Cache.picture("Downsing_BG2")
  99. @bg.bitmap.blt(0,0,@outline,@outline.rect)
  100. @bg.viewport = @viewport
  101. @bg.z = 60
  102. @bg.x = self.x
  103. @bg.y = self.y
  104. @sprite_dir = Sprite.new
  105. @sprite_dir.bitmap = Cache.picture("D_director")
  106. @sprite_dir.viewport = @viewport
  107. @sprite_dir.z = 110
  108. @sprite_dir.ox = @sprite_dir.bitmap.width
  109. @sprite_dir.oy = @sprite_dir.bitmap.height / 2
  110. @sprite_dir.x = self.x + @contents.bitmap.width / 2 - @sprite_dir.bitmap.width / 2
  111. @sprite_dir.y = self.y + @sprite_dir.bitmap.width
  112. @sprite_dir.opacity = 150
  113. @sprite_dir2 = Sprite.new
  114. @sprite_dir2.bitmap = Cache.picture("D_director")
  115. @sprite_dir2.viewport = @viewport
  116. @sprite_dir2.z = 110
  117. @sprite_dir2.ox = @sprite_dir2.bitmap.width
  118. @sprite_dir2.oy = @sprite_dir2.bitmap.height / 2
  119. @sprite_dir2.x = self.x + @contents.bitmap.width / 2 + @sprite_dir2.bitmap.width / 2 + 3
  120. @sprite_dir2.y = self.y + @sprite_dir.bitmap.width
  121. @sprite_dir2.opacity = 150
  122. @update_delay = DELAY_TIME
  123. @target_sound_delay = DELAY_TIME
  124. @found_sound_delay = DELAY_TIME
  125. normal_pose
  126. end
  127. #--------------------------------------------------------------------------
  128. # * Set Visibility
  129. #--------------------------------------------------------------------------
  130. def visible=(*arg)
  131. super(*arg)
  132. @sprite_dir.visible = arg[0]
  133. @sprite_dir2.visible = arg[0]
  134. @contents.visible = arg[0]
  135. @bg.visible = arg[0]
  136. end
  137. #--------------------------------------------------------------------------
  138. # * Arrow Poses
  139. #--------------------------------------------------------------------------
  140. def normal_pose
  141. @sprite_dir.angle = -45
  142. @sprite_dir2.angle = -135
  143. end
  144. def found_pose
  145. @sprite_dir.angle = -135
  146. @sprite_dir2.angle = -45
  147. end
  148. def up_pose
  149. @sprite_dir.angle = -90
  150. @sprite_dir2.angle = -90
  151. end
  152. def upl_pose
  153. @sprite_dir.angle = -45
  154. @sprite_dir2.angle = -45
  155. end
  156. def upr_pose
  157. @sprite_dir.angle = -135
  158. @sprite_dir2.angle = -135
  159. end
  160. def down_pose
  161. @sprite_dir.angle = 90
  162. @sprite_dir2.angle = 90
  163. end
  164. def downr_pose
  165. @sprite_dir.angle = 135
  166. @sprite_dir2.angle = 135
  167. end
  168. def downl_pose
  169. @sprite_dir.angle = 45
  170. @sprite_dir2.angle = 45
  171. end
  172. def l_pose
  173. @sprite_dir.angle = 0
  174. @sprite_dir2.angle = 0
  175. end
  176. def r_pose
  177. @sprite_dir.angle = 180
  178. @sprite_dir2.angle = 180
  179. end
  180. #--------------------------------------------------------------------------
  181. # * Update
  182. #--------------------------------------------------------------------------
  183. def update
  184. super
  185. if @update_delay > 0
  186. @update_delay -= 1
  187. end
  188. if @target_sound_delay > 0
  189. @target_sound_delay -= 1
  190. end
  191. if @found_sound_delay > 0
  192. @found_sound_delay -= 1
  193. end
  194. if @targets && @update_delay == 0
  195. distance_a = []
  196. @targets.each do |tar|
  197. next if tar.erased
  198. dis = tar.distance_x_from($game_player.x).abs + tar.distance_y_from($game_player.y).abs
  199. if dis > ACTIVE_RANGE
  200. next
  201. else
  202. distance_a.push([dis,tar])
  203. end
  204. end
  205. if distance_a.size > 0
  206. distance_a.sort! {|a,b| a[0] <=> b[0]}
  207. @last_tar = @current_target
  208. @current_target = distance_a[0][1]
  209. if @last_tar != @current_target
  210. RPG::SE.new("Decision2",100,120).play
  211. @non_target_sound = false
  212. end
  213. @update_delay = DELAY_TIME
  214. else
  215. @current_target = nil
  216. end
  217. end
  218. if @current_target
  219. if @current_target.distance_x_from($game_player.x) < 0 && @current_target.distance_y_from($game_player.y) == 0
  220. l_pose
  221. end
  222. if @current_target.distance_x_from($game_player.x) > 0 && @current_target.distance_y_from($game_player.y) == 0
  223. r_pose
  224. end
  225. if @current_target.distance_y_from($game_player.y) < 0 && @current_target.distance_x_from($game_player.x) == 0
  226. up_pose
  227. end
  228. if @current_target.distance_y_from($game_player.y) > 0 && @current_target.distance_x_from($game_player.x) == 0
  229. down_pose
  230. end
  231. if @current_target.distance_y_from($game_player.y) < 0
  232. if @current_target.distance_x_from($game_player.x) > 0
  233. upr_pose
  234. elsif @current_target.distance_x_from($game_player.x) < 0
  235. upl_pose
  236. end
  237. elsif @current_target.distance_y_from($game_player.y) > 0
  238. if @current_target.distance_x_from($game_player.x) > 0
  239. downr_pose
  240. elsif @current_target.distance_x_from($game_player.x) < 0
  241. downl_pose
  242. end
  243. end
  244. if @current_target.distance_y_from($game_player.y) == 0
  245. if @current_target.distance_x_from($game_player.x) == 0
  246. if @found_sound_delay == 0
  247. RPG::SE.new("Chime2",70,120).play
  248. found_pose
  249. @found_sound_delay = DELAY_TIME
  250. end
  251. end
  252. end
  253. elsif @current_target == nil
  254. normal_pose
  255. if @target_sound_delay == 0 && !@non_target_sound
  256. RPG::SE.new("Ice1").play
  257. @target_sound_delay = DELAY_TIME
  258. @non_target_sound = true
  259. end
  260. end
  261. end #End def
  262. #--------------------------------------------------------------------------
  263. # * Standard Padding
  264. #--------------------------------------------------------------------------
  265. def standard_padding
  266. return 2
  267. end
  268. #--------------------------------------------------------------------------
  269. # * Dispose
  270. #--------------------------------------------------------------------------
  271. def dispose
  272. super
  273. @contents.bitmap.dispose
  274. @contents.dispose
  275. @sprite_dir.bitmap.dispose
  276. @sprite_dir2.dispose
  277. @sprite_dir.dispose
  278. @bg.bitmap.dispose
  279. @bg.dispose
  280. @outline.dispose
  281. end
  282. end
  283.  
  284. class Game_Event
  285. attr_reader :erased
  286. end
  287. #===============================================================================
  288. # END OF SCRIPT!
  289. #===============================================================================
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement