Home > RGSS Script Reference > Scene_Map
Scene_Map
Inherits from: None
Description: This class handles the scene-related elements of the map, such as setting up the message window and calling various menus that would change the "Scene". Other duties, such as processing of map graphics and map events, are handled by the Game_Map class and its member objects.
class Scene_Map
# ------------------------------------
def main
@spriteset = Spriteset_Map.new
@message_window = Window_Message.new
Graphics.transition
loop do
Graphics.update
Input.update
update
if $scene != self
break
end
end
Graphics.freeze
@spriteset.dispose
@message_window.dispose
if $scene.is_a?(Scene_Title)
Graphics.transition
Graphics.freeze
end
end
# ------------------------------------
def update
loop do
$game_map.update
$game_system.map_interpreter.update
$game_player.update
$game_system.update
$game_screen.update
unless $game_temp.player_transferring
break
end
transfer_player
if $game_temp.transition_processing
break
end
end
@spriteset.update
@message_window.update
if $game_temp.gameover
$scene = Scene_Gameover.new
return
end
if $game_temp.to_title
$scene = Scene_Title.new
return
end
if $game_temp.transition_processing
$game_temp.transition_processing = false
if $game_temp.transition_name == ""
Graphics.transition(20)
else
Graphics.transition(40, "Graphics/Transitions/" +
$game_temp.transition_name)
end
end
if $game_temp.message_window_showing
return
end
if $game_player.encounter_count == 0 and $game_map.encounter_list != []
unless $game_system.map_interpreter.running? or
$game_system.encounter_disabled
$game_temp.battle_calling = true
$game_temp.battle_can_escape = true
$game_temp.battle_can_lose = false
$game_temp.battle_proc = nil
n = rand($game_map.encounter_list.size)
$game_temp.battle_troop_id = $game_map.encounter_list[n]
end
end
if Input.trigger?(Input::B)
unless $game_system.map_interpreter.running? or
$game_system.menu_disabled
$game_temp.menu_calling = true
$game_temp.menu_beep = true
end
end
if $DEBUG and Input.press?(Input::F9)
$game_temp.debug_calling = true
end
unless $game_player.moving?
if $game_temp.battle_calling
call_battle
elsif $game_temp.shop_calling
call_shop
elsif $game_temp.name_calling
call_name
elsif $game_temp.menu_calling
call_menu
elsif $game_temp.save_calling
call_save
elsif $game_temp.debug_calling
call_debug
end
end
end
# ------------------------------------
def call_battle
$game_temp.battle_calling = false
$game_temp.menu_calling = false
$game_temp.menu_beep = false
$game_player.make_encounter_count
$game_temp.map_bgm = $game_system.playing_bgm
$game_system.bgm_stop
$game_system.se_play($data_system.battle_start_se)
$game_system.bgm_play($game_system.battle_bgm)
$game_player.straighten
$scene = Scene_Battle.new
end
# ------------------------------------
def call_shop
$game_temp.shop_calling = false
$game_player.straighten
$scene = Scene_Shop.new
end
# ------------------------------------
def call_name
$game_temp.name_calling = false
$game_player.straighten
$scene = Scene_Name.new
end
# ------------------------------------
def call_menu
$game_temp.menu_calling = false
if $game_temp.menu_beep
$game_system.se_play($data_system.decision_se)
$game_temp.menu_beep = false
end
$game_player.straighten
$scene = Scene_Menu.new
end
# ------------------------------------
def call_save
$game_player.straighten
$scene = Scene_Save.new
end
# ------------------------------------
def call_debug
$game_temp.debug_calling = false
$game_system.se_play($data_system.decision_se)
$game_player.straighten
$scene = Scene_Debug.new
end
# ------------------------------------
def transfer_player
$game_temp.player_transferring = false
if $game_map.map_id != $game_temp.player_new_map_id
$game_map.setup($game_temp.player_new_map_id)
end
$game_player.moveto($game_temp.player_new_x, $game_temp.player_new_y)
case $game_temp.player_new_direction
when 2
$game_player.turn_down
when 4
$game_player.turn_left
when 6
$game_player.turn_right
when 8
$game_player.turn_up
end
$game_player.straighten
$game_map.update
@spriteset.dispose
@spriteset = Spriteset_Map.new
if $game_temp.transition_processing
$game_temp.transition_processing = false
Graphics.transition(20)
end
$game_map.autoplay
Graphics.frame_reset
Input.update
end
end
|
Spriteset: A set of map sprites, such as the viewports for each map layer, the panorama graphic, and the fog graphic.
Message_Window: A Window_Message object for showing messages.
Main
Arguments: None
Local Variables: None
How it Works: This is the main method for this class. It first sets up the spriteset and the message window. Then, we come to the familiar main loop that updates the graphics, updates the input buffer, and updates the scene itself. Once the value of $Scene has changed, the rest of the method disposes of the spriteset and message window. If the Scene is now the title screen, the graphics are frozen.
Update
Arguments: None
Local Variables: None
How it Works: This method updates the map contents and processes input from the player. The body of the method begins with a loop. This loop updates the map graphics, interpreter, player, system, and screen. Note that the interpreter is updated before the player so that the player doesn't have an opportunity to move if the conditions for one or more events became true. If the player isn't in the process of teleporting, the loop breaks and proceeds to the @spriteset.update statement. If a teleport is waiting, then the Transfer_Player method is called. If there is a transition process occuring, the loop then breaks. Once out of the loop, the spriteset and message window are updated. The next few statements are conditional checks. If the value of $game_temp.gameover is true, then control is transferred to the Game Over screen. If the value of if $game_temp.to_title is true, then control is transferred to the title screen. If a transition is pending, then the transition processing flag is cleared. If the transition name is "" (null string), then the built-in fade transition is triggered. If a name has been specified, then the transition with that name is processed. If the $game_temp.message_showing flag is set, the method returns, since none of the statements below this one should be executed if a message window is showing. The if $game_player.encounter_count == 0 and $game_map.encounter_list != [] statement checks to see if an encounter is pending because the encounter step counter has reached 0. If an encounter is pending, then the method checks to see if a non-parallel event is executing or encounters are disabled. If either is true, nothing happens. If neither are true, then a "default" battle is generated (able to escape, no defeat handler). The monster group to fight is then chosen using a random number generator. The next statement checks to see if the user has pressed "B" (cancel key). If he has, then the menu is called unless an event is running or the menu has been disabled. If the test play flag ($DEBUG) is set, then the debug menu is called if the user has pressed F9. The final part of the method checks to see if any other scenes have been called as a result of event commands such as Open Shop Window, Enemy Encounter, Open Main Menu, or Open Save Menu. If any of flags associated with calling other scenes are set, control is transferred to that scene as soon as the player finishes moving.
Call_Battle
Arguments: None
Local Variables: None
How it Works: This method calls the battle screen. First, the battle pending flag and menu call flags are cleared. The encounter count is then reset (even if this isn't a random encounter). The $game_temp.map_bgm = $game_system.playing_bgm statement saves the current map BGM so that it can be recalled when the battle concludes. The BGM is then replaced with the battle BGM declared in the System tab of the database. The player is straightened, and control is transferred to the battle screen.
Call_Shop
Arguments: None
Local Variables: None
How it Works: This method opens the shop window as a result of the "Open Shop Window" event command. It clears the Shop Called flag, straightens the player, and transfers control to the shop window.
Call_Name
Arguments: None
Local Variables: None
How it Works: This method opens the hero naming window as a result of the "Enter Hero Name" event command. It clears the Enter Hero Name flag, straightens the player, and transfers control to the naming window.
Call_Menu
Arguments: None
Local Variables: None
How it Works: This method opens the main menu as a result of the "Open Main Menu" event command being used, or the player pressing the cancel key on the map screen. It first clears the Menu Called flag. If the $game_temp.menu_beep flag is set, the decision sound effect is played and the flag is unset. Note that this flag is only set if the player called the menu by pressing the cancel key on the map screen. Calling the menu via event commands will not cause this flag to be set. The player is then straightened, and control is transferred to the menu screen.
Call_Save
Arguments: None
Local Variables: None
How it Works: This method opens the save menu as a result of the "Open Save menu" event command or choosing the "save" command from the main menu. It straightens the player, and transfers control to the save menu.
Call_Debug
Arguments: None
Local Variables: None
How it Works: This method opens the debug window when the player pressed F9 during Test Play. It clears the Debug Call flag, straightens the player, plays a decision sound effect, and transfers control to the debug window.
Transfer_Player
Arguments: None
Local Variables: None
How it Works: This method handles teleporting the player. This method differs from Game_Player#Moveto in that it supporting changing maps. First, the Player Teleporting flag is cleared. If the destination map ID differs from the current map ID, then the new map is set up. Note that in this case, the same Scene_Map object is used to contain the new map. Once the new map is set up, the Game_Player#Moveto method takes care of the intramap movement to the new X and Y coordinates. The next four statements change the player's facing if a specific facing was specified in the Teleport command. Note what happens after the map is updated. The spriteset is disposed of and a new one is created, whether the map changed or not. This is important because even if the teleport did not cause the player to change maps, the fog position and the like will be reset. The if $game_temp.transition_processing statement checks to see if a transition is processing. If one isn't, then the screen transitions on its own. The $game_map.autoplay method checks the map's automatic BGM settings, and plays the BGM that is set for the new map. The input is then updated.
|
|