Advertisement
Guest User

Untitled

a guest
Jun 22nd, 2017
493
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.66 KB | None | 0 0
  1. #===============================================================
  2. # ● [VX] ◦ MiniMap ◦ □
  3. # * Plug N Play Minimap (Don't need image~) *
  4. #--------------------------------------------------------------
  5. # ◦ by Woratana [woratana@hotmail.com]
  6. # ◦ Thaiware RPG Maker Community
  7. # ◦ Released on: 09/06/2008
  8. # ◦ Version: 1.0
  9. #--------------------------------------------------------------
  10. # ◦ Credit: KGC for XP MiniMap Script,
  11. # this script can't be done without his MiniMap.
  12. #--------------------------------------------------------------
  13.  
  14. module MiniMap
  15. #===========================================================================
  16. # [START] MINIMAP SCRIPT SETUP PART
  17. #---------------------------------------------------------------------------
  18. SWITCH_NO_MINIMAP = 10 # Turn ON this switch to NOT SHOW minimap
  19.  
  20. MAP_RECT = [410, 20, 100, 100] # Minimap size and position
  21. # [X, Y, Width, Height]
  22. # You can change it in game, by call script:
  23. # $game_system.minimap = [X, Y, Width, Height]
  24.  
  25. MAP_Z = 0 # Minimap's Z-coordinate
  26. # Increase this number if there is problem that minimap show below some objects.
  27.  
  28. GRID_SIZE = 5 # Minimap's grid size. Recommend to use more than 3.
  29.  
  30. MINIMAP_BORDER_COLOR = Color.new(0, 0, 255, 160) # Minimap's border color
  31. # Color.new(Red, Green, Blue, Opacity)
  32. MINIMAP_BORDER_SIZE = 2 # Minimap's border size
  33.  
  34. FOREGROUND_COLOR = Color.new(224, 224, 255, 160) # Passable tile color
  35. BACKGROUND_COLOR = Color.new(0, 0, 0, 160) # Unpassable tile color
  36.  
  37. USE_OUTLINE_PLAYER = true # Draw outline around player in minimap?
  38. PLAYER_OUTLINE_COLOR = Color.new(0, 0, 0, 192) # Player Outline color
  39. USE_OUTLINE_EVENT = true # Draw outline around events in minimap?
  40. EVENT_OUTLINE_COLOR = Color.new(255, 255, 255, 192) # Player Outline color
  41.  
  42. PLAYER_COLOR = Color.new(255, 0, 0, 192) # Player color
  43. #---------------------------------------------------------------------------
  44.  
  45. OBJECT_COLOR = {} # Don't change or delete this line!
  46. #===============================================================
  47. # * SETUP EVENT KEYWORD & COLOR
  48. #---------------------------------------------------------------
  49. # ** Template:
  50. # OBJECT_COLOR['keyword'] = Color.new(Red, Green, Blue, Opacity)
  51. #-------------------------------------------------------------
  52. # * 'keyword': Word you want to put in event's comment to show this color
  53. # ** Note: 'keyword' is CASE SENSITIVE!
  54. # * Color.new(...): Color you want
  55. # You can put between 0 - 255 in each argument (Red, Green, Blue, Opacity)
  56. #-------------------------------------------------------------
  57. OBJECT_COLOR['npc'] = Color.new(30,144,255,160)
  58. OBJECT_COLOR['treasure'] = Color.new(0,255,255,160)
  59. OBJECT_COLOR['enemy'] = Color.new(139,35,35,160)
  60. OBJECT_COLOR['merchant'] = Color.new(255,255,0,160)
  61.  
  62. #===========================================================================
  63. # * [OPTIONAL] TAGS:
  64. #---------------------------------------------------------------------------
  65. # Change keyword for disable minimap & keyword for show event on minimap~
  66. #-----------------------------------------------------------------------
  67. TAG_NO_MINIMAP = '[NOMAP]' # Tag for disable minimap
  68. TAG_EVENT = 'MMEV' # Tag for show event on minimap
  69. #---------------------------------------------------------------------------
  70.  
  71. #---------------------------------------------------------------------------
  72. # [END] MINIMAP SCRIPT SETUP PART
  73. #===========================================================================
  74.  
  75. def self.refresh
  76. if $scene.is_a?(Scene_Map)
  77. $scene.spriteset.minimap.refresh
  78. end
  79. end
  80.  
  81. def self.update_object
  82. if $scene.is_a?(Scene_Map)
  83. $scene.spriteset.minimap.update_object_list
  84. end
  85. end
  86. end
  87.  
  88. #==============================================================================
  89. # ■ RPG::MapInfo
  90. #==============================================================================
  91. class RPG::MapInfo
  92. def name
  93. return @name.gsub(/\[.*\]/) { }
  94. end
  95.  
  96. def original_name
  97. return @name
  98. end
  99.  
  100. def show_minimap?
  101. return !@name.include?(MiniMap::TAG_NO_MINIMAP)
  102. end
  103. end
  104. #==============================================================================
  105. # ■ Game_System
  106. #==============================================================================
  107. class Game_System
  108. attr_accessor :minimap
  109. alias wora_minimap_gamsys_ini initialize
  110.  
  111. def initialize
  112. wora_minimap_gamsys_ini
  113. @minimap = MiniMap::MAP_RECT
  114. end
  115.  
  116. def show_minimap
  117. return !$game_switches[MiniMap::SWITCH_NO_MINIMAP]
  118. end
  119. end
  120. #==============================================================================
  121. # ■ Game_Map
  122. #==============================================================================
  123. class Game_Map
  124. alias wora_minimap_gammap_setup setup
  125. def setup(map_id)
  126. wora_minimap_gammap_setup(map_id)
  127. @db_info = load_data('Data/MapInfos.rvdata') if @db_info.nil?
  128. @map_info = @db_info[map_id]
  129. end
  130.  
  131. def show_minimap?
  132. return @map_info.show_minimap?
  133. end
  134. end
  135. #==============================================================================
  136. # ■ Game_Event
  137. #==============================================================================
  138. class Game_Event < Game_Character
  139. def mm_comment?(comment, return_comment = false )
  140. if !@list.nil?
  141. for i in 0...@list.size - 1
  142. next if @list[i].code != 108
  143. if @list[i].parameters[0].include?(comment)
  144. return @list[i].parameters[0] if return_comment
  145. return true
  146. end
  147. end
  148. end
  149. return '' if return_comment
  150. return false
  151. end
  152. end
  153. #==============================================================================
  154. # ■ Game_MiniMap
  155. #------------------------------------------------------------------------------
  156. class Game_MiniMap
  157. def initialize(tilemap)
  158. @tilemap = tilemap
  159. refresh
  160. end
  161.  
  162. def dispose
  163. @border.bitmap.dispose
  164. @border.dispose
  165. @map_sprite.bitmap.dispose
  166. @map_sprite.dispose
  167. @object_sprite.bitmap.dispose
  168. @object_sprite.dispose
  169. @position_sprite.bitmap.dispose
  170. @position_sprite.dispose
  171. end
  172.  
  173. def visible
  174. return @map_sprite.visible
  175. end
  176.  
  177. def visible=(value)
  178. @map_sprite.visible = value
  179. @object_sprite.visible = value
  180. @position_sprite.visible = value
  181. @border.visible = value
  182. end
  183.  
  184. def refresh
  185. @mmr = $game_system.minimap
  186. map_rect = Rect.new(@mmr[0], @mmr[1], @mmr[2], @mmr[3])
  187. grid_size = [MiniMap::GRID_SIZE, 1].max
  188.  
  189. @x = 0
  190. @y = 0
  191. @size = [map_rect.width / grid_size, map_rect.height / grid_size]
  192.  
  193. @border = Sprite.new
  194. @border.x = map_rect.x - MiniMap::MINIMAP_BORDER_SIZE
  195. @border.y = map_rect.y - MiniMap::MINIMAP_BORDER_SIZE
  196. b_width = map_rect.width + (MiniMap::MINIMAP_BORDER_SIZE * 2)
  197. b_height = map_rect.height + (MiniMap::MINIMAP_BORDER_SIZE * 2)
  198. @border.bitmap = Bitmap.new(b_width, b_height)
  199. @border.bitmap.fill_rect(@border.bitmap.rect, MiniMap::MINIMAP_BORDER_COLOR)
  200. @border.bitmap.clear_rect(MiniMap::MINIMAP_BORDER_SIZE, MiniMap::MINIMAP_BORDER_SIZE,
  201. @border.bitmap.width - (MiniMap::MINIMAP_BORDER_SIZE * 2),
  202. @border.bitmap.height - (MiniMap::MINIMAP_BORDER_SIZE * 2))
  203.  
  204. @map_sprite = Sprite.new
  205. @map_sprite.x = map_rect.x
  206. @map_sprite.y = map_rect.y
  207. @map_sprite.z = MiniMap::MAP_Z
  208. bitmap_width = $game_map.width * grid_size + map_rect.width
  209. bitmap_height = $game_map.height * grid_size + map_rect.height
  210. @map_sprite.bitmap = Bitmap.new(bitmap_width, bitmap_height)
  211. @map_sprite.src_rect = map_rect
  212.  
  213. @object_sprite = Sprite.new
  214. @object_sprite.x = map_rect.x
  215. @object_sprite.y = map_rect.y
  216. @object_sprite.z = MiniMap::MAP_Z + 1
  217. @object_sprite.bitmap = Bitmap.new(bitmap_width, bitmap_height)
  218. @object_sprite.src_rect = map_rect
  219.  
  220. @position_sprite = Sprite_Base.new
  221. @position_sprite.x = map_rect.x + @size[0] / 2 * grid_size
  222. @position_sprite.y = map_rect.y + @size[1] / 2 * grid_size
  223. @position_sprite.z = MiniMap::MAP_Z + 2
  224.  
  225. bitmap = Bitmap.new(grid_size, grid_size)
  226. # Player's Outline
  227. if MiniMap::USE_OUTLINE_PLAYER and MiniMap::GRID_SIZE >= 3
  228. bitmap.fill_rect(bitmap.rect, MiniMap::PLAYER_OUTLINE_COLOR)
  229. brect = Rect.new(bitmap.rect.x + 1, bitmap.rect.y + 1, bitmap.rect.width - 2,
  230. bitmap.rect.height - 2)
  231. bitmap.clear_rect(brect)
  232. else
  233. brect = bitmap.rect
  234. end
  235.  
  236. bitmap.fill_rect(brect, MiniMap::PLAYER_COLOR)
  237. @position_sprite.bitmap = bitmap
  238.  
  239. draw_map
  240. update_object_list
  241. draw_object
  242. update_position
  243. end
  244.  
  245. def draw_map
  246. bitmap = @map_sprite.bitmap
  247. bitmap.fill_rect(bitmap.rect, MiniMap::BACKGROUND_COLOR)
  248. map_rect = Rect.new(@mmr[0], @mmr[1], @mmr[2], @mmr[3])
  249. grid_size = [MiniMap::GRID_SIZE, 1].max
  250.  
  251. $game_map.width.times do |i|
  252. $game_map.height.times do |j|
  253. if !$game_map.passable?(i, j)
  254. next
  255. end
  256. rect = Rect.new(map_rect.width / 2 + grid_size * i,
  257. map_rect.height / 2 + grid_size * j,
  258. grid_size, grid_size)
  259. if grid_size >= 3
  260. if !$game_map.passable?(i, j)
  261. rect.height -= 1
  262. rect.x += 1
  263. rect.width -= 1
  264. rect.width -= 1
  265. rect.y += 1
  266. rect.height -= 1
  267. end
  268. end
  269. bitmap.fill_rect(rect, MiniMap::FOREGROUND_COLOR)
  270. end
  271. end
  272. end
  273.  
  274. def update_object_list
  275. @object_list = {}
  276. $game_map.events.values.each do |e|
  277. comment = e.mm_comment?(MiniMap::TAG_EVENT, true)
  278. if comment != ''
  279. type = comment.gsub(/#{MiniMap::TAG_EVENT}/){}.gsub(/\s+/){}
  280. @object_list[type] = [] if @object_list[type].nil?
  281. @object_list[type] << e
  282. end
  283. end
  284. end
  285.  
  286. def draw_object
  287. bitmap = @object_sprite.bitmap
  288. bitmap.clear
  289. map_rect = Rect.new(@mmr[0], @mmr[1], @mmr[2], @mmr[3])
  290. grid_size = [MiniMap::GRID_SIZE, 1].max
  291. rect = Rect.new(0, 0, grid_size, grid_size)
  292. mw = map_rect.width / 2
  293. mh = map_rect.height / 2
  294.  
  295. @object_list.each do |key, events|
  296. color = MiniMap::OBJECT_COLOR[key]
  297. next if events.nil? or color.nil?
  298. events.each do |obj|
  299. if !obj.character_name.empty?
  300. rect.x = mw + obj.real_x * grid_size / 256
  301. rect.y = mh + obj.real_y * grid_size / 256
  302. # Event's Outline
  303. if MiniMap::USE_OUTLINE_EVENT and MiniMap::GRID_SIZE >= 3
  304. bitmap.fill_rect(rect, MiniMap::EVENT_OUTLINE_COLOR)
  305. brect = Rect.new(rect.x + 1, rect.y + 1, rect.width - 2,
  306. rect.height - 2)
  307. bitmap.clear_rect(brect)
  308. else
  309. brect = bitmap.rect
  310. end
  311. bitmap.fill_rect(brect, color)
  312. end
  313. end
  314. end
  315. end
  316.  
  317. def update
  318. if @mmr != $game_system.minimap
  319. dispose
  320. refresh
  321. end
  322. draw_object
  323. update_position
  324. if @map_sprite.visible
  325. @map_sprite.update
  326. @object_sprite.update
  327. @position_sprite.update
  328. end
  329. end
  330.  
  331. def update_position
  332. map_rect = Rect.new(@mmr[0], @mmr[1], @mmr[2], @mmr[3])
  333. grid_size = [MiniMap::GRID_SIZE, 1].max
  334. sx = $game_player.real_x * grid_size / 256
  335. sy = $game_player.real_y * grid_size / 256
  336. @map_sprite.src_rect.x = sx
  337. @map_sprite.src_rect.y = sy
  338. @object_sprite.src_rect.x = sx
  339. @object_sprite.src_rect.y = sy
  340. end
  341. end
  342. #==============================================================================
  343. # ■ Spriteset_Map
  344. #------------------------------------------------------------------------------
  345. class Spriteset_Map
  346. attr_reader :minimap
  347. alias wora_minimap_sprsetmap_ini initialize
  348. alias wora_minimap_sprsetmap_dis dispose
  349. alias wora_minimap_sprsetmap_upd update
  350.  
  351. def initialize
  352. wora_minimap_sprsetmap_ini
  353. if $game_map.show_minimap?
  354. @minimap = Game_MiniMap.new(@tilemap)
  355. $game_system.show_minimap = true if $game_system.show_minimap.nil?
  356. @minimap.visible = $game_system.show_minimap
  357. end
  358. end
  359.  
  360. def dispose
  361. @minimap.dispose if !@minimap.nil?
  362. wora_minimap_sprsetmap_dis
  363. end
  364.  
  365. def update
  366. if !@minimap.nil?
  367. if $game_system.show_minimap
  368. @minimap.visible = true
  369. @minimap.update
  370. else
  371. @minimap.visible = false
  372. end
  373. end
  374. wora_minimap_sprsetmap_upd
  375. end
  376. end
  377. #==============================================================================
  378. # ■ Scene_Map
  379. #------------------------------------------------------------------------------
  380. class Scene_Map < Scene_Base
  381. attr_reader :spriteset
  382. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement