#=======================================================# ● [VX] ◦ MiniMap ◦ □# * Plug N Play Minimap (Don't need image~) *#--------------------------------------------------------------# ◦ by Woratana [woratana@hotmail.com]# ◦ Thaiware RPG Maker Community# ◦ Released on: 09/06/2008# ◦ Version: 1.0#--------------------------------------------------------------# ◦ Credit: KGC for XP MiniMap Script,# this script can't be done without his MiniMap.#--------------------------------------------------------------module MiniMap#===========================================================================# [START] MINIMAP SCRIPT SETUP PART#---------------------------------------------------------------------------SWITCH_NO_MINIMAP = 10 # Turn ON this switch to NOT SHOW minimapMAP_RECT = [410, 20, 100, 100] # Minimap size and position# [X, Y, Width, Height]# You can change it in game, by call script:# $game_system.minimap = [X, Y, Width, Height]MAP_Z = 0 # Minimap's Z-coordinate# Increase this number if there is problem that minimap show below some objects.GRID_SIZE = 5 # Minimap's grid size. Recommend to use more than 3.MINIMAP_BORDER_COLOR = Color.new(0, 0, 255, 160) # Minimap's border color# Color.new(Red, Green, Blue, Opacity)MINIMAP_BORDER_SIZE = 2 # Minimap's border sizeFOREGROUND_COLOR = Color.new(224, 224, 255, 160) # Passable tile colorBACKGROUND_COLOR = Color.new(0, 0, 0, 160) # Unpassable tile colorUSE_OUTLINE_PLAYER = true # Draw outline around player in minimap?PLAYER_OUTLINE_COLOR = Color.new(0, 0, 0, 192) # Player Outline colorUSE_OUTLINE_EVENT = true # Draw outline around events in minimap?EVENT_OUTLINE_COLOR = Color.new(255, 255, 255, 192) # Player Outline colorPLAYER_COLOR = Color.new(255, 0, 0, 192) # Player color#---------------------------------------------------------------------------OBJECT_COLOR = {} # Don't change or delete this line!#===============================================================# * SETUP EVENT KEYWORD & COLOR#---------------------------------------------------------------# ** Template:# OBJECT_COLOR['keyword'] = Color.new(Red, Green, Blue, Opacity)#-------------------------------------------------------------# * 'keyword': Word you want to put in event's comment to show this color# ** Note: 'keyword' is CASE SENSITIVE!# * Color.new(...): Color you want# You can put between 0 - 255 in each argument (Red, Green, Blue, Opacity)#-------------------------------------------------------------OBJECT_COLOR['npc'] = Color.new(30,144,255,160)OBJECT_COLOR['treasure'] = Color.new(0,255,255,160)OBJECT_COLOR['enemy'] = Color.new(139,35,35,160)OBJECT_COLOR['merchant'] = Color.new(255,255,0,160)#===========================================================================# * [OPTIONAL] TAGS:#---------------------------------------------------------------------------# Change keyword for disable minimap & keyword for show event on minimap~#-----------------------------------------------------------------------TAG_NO_MINIMAP = '[NOMAP]' # Tag for disable minimapTAG_EVENT = 'MMEV' # Tag for show event on minimap#---------------------------------------------------------------------------#---------------------------------------------------------------------------# [END] MINIMAP SCRIPT SETUP PART#===========================================================================def self.refreshif $scene.is_a?(Scene_Map)$scene.spriteset.minimap.refreshendenddef self.update_objectif $scene.is_a?(Scene_Map)$scene.spriteset.minimap.update_object_listendendend#==============================================================================# ■ RPG::MapInfo#==============================================================================class RPG::MapInfodef namereturn @name.gsub(/\[.*\]/) { }enddef original_namereturn @nameenddef show_minimap?return !@name.include?(MiniMap::TAG_NO_MINIMAP)endend#==============================================================================# ■ Game_System#==============================================================================class Game_Systemattr_accessor :minimapalias wora_minimap_gamsys_ini initializedef initializewora_minimap_gamsys_ini@minimap = MiniMap::MAP_RECTenddef show_minimapreturn !$game_switches[MiniMap::SWITCH_NO_MINIMAP]endend#==============================================================================# ■ Game_Map#==============================================================================class Game_Mapalias wora_minimap_gammap_setup setupdef setup(map_id)wora_minimap_gammap_setup(map_id)@db_info = load_data('Data/MapInfos.rvdata') if @db_info.nil?@map_info = @db_info[map_id]enddef show_minimap?return @map_info.show_minimap?endend#==============================================================================# ■ Game_Event#==============================================================================class Game_Event < Game_Characterdef mm_comment?(comment, return_comment = false )if !@list.nil?for i in 0...@list.size - 1next if @list[i].code != 108if @list[i].parameters[0].include?(comment)return @list[i].parameters[0] if return_commentreturn trueendendendreturn '' if return_commentreturn falseendend#==============================================================================# ■ Game_MiniMap#------------------------------------------------------------------------------class Game_MiniMapdef initialize(tilemap)@tilemap = tilemaprefreshenddef dispose@border.bitmap.dispose@border.dispose@map_sprite.bitmap.dispose@map_sprite.dispose@object_sprite.bitmap.dispose@object_sprite.dispose@position_sprite.bitmap.dispose@position_sprite.disposeenddef visiblereturn @map_sprite.visibleenddef visible=(value)@map_sprite.visible = value@object_sprite.visible = value@position_sprite.visible = value@border.visible = valueenddef refresh@mmr = $game_system.minimapmap_rect = Rect.new(@mmr[0], @mmr[1], @mmr[2], @mmr[3])grid_size = [MiniMap::GRID_SIZE, 1].max@x = 0@y = 0@size = [map_rect.width / grid_size, map_rect.height / grid_size]@border = Sprite.new@border.x = map_rect.x - MiniMap::MINIMAP_BORDER_SIZE@border.y = map_rect.y - MiniMap::MINIMAP_BORDER_SIZEb_width = map_rect.width + (MiniMap::MINIMAP_BORDER_SIZE * 2)b_height = map_rect.height + (MiniMap::MINIMAP_BORDER_SIZE * 2)@border.bitmap = Bitmap.new(b_width, b_height)@border.bitmap.fill_rect(@border.bitmap.rect, MiniMap::MINIMAP_BORDER_COLOR)@border.bitmap.clear_rect(MiniMap::MINIMAP_BORDER_SIZE, MiniMap::MINIMAP_BORDER_SIZE,@border.bitmap.width - (MiniMap::MINIMAP_BORDER_SIZE * 2),@border.bitmap.height - (MiniMap::MINIMAP_BORDER_SIZE * 2))@map_sprite = Sprite.new@map_sprite.x = map_rect.x@map_sprite.y = map_rect.y@map_sprite.z = MiniMap::MAP_Zbitmap_width = $game_map.width * grid_size + map_rect.widthbitmap_height = $game_map.height * grid_size + map_rect.height@map_sprite.bitmap = Bitmap.new(bitmap_width, bitmap_height)@map_sprite.src_rect = map_rect@object_sprite = Sprite.new@object_sprite.x = map_rect.x@object_sprite.y = map_rect.y@object_sprite.z = MiniMap::MAP_Z + 1@object_sprite.bitmap = Bitmap.new(bitmap_width, bitmap_height)@object_sprite.src_rect = map_rect@position_sprite = Sprite_Base.new@position_sprite.x = map_rect.x + @size[0] / 2 * grid_size@position_sprite.y = map_rect.y + @size[1] / 2 * grid_size@position_sprite.z = MiniMap::MAP_Z + 2bitmap = Bitmap.new(grid_size, grid_size)# Player's Outlineif MiniMap::USE_OUTLINE_PLAYER and MiniMap::GRID_SIZE >= 3bitmap.fill_rect(bitmap.rect, MiniMap::PLAYER_OUTLINE_COLOR)brect = Rect.new(bitmap.rect.x + 1, bitmap.rect.y + 1, bitmap.rect.width - 2,bitmap.rect.height - 2)bitmap.clear_rect(brect)elsebrect = bitmap.rectendbitmap.fill_rect(brect, MiniMap::PLAYER_COLOR)@position_sprite.bitmap = bitmapdraw_mapupdate_object_listdraw_objectupdate_positionenddef draw_mapbitmap = @map_sprite.bitmapbitmap.fill_rect(bitmap.rect, MiniMap::BACKGROUND_COLOR)map_rect = Rect.new(@mmr[0], @mmr[1], @mmr[2], @mmr[3])grid_size = [MiniMap::GRID_SIZE, 1].max$game_map.width.times do |i|$game_map.height.times do |j|if !$game_map.passable?(i, j)nextendrect = Rect.new(map_rect.width / 2 + grid_size * i,map_rect.height / 2 + grid_size * j,grid_size, grid_size)if grid_size >= 3if !$game_map.passable?(i, j)rect.height -= 1rect.x += 1rect.width -= 1rect.width -= 1rect.y += 1rect.height -= 1endendbitmap.fill_rect(rect, MiniMap::FOREGROUND_COLOR)endendenddef update_object_list@object_list = {}$game_map.events.values.each do |e|comment = e.mm_comment?(MiniMap::TAG_EVENT, true)if comment != ''type = comment.gsub(/#{MiniMap::TAG_EVENT}/){}.gsub(/\s+/){}@object_list[type] = [] if @object_list[type].nil?@object_list[type] << eendendenddef draw_objectbitmap = @object_sprite.bitmapbitmap.clearmap_rect = Rect.new(@mmr[0], @mmr[1], @mmr[2], @mmr[3])grid_size = [MiniMap::GRID_SIZE, 1].maxrect = Rect.new(0, 0, grid_size, grid_size)mw = map_rect.width / 2mh = map_rect.height / 2@object_list.each do |key, events|color = MiniMap::OBJECT_COLOR[key]next if events.nil? or color.nil?events.each do |obj|if !obj.character_name.empty?rect.x = mw + obj.real_x * grid_size / 256rect.y = mh + obj.real_y * grid_size / 256# Event's Outlineif MiniMap::USE_OUTLINE_EVENT and MiniMap::GRID_SIZE >= 3bitmap.fill_rect(rect, MiniMap::EVENT_OUTLINE_COLOR)brect = Rect.new(rect.x + 1, rect.y + 1, rect.width - 2,rect.height - 2)bitmap.clear_rect(brect)elsebrect = bitmap.rectendbitmap.fill_rect(brect, color)endendendenddef updateif @mmr != $game_system.minimapdisposerefreshenddraw_objectupdate_positionif @map_sprite.visible@map_sprite.update@object_sprite.update@position_sprite.updateendenddef update_positionmap_rect = Rect.new(@mmr[0], @mmr[1], @mmr[2], @mmr[3])grid_size = [MiniMap::GRID_SIZE, 1].maxsx = $game_player.real_x * grid_size / 256sy = $game_player.real_y * grid_size / 256@map_sprite.src_rect.x = sx@map_sprite.src_rect.y = sy@object_sprite.src_rect.x = sx@object_sprite.src_rect.y = syendend#==============================================================================# ■ Spriteset_Map#------------------------------------------------------------------------------class Spriteset_Mapattr_reader :minimapalias wora_minimap_sprsetmap_ini initializealias wora_minimap_sprsetmap_dis disposealias wora_minimap_sprsetmap_upd updatedef initializewora_minimap_sprsetmap_iniif $game_map.show_minimap?@minimap = Game_MiniMap.new(@tilemap)$game_system.show_minimap = true if $game_system.show_minimap.nil?@minimap.visible = $game_system.show_minimapendenddef dispose@minimap.dispose if !@minimap.nil?wora_minimap_sprsetmap_disenddef updateif !@minimap.nil?if $game_system.show_minimap@minimap.visible = true@minimap.updateelse@minimap.visible = falseendendwora_minimap_sprsetmap_updendend#==============================================================================# ■ Scene_Map#------------------------------------------------------------------------------class Scene_Map < Scene_Baseattr_reader :spritesetend;