Don't like ads? PRO users don't see any ads ;-)
Guest

Map Title

By: a guest on Jun 6th, 2012  |  syntax: Ruby  |  size: 3.44 KB  |  hits: 31  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. module Title_Map
  2.   MAP_ID = 3 # Map_ID for background
  3.   X = 5 # initial x-coordinate of player
  4.   Y = 5 # initial y-coordinate of player
  5.   GAME_X = 30 # x-coordinate for picture on screen
  6.   GAME_Y = 100 # y-coordinate for picture on screen
  7.   WINDOW_WIDTH = 160 # width of window for difficulty
  8.   DEFIC = {
  9.   # name of level => [Switch ID (no switch = 0 , value of variable]
  10.   "Easy" => [0,1],
  11.   "Normal" => [0,2],
  12.   "Hard" => [0,3],
  13.   } #<= Don't delete!
  14.   ORDER = [
  15.   "Easy",
  16.   "Normal",
  17.   "Hard",
  18.   ]
  19.   DIFFICULTY_VARIABLE = 87 # variable for saving difficulty
  20. end
  21. include Title_Map
  22. class Scene_Title
  23.   alias cmd_new_game command_new_game unless $@
  24.   alias start_map_background start unless $@
  25.   def start
  26.     start_map_background
  27.     $game_map.setup(MAP_ID)
  28.     $game_player.moveto(X,Y)
  29.     $game_player.refresh
  30.     $game_map.update
  31.     saves = Dir.glob('Save*.rvdata')
  32.     @com = []
  33.     for k in ORDER
  34.       s = false
  35.       if DEFIC[k][0] == 0
  36.         @com.push(k)
  37.       else
  38.         for as in saves
  39.           file = File.open(as,"rb")
  40.           read_data(file)
  41.           if $game_switches[DEFIC[k][0]]
  42.             s = true
  43.             file.close
  44.             break
  45.           end
  46.         end
  47.         if s
  48.           @com.push(k)
  49.         end
  50.       end
  51.     end
  52.     create_game_objects
  53.     $game_map.setup(MAP_ID)
  54.     $game_player.moveto(X,Y)
  55.     $game_player.refresh
  56.     $game_map.update
  57.     @choose_dif = Window_Command.new(WINDOW_WIDTH,@com)
  58.     @choose_dif.x = (544-160)/2
  59.     @choose_dif.y = (416-@choose_dif.height)/2
  60.     @choose_dif.active = false
  61.     @choose_dif.visible = false
  62.     @spriteset = Spriteset_Map.new
  63.     create_title_graphic
  64.   end
  65.   def read_data(file)
  66.     characters           = Marshal.load(file)
  67.     Graphics.frame_count = Marshal.load(file)
  68.     @last_bgm            = Marshal.load(file)
  69.     @last_bgs            = Marshal.load(file)
  70.     $game_system         = Marshal.load(file)
  71.     $game_message        = Marshal.load(file)
  72.     $game_switches       = Marshal.load(file)
  73.     $game_variables      = Marshal.load(file)
  74.     $game_self_switches  = Marshal.load(file)
  75.     $game_actors         = Marshal.load(file)
  76.     $game_party          = Marshal.load(file)
  77.     $game_troop          = Marshal.load(file)
  78.     $game_map            = Marshal.load(file)
  79.     $game_player         = Marshal.load(file)
  80.   end
  81.   alias create_title_graphic_map_background create_title_graphic unless $@
  82.   def create_title_graphic
  83.     create_title_graphic_map_background
  84.     @sprite.x = GAME_X
  85.     @sprite.y = GAME_Y
  86.   end
  87.   alias update_map_background update unless $@
  88.   def update
  89.     if @command_window.active
  90.       update_map_background
  91.     else
  92.       @choose_dif.update
  93.       if Input.trigger?(Input::C)
  94.         Sound.play_decision
  95.         $game_variables[DIFFICULTY_VARIABLE] = DEFIC[ @com[@choose_dif.index] ][1]
  96.         cmd_new_game
  97.       elsif Input.trigger?(Input::B)
  98.         @choose_dif.active = false
  99.         @choose_dif.visible = false
  100.         @command_window.active = true
  101.         @command_window.visible = true
  102.       end
  103.     end
  104.     $game_map.update
  105.     @spriteset.update
  106.   end
  107.   alias terminate_map_background terminate unless $@
  108.   def terminate
  109.     terminate_map_background
  110.     @spriteset.dispose
  111.     @choose_dif.dispose
  112.   end
  113.   def command_new_game
  114.     @choose_dif.active = true
  115.     @choose_dif.visible = true
  116.     @command_window.active = false
  117.     @command_window.visible = false
  118.   end
  119. end