Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. #==============================================================================#
  2. #  Multiplayer.
  3. #==============================================================================#
  4. #  Plataforma: RPGMAKER VX ACE
  5. #  Dificultad: Medio
  6. #  Version   : 1.2
  7. #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~#
  8. #  21-08-2013 - Version 1.1 => Implementacion pantalla dividida.
  9. #  19-08-2013 - Version 1.1 => mejora del codigo.
  10. #  14-04-2013 - Version 1.0 => version inicial.
  11. #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~#
  12. #  Permite crear a un segundo jugador.
  13. #==============================================================================#
  14. module NeoGab
  15.   module DirPlayer2
  16. #==============================================================================#
  17. #  Configuraciones.
  18. #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++#
  19.   DOWN  = Input::Y       # S en el teclado.
  20.   LEFT  = Input::X       # A en el teclado.
  21.   RIGHT = Input::Z       # D en el teclado.
  22.   UP    = Input::R       # W en el teclado.
  23.   ENTER = Input::L       # Q en el teclado.
  24.   RUN   = Input::A       # Shift en el teclado.
  25. #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++#
  26. #  Fin de las configuraciones.
  27. #==============================================================================#
  28.   end
  29. end
  30. #==============================================================================
  31. # • Input.
  32. #==============================================================================
  33. module Input
  34.   extend self
  35.   def self.dir4_player2
  36.     return 2 if self.press?(NeoGab::DirPlayer2::DOWN)
  37.     return 4 if self.press?(NeoGab::DirPlayer2::LEFT)
  38.     return 6 if self.press?(NeoGab::DirPlayer2::RIGHT)
  39.     return 8 if self.press?(NeoGab::DirPlayer2::UP)
  40.     return 0
  41.   end
  42.   def self.dir8_player2
  43.     if self.press?(NeoGab::DirPlayer2::UP)
  44.       return 9 if self.press?(NeoGab::DirPlayer2::RIGHT)
  45.       return 7 if self.press?(NeoGab::DirPlayer2::LEFT)
  46.       return 8
  47.     end
  48.     if self.press?(NeoGab::DirPlayer2::DOWN)
  49.       return 3 if self.press?(NeoGab::DirPlayer2::RIGHT)
  50.       return 1 if self.press?(NeoGab::DirPlayer2::LEFT)
  51.       return 2
  52.     end
  53.     return 6 if self.press?(NeoGab::DirPlayer2::RIGHT)
  54.     return 4 if self.press?(NeoGab::DirPlayer2::LEFT)
  55.     return 0
  56.   end
  57. end
  58.  
  59. #==============================================================================
  60. # ■ Game Multiplayer
  61. #==============================================================================
  62. class Game_Multiplayer < Game_Player
  63.   def actor
  64.     $game_party.battle_members[1]
  65.   end
  66.   def dash?
  67.     return false if @move_route_forcing
  68.     return false if $game_map.disable_dash?
  69.     return Input.press?(NeoGab::DirPlayer2::RUN)
  70.   end
  71.   def move_by_input
  72.     return unless movable?
  73.     return if $game_map.interpreter.running?
  74.     move_straight(Input.dir4_player2) if Input.dir4_player2 > 0
  75.   end
  76.   def update_nonmoving(last_moving)
  77.     return if $game_map.interpreter.running?
  78.     if last_moving
  79.       $game_party.on_player_walk
  80.       return if check_touch_event
  81.     end
  82.     if movable? && Input.trigger?(NeoGab::DirPlayer2::ENTER)
  83.       return if check_action_event
  84.     end
  85.     update_encounter if last_moving
  86.   end
  87.   def center(x, y)
  88.     $game_map.set_display_pos_p2(x - center_x, y - center_y)
  89.   end
  90.   def moveto(x, y)
  91.     super
  92.     center(x, y)
  93.     make_encounter_count
  94.   end
  95.   def update_scroll(last_real_x, last_real_y)
  96.     ax1 = $game_map.adjust_x_p2(last_real_x)
  97.     ay1 = $game_map.adjust_y_p2(last_real_y)
  98.     ax2 = $game_map.adjust_x_p2(@real_x)
  99.     ay2 = $game_map.adjust_y_p2(@real_y)
  100.     $game_map.scroll_down_p2 (ay2 - ay1) if ay2 > ay1 && ay2 > center_y
  101.     $game_map.scroll_left_p2 (ax1 - ax2) if ax2 < ax1 && ax2 < center_x
  102.     $game_map.scroll_right_p2(ax2 - ax1) if ax2 > ax1 && ax2 > center_x
  103.     $game_map.scroll_up_p2   (ay1 - ay2) if ay2 < ay1 && ay2 < center_y
  104.   end
  105.   def collide_with_other_player?(x, y)
  106.     $game_player.collide?(x, y)
  107.   end
  108. end
  109.  
  110. #==============================================================================
  111. # ■ Game Player
  112. #==============================================================================
  113. class Game_Player < Game_Character  
  114.   alias :nmp_collidewith :collide_with_characters?
  115. #~   def center_x
  116. #~     (Graphics.width / 32 - 1) / 4.0
  117. #~   end
  118.   def center_y
  119.     (Graphics.height / 32 - 1) / 4.0
  120.   end
  121.   def perform_transfer
  122.     if transfer?
  123.       set_direction(@new_direction)
  124.       $game_player2.sync_with($game_player)
  125.       if @new_map_id != $game_map.map_id
  126.         $game_map.setup(@new_map_id)
  127.         $game_map.autoplay
  128.       end
  129.       moveto(@new_x, @new_y)
  130.       $game_player2.moveto(@new_x, @new_y)
  131.       clear_transfer_info
  132.     end
  133.   end
  134.   def start_map_event(x, y, triggers, normal)
  135.     $game_map.events_xy(x, y).each do |event|
  136.       if event.trigger_in?(triggers) && event.normal_priority? == normal
  137.         event.turn_toward_character(self)
  138.         event.start
  139.       end
  140.     end
  141.   end
  142.   def collide_with_other_player?(x, y)
  143.     $game_player2.collide?(x, y)
  144.   end
  145.   def collide_with_characters?(x, y)
  146.     return true if collide_with_other_player?(x, y)
  147.     nmp_collidewith(x, y)
  148.   end
  149. end
  150.  
  151. #==============================================================================
  152. # ■ Game Character
  153. #==============================================================================
  154. class Game_Character < Game_CharacterBase
  155.   def sync_with(target)
  156.     @x = target.x
  157.     @y = target.y
  158.     @real_x = target.real_x
  159.     @real_y = target.real_y
  160.     @direction = target.direction
  161.     update_bush_depth
  162.   end
  163. end
  164.  
  165. #==============================================================================
  166. # ■ Game_Followers
  167. #==============================================================================
  168. class Game_Followers
  169.   def initialize(leader)
  170.     @visible = $data_system.opt_followers
  171.     @gathering = false
  172.     @data = []
  173.     @data.push(Game_Follower.new(2, leader))
  174.     (3...$game_party.max_battle_members).each do |index|
  175.       @data.push(Game_Follower.new(index, @data[-1]))
  176.     end
  177.   end
  178. end
  179.  
  180. #==============================================================================
  181. # ■ DataManager.
  182. #==============================================================================
  183. module DataManager
  184.   class << self
  185.     alias :multiplayer_create_game_objects :create_game_objects
  186.     alias :multiplayer_make_save_contents :make_save_contents
  187.     alias :multiplayer_extract_save_contents :extract_save_contents
  188.   end
  189.   def self.create_game_objects
  190.     multiplayer_create_game_objects
  191.     $game_player2 = Game_Multiplayer.new
  192.   end
  193.   def self.make_save_contents
  194.     contents = multiplayer_make_save_contents
  195.     contents[:player2] = $game_player2
  196.     contents
  197.   end
  198.   def self.extract_save_contents(contents)
  199.     multiplayer_extract_save_contents(contents)
  200.     $game_player2 = contents[:player2]
  201.   end
  202.   def self.setup_new_game
  203.     create_game_objects
  204.     $game_party.setup_starting_members
  205.     $game_map.setup($data_system.start_map_id)
  206.     $game_player.moveto($data_system.start_x, $data_system.start_y)
  207.     $game_player.refresh
  208.     $game_player2.moveto($data_system.start_x, $data_system.start_y)
  209.     $game_player2.refresh
  210.     Graphics.frame_count = 0
  211.   end
  212. end
  213.  
  214. #==============================================================================
  215. # ■ Game Party.
  216. #==============================================================================
  217. class Game_Party
  218.   alias :multiplayer_add_actor :add_actor
  219.   alias :multiplayer_remove_actor :remove_actor
  220.   def add_actor(actor_id)
  221.     multiplayer_add_actor(actor_id)
  222.     $game_player2.refresh if $game_player2
  223.   end
  224.   def remove_actor(actor_id)
  225.     multiplayer_remove_actor(actor_id)
  226.     $game_player2.refresh if $game_player2
  227.   end
  228. end
  229.  
  230. #==============================================================================
  231. # ■ Scene_Menu
  232. #==============================================================================
  233. class Scene_Menu < Scene_MenuBase
  234.   alias :multiplayer_on_formation_ok :on_formation_ok
  235.   def on_formation_ok
  236.     multiplayer_on_formation_ok
  237.     $game_player2.refresh if $game_player2
  238.   end
  239. end
  240.  
  241. #==============================================================================
  242. # ■ Game Map.
  243. #==============================================================================
  244. class Game_Map
  245.   attr_accessor :display_x2
  246.   attr_accessor :display_y2
  247.   alias :nmp_initialize :initialize
  248.   def initilaize
  249.     @display_x2 = 0
  250.     @display_y2 = 0
  251.     nmp_initialize
  252.   end
  253.   alias :nmp_setup :setup
  254.   def setup(map_id)
  255.     @display_x2 = 0
  256.     @display_y2 = 0
  257.     @scroll_direction_2 = 2
  258.     @scroll_rest_2 = 0
  259.     @scroll_speed_2 = 4
  260.     nmp_setup(map_id)
  261.   end
  262.   def scroll_down_p2(distance)
  263.     if loop_vertical?
  264.       @display_y2 += distance
  265.       @display_y2 %= @map.height
  266.       @parallax_y += distance if @parallax_loop_y
  267.     else
  268.       last_y = @display_y2
  269.       @display_y2 = [@display_y2 + distance, height - screen_tile_y].min
  270.       @parallax_y += @display_y2 - last_y
  271.     end
  272.   end
  273.   def scroll_left_p2(distance)
  274.     if loop_horizontal?
  275.       @display_x2 += @map.width - distance
  276.       @display_x2 %= @map.width
  277.       @parallax_x -= distance if @parallax_loop_x
  278.     else
  279.       last_x = @display_x2
  280.       @display_x2 = [@display_x2 - distance, 0].max
  281.       @parallax_x += @display_x2 - last_x
  282.     end
  283.   end
  284.   def scroll_right_p2(distance)
  285.     if loop_horizontal?
  286.       @display_x2 += distance
  287.       @display_x2 %= @map.width
  288.       @parallax_x += distance if @parallax_loop_x
  289.     else
  290.       last_x = @display_x2
  291.       @display_x2 = [@display_x2 + distance, (width - screen_tile_x)].min
  292.       @parallax_x += @display_x2 - last_x
  293.     end
  294.   end
  295.   def scroll_up_p2(distance)
  296.     if loop_vertical?
  297.       @display_y2 += @map.height - distance
  298.       @display_y2 %= @map.height
  299.       @parallax_y -= distance if @parallax_loop_y
  300.     else
  301.       last_y = @display_y2
  302.       @display_y2 = [@display_y2 - distance, 0].max
  303.       @parallax_y += @display_y2 - last_y
  304.     end
  305.   end
  306.   def start_scroll_p2(direction, distance, speed)
  307.     @scroll_direction_2 = direction
  308.     @scroll_rest_2 = distance
  309.     @scroll_speed_2 = speed
  310.   end
  311.   def scrolling_2?
  312.     @scroll_rest_2 > 0
  313.   end
  314.   def update_scroll
  315.     return unless scrolling_2?
  316.     last_x = @display_x2
  317.     last_y = @display_y2
  318.     do_scroll_p2(@scroll_direction_2, scroll_distance_p2)
  319.     if @display_x2 == last_x && @display_y2 == last_y
  320.       @scroll_rest_2 = 0
  321.     else
  322.       @scroll_rest_2 -= scroll_distance_p2
  323.     end
  324.   end
  325.   def do_scroll_p2(direction, distance)
  326.     case direction
  327.     when 2;  scroll_down_p2 (distance)
  328.     when 4;  scroll_left_p2 (distance)
  329.     when 6;  scroll_right_p2(distance)
  330.     when 8;  scroll_up_p2   (distance)
  331.     end
  332.   end
  333.   def scroll_distance_p2
  334.     2 ** @scroll_speed_2 / 256.0
  335.   end
  336.   def set_display_pos_p2(x, y)
  337.     x = [0, [x, width - screen_tile_x].min].max unless loop_horizontal?
  338.     y = [0, [y, height - screen_tile_y].min].max unless loop_vertical?
  339.     @display_x2 = (x + width) % width
  340.     @display_y2 = (y + height) % height
  341.     @parallax_x2 = x
  342.     @parallax_y = y
  343.   end
  344.   def adjust_x_p2(x)
  345.     if loop_horizontal? && x < @display_x2 - (width - screen_tile_x) / 2
  346.       x - @display_x2 + @map.width
  347.     else
  348.       x - @display_x2
  349.     end
  350.   end
  351.   def adjust_y_p2(y)
  352.     if loop_vertical? && y < @display_y2 - (height - screen_tile_y) / 2
  353.       y - @display_y2 + @map.height
  354.     else
  355.       y - @display_y2
  356.     end
  357.   end
  358. #~   def screen_tile_x
  359. #~     Graphics.width / 64
  360. #~   end
  361.   def screen_tile_y
  362.     Graphics.height / 64
  363.   end
  364. end
  365.  
  366. #==============================================================================
  367. # ■ Game_CharacterBase.
  368. #==============================================================================
  369. class Game_CharacterBase
  370.   def screen_x_p2
  371.     $game_map.adjust_x_p2(@real_x) * 32 + 16
  372.   end
  373.   def screen_y_p2
  374.     $game_map.adjust_y_p2(@real_y) * 32 + 32 - shift_y - jump_height
  375.   end
  376.   def screen_z_p2
  377.     @priority_type * 100
  378.   end
  379.   def jumpto_tile(x, y)
  380.     jumpto(0, [x, y])
  381.   end
  382.   def jumpto(char_id, tilexy=nil)
  383.     if char_id > 0
  384.       char = $game_map.events[char_id]
  385.     elsif char_id < 0
  386.       char = $game_player2
  387.     else
  388.       char = $game_player
  389.     end  
  390.     tilexy.nil? ? condxy = [char.x, char.y] : condxy = [tilexy[0], tilexy[1]]
  391.     jx = + eval_distance(tilexy.nil? ? char : tilexy)[0] if condxy[0] >= @x
  392.     jy = - eval_distance(tilexy.nil? ? char : tilexy)[1] if condxy[1] <= @y
  393.     jx = - eval_distance(tilexy.nil? ? char : tilexy)[0] if condxy[0] <= @x
  394.     jy = - eval_distance(tilexy.nil? ? char : tilexy)[1] if condxy[1] <= @y
  395.     jx = - eval_distance(tilexy.nil? ? char : tilexy)[0] if condxy[0] <= @x
  396.     jy = + eval_distance(tilexy.nil? ? char : tilexy)[1] if condxy[1] >= @y
  397.     jx = + eval_distance(tilexy.nil? ? char : tilexy)[0] if condxy[0] >= @x
  398.     jy = + eval_distance(tilexy.nil? ? char : tilexy)[1] if condxy[1] >= @y
  399.     jump(jx, jy)
  400.   end
  401.   def eval_distance(target)
  402.     if target.is_a?(Array)
  403.       distance_x = (@x - target[0]).abs
  404.       distance_y = (@y - target[1]).abs
  405.     else
  406.       distance_x = (@x - target.x).abs
  407.       distance_y = (@y - target.y).abs
  408.     end
  409.     return [distance_x, distance_y]
  410.   end
  411. end
  412.  
  413. #==============================================================================
  414. # ■ Game_Event
  415. #==============================================================================
  416. class Game_Event < Game_Character
  417.   alias :nmp_collidewith :collide_with_characters?
  418.   def collide_with_characters?(x, y)
  419.     return true if collide_with_player2?(x, y)
  420.     nmp_collidewith(x, y)
  421.   end
  422.   def collide_with_player2?(x, y)
  423.     normal_priority? && $game_player2.collide?(x, y)
  424.   end
  425.   def lock
  426.     unless @locked
  427.       @prelock_direction = @direction
  428.       @locked = true
  429.     end
  430.   end
  431. end
  432.  
  433. #==============================================================================
  434. # ■ Scene Map.
  435. #==============================================================================
  436. class Scene_Map < Scene_Base
  437.   alias :multiplayer_map_start :start
  438.   alias :multiplayer_map_updt :update
  439.   alias :multiplayer_map_disp :dispose_spriteset
  440.   alias :multiplayer_map_updtforfade :update_for_fade
  441.   def start
  442.     super
  443.     multiplayer_map_start
  444.     @spriteset2 = Spriteset_Map2.new
  445.   end
  446.   def update
  447.     multiplayer_map_updt
  448.     $game_player2.update if $game_player2
  449.     @spriteset2.update
  450.   end
  451.   def dispose_spriteset
  452.     multiplayer_map_disp
  453.     @spriteset2.dispose
  454.   end
  455.   def update_call_menu
  456.     if $game_system.menu_disabled || $game_map.interpreter.running?
  457.       @menu_calling = false
  458.     else
  459.       @menu_calling ||= Input.trigger?(:B)
  460.       call_menu if @menu_calling && !$game_player.moving?
  461.     end
  462.   end
  463.   def update_for_fade
  464.     multiplayer_map_updtforfade
  465.     @spriteset2.update
  466.   end
  467. end
  468.  
  469. #==============================================================================
  470. # ■ Spriteset_Map.
  471. #==============================================================================
  472. class Spriteset_Map
  473.   alias :multiplayer_create_characters :create_characters
  474.   def create_characters
  475.     multiplayer_create_characters
  476.     @character_sprites.push(Sprite_Character.new(@viewport1, $game_player2))
  477.   end
  478.   def create_viewports
  479.     @viewport1 = Viewport.new(0, 0, Graphics.width, (Graphics.height/2)-1)
  480.     @viewport2 = Viewport.new(0, 0, Graphics.width, (Graphics.height/2)-1)
  481.     @viewport3 = Viewport.new(0, 0, Graphics.width, (Graphics.height/2)-1)
  482.     @viewport2.z = 50
  483.     @viewport3.z = 100
  484.   end
  485. end
  486.  
  487. #==============================================================================
  488. # ■ Spriteset_Map.
  489. #==============================================================================
  490. class Spriteset_Map2
  491.   def initialize
  492.     create_viewports
  493.     create_tilemap
  494.     create_parallax
  495.     create_characters
  496.     create_shadow
  497.     create_weather
  498.     create_timer
  499.     update
  500.   end
  501.   def create_viewports
  502.     @viewport1 = Viewport.new(0,(Graphics.height/2)+1,Graphics.width,(Graphics.height/2)-1)
  503.     @viewport2 = Viewport.new(0,(Graphics.height/2)+1,Graphics.width,(Graphics.height/2)-1)
  504.     @viewport3 = Viewport.new(0,(Graphics.height/2)+1,Graphics.width,(Graphics.height/2)-1)
  505.     @viewport2.z = 50
  506.     @viewport3.z = 100
  507.   end
  508.   def create_tilemap
  509.     @tilemap = Tilemap.new(@viewport1)
  510.     @tilemap.map_data = $game_map.data
  511.     load_tileset
  512.   end
  513.   def load_tileset
  514.     @tileset = $game_map.tileset
  515.     @tileset.tileset_names.each_with_index do |name, i|
  516.       @tilemap.bitmaps[i] = Cache.tileset(name)
  517.     end
  518.     @tilemap.flags = @tileset.flags
  519.   end
  520.   def create_parallax
  521.     @parallax = Plane.new(@viewport1)
  522.     @parallax.z = -100
  523.   end
  524.   def create_characters
  525.     @character_sprites = []
  526.     $game_map.events.values.each do |event|
  527.       @character_sprites.push(Sprite_Character2.new(@viewport1, event))
  528.     end
  529.     $game_map.vehicles.each do |vehicle|
  530.       @character_sprites.push(Sprite_Character2.new(@viewport1, vehicle))
  531.     end
  532.     $game_player.followers.reverse_each do |follower|
  533.       @character_sprites.push(Sprite_Character2.new(@viewport1, follower))
  534.     end
  535.     @character_sprites.push(Sprite_Character2.new(@viewport1, $game_player))
  536.     @character_sprites.push(Sprite_Character2.new(@viewport1, $game_player2))
  537.     @map_id = $game_map.map_id
  538.   end
  539.   def create_shadow
  540.     @shadow_sprite = Sprite.new(@viewport1)
  541.     @shadow_sprite.bitmap = Cache.system("Shadow")
  542.     @shadow_sprite.ox = @shadow_sprite.bitmap.width / 2
  543.     @shadow_sprite.oy = @shadow_sprite.bitmap.height
  544.     @shadow_sprite.z = 180
  545.   end
  546.   def create_weather
  547.     @weather = Spriteset_Weather.new(@viewport2)
  548.   end
  549.   def create_timer
  550.     @timer_sprite = Sprite_Timer.new(@viewport2)
  551.   end
  552.   def dispose
  553.     dispose_tilemap
  554.     dispose_parallax
  555.     dispose_characters
  556.     dispose_shadow
  557.     dispose_weather
  558.     dispose_timer
  559.     dispose_viewports
  560.   end
  561.   def dispose_tilemap
  562.     @tilemap.dispose
  563.   end
  564.   def dispose_parallax
  565.     @parallax.bitmap.dispose if @parallax.bitmap
  566.     @parallax.dispose
  567.   end
  568.   def dispose_characters
  569.     @character_sprites.each {|sprite| sprite.dispose }
  570.   end
  571.   def dispose_shadow
  572.     @shadow_sprite.dispose
  573.   end
  574.   def dispose_weather
  575.     @weather.dispose
  576.   end
  577.   def dispose_timer
  578.     @timer_sprite.dispose
  579.   end
  580.   def dispose_viewports
  581.     @viewport1.dispose
  582.     @viewport2.dispose
  583.     @viewport3.dispose
  584.   end
  585.   def refresh_characters
  586.     dispose_characters
  587.     create_characters
  588.   end
  589.   def update
  590.     update_tileset
  591.     update_tilemap
  592.     update_parallax
  593.     update_characters
  594.     update_shadow
  595.     update_weather
  596.     update_timer
  597.     update_viewports
  598.   end
  599.   def update_tileset
  600.     if @tileset != $game_map.tileset
  601.       load_tileset
  602.       refresh_characters
  603.     end
  604.   end
  605.   def update_tilemap
  606.     @tilemap.map_data = $game_map.data
  607.     @tilemap.ox = $game_map.display_x2 * 32
  608.     @tilemap.oy = $game_map.display_y2 * 32
  609.     @tilemap.update
  610.   end
  611.   def update_parallax
  612.     if @parallax_name != $game_map.parallax_name
  613.       @parallax_name = $game_map.parallax_name
  614.       @parallax.bitmap.dispose if @parallax.bitmap
  615.       @parallax.bitmap = Cache.parallax(@parallax_name)
  616.       Graphics.frame_reset
  617.     end
  618.     @parallax.ox = $game_map.parallax_ox(@parallax.bitmap)
  619.     @parallax.oy = $game_map.parallax_oy(@parallax.bitmap)
  620.   end
  621.   def update_characters
  622.     refresh_characters if @map_id != $game_map.map_id
  623.     @character_sprites.each {|sprite| sprite.update }
  624.   end
  625.   def update_shadow
  626.     airship = $game_map.airship
  627.     @shadow_sprite.x = airship.screen_x_p2
  628.     @shadow_sprite.y = airship.screen_y_p2 + airship.altitude
  629.     @shadow_sprite.opacity = airship.altitude * 8
  630.     @shadow_sprite.update
  631.   end
  632.   def update_weather
  633.     @weather.type = $game_map.screen.weather_type
  634.     @weather.power = $game_map.screen.weather_power
  635.     @weather.ox = $game_map.display_x2 * 32
  636.     @weather.oy = $game_map.display_y2 * 32
  637.     @weather.update
  638.   end
  639.   def update_timer
  640.     @timer_sprite.update
  641.   end
  642.   def update_viewports
  643.     @viewport1.tone.set($game_map.screen.tone)
  644.     @viewport1.ox = $game_map.screen.shake
  645.     @viewport2.color.set($game_map.screen.flash_color)
  646.     @viewport3.color.set(0, 0, 0, 255 - $game_map.screen.brightness)
  647.     @viewport1.update
  648.     @viewport2.update
  649.     @viewport3.update
  650.   end
  651. end
  652.  
  653. #==============================================================================
  654. # ■ Sprite_Character2.
  655. #==============================================================================
  656. class Sprite_Character2 < Sprite_Base
  657.   attr_accessor :character
  658.   def initialize(viewport, character = nil)
  659.     super(viewport)
  660.     @character = character
  661.     update
  662.   end
  663.   def update
  664.     super
  665.     update_bitmap
  666.     update_src_rect
  667.     update_position
  668.     update_other
  669.   end
  670.   def tileset_bitmap(tile_id)
  671.     Cache.tileset($game_map.tileset.tileset_names[5 + tile_id / 256])
  672.   end
  673.   def update_bitmap
  674.     if graphic_changed?
  675.       @tile_id = @character.tile_id
  676.       @character_name = @character.character_name
  677.       @character_index = @character.character_index
  678.       if @tile_id > 0
  679.         set_tile_bitmap
  680.       else
  681.         set_character_bitmap
  682.       end
  683.     end
  684.   end
  685.   def graphic_changed?
  686.     @tile_id != @character.tile_id ||
  687.     @character_name != @character.character_name ||
  688.     @character_index != @character.character_index
  689.   end
  690.   def set_tile_bitmap
  691.     sx = (@tile_id / 128 % 2 * 8 + @tile_id % 8) * 32;
  692.     sy = @tile_id % 256 / 8 % 16 * 32;
  693.     self.bitmap = tileset_bitmap(@tile_id)
  694.     self.src_rect.set(sx, sy, 32, 32)
  695.     self.ox = 16
  696.     self.oy = 32
  697.   end
  698.   def set_character_bitmap
  699.     self.bitmap = Cache.character(@character_name)
  700.     sign = @character_name[/^[\!\$]./]
  701.     if sign && sign.include?('$')
  702.       @cw = bitmap.width / 3
  703.       @ch = bitmap.height / 4
  704.     else
  705.       @cw = bitmap.width / 12
  706.       @ch = bitmap.height / 8
  707.     end
  708.     self.ox = @cw / 2
  709.     self.oy = @ch
  710.   end
  711.   def update_src_rect
  712.     if @tile_id == 0
  713.       index = @character.character_index
  714.       pattern = @character.pattern < 3 ? @character.pattern : 1
  715.       sx = (index % 4 * 3 + pattern) * @cw
  716.       sy = (index / 4 * 4 + (@character.direction - 2) / 2) * @ch
  717.       self.src_rect.set(sx, sy, @cw, @ch)
  718.     end
  719.   end
  720.   def update_position
  721.     self.x = @character.screen_x_p2
  722.     self.y = @character.screen_y_p2
  723.     self.z = @character.screen_z_p2
  724.   end
  725.   def update_other
  726.     self.opacity = @character.opacity
  727.     self.blend_type = @character.blend_type
  728.     self.bush_depth = @character.bush_depth
  729.     self.visible = !@character.transparent
  730.   end
  731. end