Submit Your Article Guild Wars 2 Forum RPG Maker VX.com
 
RPG Maker
 

 Username:
 Password:
   Not a member? Register!



Home > RGSS Script Reference > Game_Map

Game_Map


Inherits from: None

Description: This class contains information about the current map, including its tileset, passability, fog, panorama, battle background, and events.

Code


class Game_Map
# ------------------------------------  
  attr_accessor :tileset_name
  attr_accessor :autotile_names
  attr_accessor :panorama_name
  attr_accessor :panorama_hue
  attr_accessor :fog_name
  attr_accessor :fog_hue
  attr_accessor :fog_opacity
  attr_accessor :fog_blend_type
  attr_accessor :fog_zoom
  attr_accessor :fog_sx
  attr_accessor :fog_sy
  attr_accessor :battleback_name
  attr_accessor :display_x
  attr_accessor :display_y
  attr_accessor :need_refresh
  attr_reader   :passages
  attr_reader   :priorities
  attr_reader   :terrain_tags
  attr_reader   :events
  attr_reader   :fog_ox
  attr_reader   :fog_oy
  attr_reader   :fog_tone
# ------------------------------------  
  def initialize
    @map_id = 0
  end
# ------------------------------------  
  def setup(map_id)
    @map_id = map_id
    @map = load_data(sprintf("Data/Map%03d.rxdata", @map_id))
    tileset = $data_tilesets[@map.tileset_id]
    @tileset_name = tileset.tileset_name
    @autotile_names = tileset.autotile_names
    @panorama_name = tileset.panorama_name
    @panorama_hue = tileset.panorama_hue
    @fog_name = tileset.fog_name
    @fog_hue = tileset.fog_hue
    @fog_opacity = tileset.fog_opacity
    @fog_blend_type = tileset.fog_blend_type
    @fog_zoom = tileset.fog_zoom
    @fog_sx = tileset.fog_sx
    @fog_sy = tileset.fog_sy
    @battleback_name = tileset.battleback_name
    @passages = tileset.passages
    @priorities = tileset.priorities
    @terrain_tags = tileset.terrain_tags
    @display_x = 0
    @display_y = 0
    @need_refresh = false
    @events = {}
    for i in @map.events.keys
      @events[i] = Game_Event.new(@map_id, @map.events[i])
    end
    @common_events = {}
    for i in 1...$data_common_events.size
      @common_events[i] = Game_CommonEvent.new(i)
    end
    @fog_ox = 0
    @fog_oy = 0
    @fog_tone = Tone.new(0, 0, 0, 0)
    @fog_tone_target = Tone.new(0, 0, 0, 0)
    @fog_tone_duration = 0
    @fog_opacity_duration = 0
    @fog_opacity_target = 0
    @scroll_direction = 2
    @scroll_rest = 0
    @scroll_speed = 4
  end
# ------------------------------------  
  def map_id
    return @map_id
  end
# ------------------------------------  
  def width
    return @map.width
  end
# ------------------------------------  
  def height
    return @map.height
  end
# ------------------------------------  
  def encounter_list
    return @map.encounter_list
  end
# ------------------------------------  
  def encounter_step
    return @map.encounter_step
  end
# ------------------------------------  
  def data
    return @map.data
  end
# ------------------------------------  
  def autoplay
    if @map.autoplay_bgm
      $game_system.bgm_play(@map.bgm)
    end
    if @map.autoplay_bgs
      $game_system.bgs_play(@map.bgs)
    end
  end
# ------------------------------------  
  def refresh
    if @map_id > 0
      for event in @events.values
        event.refresh
      end
      for common_event in @common_events.values
        common_event.refresh
      end
    end
    @need_refresh = false
  end
# ------------------------------------  
  def scroll_down(distance)
    @display_y = [@display_y + distance, (self.height - 15) * 128].min
  end
# ------------------------------------  
  def scroll_left(distance)
    @display_x = [@display_x - distance, 0].max
  end
# ------------------------------------  
  def scroll_right(distance)
    @display_x = [@display_x + distance, (self.width - 20) * 128].min
  end
# ------------------------------------  
  def scroll_up(distance)
    @display_y = [@display_y - distance, 0].max
  end
# ------------------------------------  
  def valid?(x, y)
    return (x >= 0 and x < width and y >= 0 and y < height)
  end
# ------------------------------------  
  def passable?(x, y, d, self_event = nil)
    unless valid?(x, y)
      return false
    end
    bit = (1 << (d / 2 - 1)) & 0x0f
    for event in events.values
      if event.tile_id >= 0 and event != self_event and
         event.x == x and event.y == y and not event.through
        if @passages[event.tile_id] & bit != 0
          return false
        elsif @passages[event.tile_id] & 0x0f == 0x0f
          return false
        elsif @priorities[event.tile_id] == 0
          return true
        end
      end
    end
    for i in [2, 1, 0]
      tile_id = data[x, y, i]
      if tile_id == nil
        return false
      elsif @passages[tile_id] & bit != 0
        return false
      elsif @passages[tile_id] & 0x0f == 0x0f
        return false
      elsif @priorities[tile_id] == 0
        return true
      end
    end
    return true
  end
# ------------------------------------  
  def bush?(x, y)
    for i in [2, 1, 0]
      tile_id = data[x, y, i]
      if tile_id == nil
        return false
      elsif @passages[tile_id] & 0x40 == 0x40
        return true
      end
    end
    return false
  end
# ------------------------------------  
  def counter?(x, y)
    for i in [2, 1, 0]
      tile_id = data[x, y, i]
      if tile_id == nil
        return false
      elsif @passages[tile_id] & 0x80 == 0x80
        return true
      end
    end
    return false
  end
# ------------------------------------  
  def terrain_tag(x, y)
    for i in [2, 1, 0]
      tile_id = data[x, y, i]
      if tile_id == nil
        return 0
      elsif @terrain_tags[tile_id] > 0
        return @terrain_tags[tile_id]
      end
    end
    return 0
  end
# ------------------------------------  
  def check_event(x, y)
    for event in $game_map.events.values
      if event.x == x and event.y == y
        return event.id
      end
    end
  end
# ------------------------------------  
  def start_scroll(direction, distance, speed)
    @scroll_direction = direction
    @scroll_rest = distance * 128
    @scroll_speed = speed
  end
# ------------------------------------  
  def scrolling?
    return @scroll_rest > 0
  end
# ------------------------------------  
  def start_fog_tone_change(tone, duration)
    @fog_tone_target = tone.clone
    @fog_tone_duration = duration
    if @fog_tone_duration == 0
      @fog_tone = @fog_tone_target.clone
    end
  end
# ------------------------------------  
  def start_fog_opacity_change(opacity, duration)
    @fog_opacity_target = opacity * 1.0
    @fog_opacity_duration = duration
    if @fog_opacity_duration == 0
      @fog_opacity = @fog_opacity_target.clone
    end
  end
# ------------------------------------  
  def update
    if $game_map.need_refresh
      refresh
    end
    if @scroll_rest > 0
      distance = 2 ** @scroll_speed
      case @scroll_direction
      when 2
        scroll_down(distance)
      when 4
        scroll_left(distance)
      when 6
        scroll_right(distance)
      when 8
        scroll_up(distance)
      end
      @scroll_rest -= distance
    end
    for event in @events.values
      event.update
    end
    for common_event in @common_events.values
      common_event.update
    end
    @fog_ox -= @fog_sx / 8.0
    @fog_oy -= @fog_sy / 8.0
    if @fog_tone_duration >= 1
      d = @fog_tone_duration
      target = @fog_tone_target
      @fog_tone.red = (@fog_tone.red * (d - 1) + target.red) / d
      @fog_tone.green = (@fog_tone.green * (d - 1) + target.green) / d
      @fog_tone.blue = (@fog_tone.blue * (d - 1) + target.blue) / d
      @fog_tone.gray = (@fog_tone.gray * (d - 1) + target.gray) / d
      @fog_tone_duration -= 1
    end
    if @fog_opacity_duration >= 1
      d = @fog_opacity_duration
      @fog_opacity = (@fog_opacity * (d - 1) + @fog_opacity_target) / d
      @fog_opacity_duration -= 1
    end
  end
end

Properties


Map_ID: The map ID of the current map.

Map: The raw data loaded from "mapXXXX.rxdata". This data is then parsed in order to set the individual map properties.

Tileset_Name: The file name from which the map's tileset is drawn.

Autotile_Names: An array containing the filenames from which the map's autotiles are drawn.

Panorama_Name: The filename from which the map's panorama is drawn.

Panorama_Hue: The color modification of the panorama.

Fog_Name: The filename from which the map's fog overlay is drawn.

Fog_Hue: The fog's color modification.

Fog_Opacity: The fog's opacity value, from 0 (completely transparent) to 255 (completely opaque).

Fog_Blend_Type: The graphical blend type of the fog (0 = Normal, 1 = Additive, 2 = Negative).

Fog_Zoom: The magnification of the fog, expressed as a percentage.

Fog_SX: The scroll speed of the fog in the X direction. A positive value indicates scrolling to the right. A negative value indicates scrolling to the left.

Fog_SY: The scroll speed of the fog in the Y direction. A positive value indicates scrolling downward. A negative value indicates scrolling upward.

Battleback_Name: The name of the file from which the map's battle background is drawn.

Display_X: How far right the map has scrolled relative to the far left side of the map. Expressed in real units (4 real units = 1 pixel).

Display_Y: How far down the map has scrolled relative to the top of the map. Expressed in real units (4 real units = 1 pixel).

Passages: An array containing all the passability values for the tiles on the current map.

Priorities: An array containing all the tile priorities for the tiles on the current map.

Terrain_Tags: An array containing the terrain tags for the tiles on the current map.

Events: An array containing Game_Event objects representing the events on the current map.

Fog_OX: The displacement of the fog effect relative to the origin in the X direction.

Fog_OY: The displacement of the fog effect relative to the origin in the Y direction.

Fog_Tone: The fog's color tone. This can be changed with the "Tint Fog" event command.

Fog_Tone_Duration: The amount of frames remaining in a "Tint Fog" operation.

Fog_Tone_Target: The target tone for a "Tint Fog" operation.

Fog_Opacity_Duration: The amount of frames remaining in a "Change Fog Opacity" operation.

Fog_Opacity_Target: The target opacity value for a "Change Fog Opacity" operation.

Need_Refresh: This flag is set if the map graphics need to be refreshed.

Scroll_Direction: The direction in which the map is scrolling (2 = Down, 4 = Left, 6 = Right, 8 = Up).

Scroll_Rest: The number of real units reamining in a scroll operation.

Scroll_Speed: The speed at which the map scrolls each frame.

Methods


Initialize

Arguments: None
Local Variables: None

How it Works: Sets the @map_id variable to 0 (initialization for a given map is done in the Setup method).

Setup

Arguments:
Map_ID: The map ID of the map being set up.
Local Variables: None

How it Works: This method sets up a map by loading the raw data from the map (the @map = load_data(sprintf("Data/Map%03d.rxdata", @map_id)) statement) and then setting the tileset to the ID of the tileset declared for the map. It then uses that tileset information to set the values of the autotiles, panorama, fog, and battle background properties. The rest of the method initializes the events and map display properties.

Map_ID

Arguments: None
Local Variables: None

How it Works: Returns the map ID of the current map.

Width

Arguments: None
Local Variables: None

How it Works: Returns the width of the map, in tiles.

Height

Arguments: None
Local Variables: None

How it Works: Returns the height of the map, in tiles.

Encounter_List

Arguments: None
Local Variables: None

How it Works: Returns the encounter list stored in the map's data file. It's not clear how this list is stored.

Encounter_Step

Arguments: None
Local Variables: None

How it Works: Returns the average number of steps between encounters stored in the map data file.

Data

Arguments: None
Local Variables: None

How it Works: Returns the raw tile information from the map data file to the caller.

Autoplay

Arguments: None
Local Variables: None

How it Works: Makes the BGM and/or BGS associated with the map as declared in the map settings begin playing.

Refresh

Arguments: None
Local Variables: None

How it Works: Refreshes the state of the map's events and the common events declared in the database. This method is called only when the @need_refresh flag is set. It first iterates through the list of map events on the map and calls the Game_Event#refresh method for each of them. Then, the Game_CommonEvent#refresh method is called for each common event declared in the database. Finally, the @need_refresh flag is cleared.

Scroll_Down

Arguments:
Distance: The distance to scroll in real units (4 real units = 1 pixel).
Local Variables: None

How it Works: This method scrolls the map downward by increasing the value of @display_y by the value of distance. In order to prevent the map from scrolling further than the bottom of the map, the new value of @display_y is compared with the map's height (in tiles) minus 15, x 128, in order to create a boundary line. If the new value of @display_y would be larger than that, the map only scrolls to the boundary line.

Scroll_Left

Arguments:
Distance: The distance to scroll in real units (4 real units = 1 pixel).
Local Variables: None

How it Works: This method scrolls the map left by decreasing the value of @display_x by the value of distance. In order to prevent the map from scrolling further than the left side of the map, the new value of @display_x is compared with 0 in order to create a boundary line. If the new value of @display_x would be smaller than 0, the map only scrolls to the boundary line.

Scroll_Right

Arguments:
Distance: The distance to scroll in real units (4 real units = 1 pixel).
Local Variables: None

How it Works: This method scrolls the map right by increasing the value of @display_x by the value of distance. In order to prevent the map from scrolling further than the right side of the map, the new value of @display_y is compared with the map's width (in tiles) minus 20, x 128, in order to create a boundary line. If the new value of @display_x would be larger than that, the map only scrolls to the boundary line.

Scroll_Up

Arguments:
Distance: The distance to scroll in real units (4 real units = 1 pixel).
Local Variables: None

How it Works: This method scrolls the map upward by decreasing the value of @display_y by the value of distance. In order to prevent the map from scrolling further than the top of the map, the new value of @display_y is compared with 0 in order to create a boundary line. If the new value of @display_y would be smaller than 0, the map only scrolls to the boundary line.

Valid?

Arguments:
X: The X coordinate to check.
Y: The Y coordinate to check.
Local Variables: None

How it Works: This method checks to see if an ordered pair of (X, Y) tile coordinates passed to it are within the bounds of the map. If the X value is at least 0 and less than the width of the map, and the Y value is at least 0 and less than the height of the map, this method returns true. Otherwise, it returns false.

Passable?

Arguments:
X: The X coordinate to check.
Y: The Y coordinate to check.
D: The direction to check (0 = Multidirectional, 2 = Down, 4 = Left, 6 = Right, 8 = Up, 10 = Special)
Self_Event: The event for which passability is being evaluated.
Local Variables:
Bit: A bit pattern, but it's not clear what this does.

How it Works: This method checks to see if a tile on the map is passable. First, it checks to see if the tile coordinates passed to the method are within the bounds of the map. If they aren't, the method returns false. The rest of this method uses strange bitwise operations that I'm not familiar with, so this method will have to stay undocumented for now.

Bush?

Arguments:
X: The X coordinate to check.
Y: The Y coordinate to check.
Local Variables: None

How it Works: Returns true if the "Obscure Character" flag is set for any of the three tiles at the specified X/Y coordinates.

Counter?

Arguments:
X: The X coordinate to check.
Y: The Y coordinate to check.
Local Variables: None

How it Works: Returns true if the counter flag is set for any of the three tiles at the specified X/Y coordinates.

Terrain_Tag

Arguments:
X: The X coordinate to check.
Y: The Y coordinate to check.
Local Variables: None

How it Works: Returns the terrain tag for the specified X and Y coordinates. First, the terrain tag of the tile on the top layer is checked. If that value is greater than 0, then that terrain tag is returned. Otherwise, the process is repeated for the middle layer and the bottom layer. If none of the tiles at the specified X/Y coordinates have non-zero terrain tags, 0 is returned.

Check_Event

Arguments:
X: The X coordinate to check.
Y: The Y coordinate to check.
Local Variables: None

How it Works: Returns the event ID of the event at the X/Y tile coordinates passed to this method. If there are multiple events on the tile in question, the ID of the event with the lowest ID number will be returned. If there is no event on the specified tile, the method returns nil.

Start_Scroll

Arguments:
Direction: The direction to scroll (2 = Down, 4 = Left, 6 = Right, 8 = Up).
Distance: The distance to scroll, in tiles.
Speed: The speed to scroll, expressed as a value from 1-6.
Local Variables: None

How it Works: Sets the value of @scroll_direction to the direction to scroll. Sets the value of @scroll_rest to the scroll distance times 128. @scroll_rest expresses the amount of real units remaining in the scroll operation. Finally, @scroll_speed is set to the speed value passed to the method. The Update method handles the frame-by-frame action of the scroll operation.

Scrolling?

Arguments: None
Local Variables: None

How it Works: This method returns true if there is at least 1 real unit remaining in a scroll operation (@scroll_rest > 0). Otherwise, it returns false

Start_Fog_Tone_Change

Arguments:
Tone: The fog's new tone
Duration: The transition time from the old tone to the new tone, in frames.
Local Variables: None

How it Works: This method sets the @fog_tone_target to the new tone and @fog_tone_duration to the duration of the tone change, in frames. If the duration of the tone change is 0 frames, the method directly changes the tone to the new tone. If the tone change lasts 1 or more frames, the Update method handles the frame-by-frame transition.

Start_Fog_Opacity_Change

Arguments:
Opacity: The fog's new opacity
Duration: The transition time from the old opacity to the new opacity, in frames.
Local Variables: None

How it Works: This method sets the @fog_opacity_target to the new opacity value and @fog_opacity_duration to the duration of the opacity change, in frames. If the duration of the opacity change is 0 frames, the method directly changes the tone to the new opacity. If the opacity change lasts 1 or more frames, the Update method handles the frame-by-frame transition.

Update

Arguments: None
Local Variables:
Distance: The number of real units to scroll the map this frame (4 real units = 1 pixel).

How it Works: This method updates the map's state each frame. First, if the game map needs refreshing, due to changes in event status, a call to Refresh is made. Once that's taken care of, the next order of business is update any scrolling action in progress. If the value of scroll_rest is at least 1, the value of distance (in real units) is set to 2scroll speed. Then, the appropriate directional scroll method is called to actually update the graphics. Finally, the value of scroll_rest is decreased by the value of distance. The two for loops iterate first through the map events, then the common events, and update each event's state. The last part of the method deals with updating any fog effects running on the map. The @fog_ox -= @fog_sx / 8.0 and @fog_oy -= @fog_sy / 8.0 statements update the displacement of the fog relative to the origin. Note that since these values represent displacements from the origin, the value will move in the opposite direction from the direction of scrolling. Next, any fog tinting effect in progress is handled. Each color is handled seperately. The effect of the equation @fog_tone.red = (@fog_tone.red * (d - 1) + target.red) / d statement and its counterparts for the other colors is that each frame, that's color will change by (target tone - beginning tone / total duration) tone units per frame. Finally, any fog opacity changes are handled by using the same equation as above on the fog opacity value. 
Syntax
@
@@
$
alias
[array index]
attr_accessor
attr_reader
attr_writer
class
def
do
ensure
for
if
[iterator]
key => value
new
next
nil
redo
require
return
rescue
self
super
undef
unless
until
while
yield

Classes
Arrow_Actor
Arrow_Base
Arrow_Enemy
Game_Actor
Game_Actors
Game_BattleAct
Game_Battler
Game_Character
Game_Common
Game_Enemy
Game_Event
Game_Map
Game_Party
Game_Picture
Game_Player
Game_Screen
Game_SlfSwitch
Game_Switches
Game_System
Game_Troop
Game_Variables
Interpreter
Scene_Debug
Scene_End
Scene_Equip
Scene_File
Scene_Gameover
Scene_Item
Scene_Load
Scene_Map
Scene_Menu
Scene_Name
Scene_Save
Scene_Shop
Scene_Skill
Scene_Status
Scene_Title
Sprite_Battler
Sprite_Character
Sprite_Picture
Sprite_Timer
Spriteset_Battle
Spriteset_Map
Window_Base
Window_Battleresult
Window_Battlestatus
Window_Command
Window_DebugLeft
Window_DebugRight
Window_EquipItem
Window_EquipLeft
Window_EquipRight
Window_Gold
Window_Help
Window_InputNumb
Window_Item
Window_MenuStatus
Window_Message
Window_NameEdit
Window_NameInput
Window_PartyCom
Window_PlayTime
Window_SaveFile
Window_Selectable
Window_ShopBuy
Window_ShopCom
Window_ShopNum
Window_ShopSell
Window_ShopStatus
Window_Skill
Window_SkillStatus
Window_Status
Window_Steps
Window_Target

Other
Class Hierarchy
Global Variables


RPG RPG Revolution
RPG RPG Revolution is your #1 stop for game development and console RPG games, as well as those created by people like you. Link to us to support us, so we may grow to be better website community for you.

RPG RPG Revolution is an Privacy Policy and Legal