Advertisement
Guest User

Show mini-Chars in vehicles (RPG MAKER VX ACE)

a guest
Mar 7th, 2016
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 5.47 KB | None | 0 0
  1. #==============================================================================
  2. class Game_Vehicle < Game_Character
  3.     #----------------------------------------------------------------------------
  4.  
  5.   # ============================== CONFIGURATION ==============================
  6.     MAX_PLAYER_TO_SHOW_IN_VEHICLE = 2 # máximos minichars dibujados de tu party
  7.     MINI_PLAYER_IN_BOAT = true # Muestra minichars sobre botes
  8.     MINI_PLAYER_IN_AIRSHIP = true # Muestra minichars en aviones
  9.     MINI_PLAYER_IN_SHIP = true # Muestra minichars en barcos
  10.     MOVEMENT_IN_BOAT = true # Anima minichars en botes
  11.     MOVEMENT_IN_SHIP = true # Anima minichars en barcos
  12.     MOVEMENT_IN_AIRSHIP = true # Anima minichars en Aviones
  13.     # Animaciones para los diferentes vehículos
  14.     BOAT_MINICHARS_ANIMATION = [0,1,1,0,0,0,-1,-1,-1,0,0,0,1]
  15.     SHIP_MINICHARS_ANIMATION = [0,1,1,0,0,0,-1,-1,-1,0,0,0,1]
  16.     AIRSHIP_MINICHARS_ANIMATION = [0,1,1,0,0,0,-1,-1,-1,0,0,0,1]
  17.   # ============================ END CONFIGURATION ============================
  18.  
  19.   #----------------------------------------------------------------------------
  20.   alias refresh_newold refresh unless $@
  21.     #----------------------------------------------------------------------------
  22.     def refresh
  23.     refresh_newold
  24.     unless @driving
  25.         dispose_mini_actors
  26.     end
  27.     end
  28.     #----------------------------------------------------------------------------
  29.     alias get_off_newold get_off unless $@
  30.     #----------------------------------------------------------------------------
  31.     def get_off
  32.     dispose_mini_actors
  33.     get_off_newold
  34.     end
  35.     #----------------------------------------------------------------------------
  36.     alias get_on_newold get_on unless $@
  37.     #----------------------------------------------------------------------------
  38.     def get_on
  39.     get_on_newold
  40.     if @type == :airship
  41.         @initial_up = [32,30,28,26,24,22,20,18,16,14,12,10,8,4,2]
  42.     end
  43.     if @movement_mini_actors.nil?
  44.         if @type == :boat
  45.          @movement_mini_actors = [0,BOAT_MINICHARS_ANIMATION]
  46.         elsif @type == :airship
  47.         @movement_mini_actors = [0,AIRSHIP_MINICHARS_ANIMATION]
  48.         else
  49.         @movement_mini_actors = [0,SHIP_MINICHARS_ANIMATION]
  50.         end
  51.     end
  52.     @movement_mini_actors[0] = 0
  53.     end
  54.     #----------------------------------------------------------------------------
  55.     def dispose_mini_actors
  56.     unless @mini_actors.nil?
  57.         @mini_actors.each {|sprite| sprite.bitmap.dispose; sprite.dispose}
  58.         @mini_actors = nil
  59.     end
  60.     end
  61.     #----------------------------------------------------------------------------
  62.     alias new_update_newold update unless $@
  63.     #----------------------------------------------------------------------------
  64.     def update
  65.     new_update_newold
  66.     if @driving and ((@type == :boat and MINI_PLAYER_IN_BOAT) or
  67.         (@type == :airship and MINI_PLAYER_IN_AIRSHIP) or
  68.         (@type == :ship and MINI_PLAYER_IN_SHIP))
  69.         refresh_players_in_vehicle
  70.     end
  71.     end
  72.     #----------------------------------------------------------------------------
  73.     def refresh_players_in_vehicle
  74.     return unless SceneManager.scene.is_a?(Scene_Map)
  75.     dispose_mini_actors
  76.     actors = []
  77.     x = y = 0
  78.     mod = 20/MAX_PLAYER_TO_SHOW_IN_VEHICLE
  79.     if @type == :boat
  80.         modX = modY = 0
  81.     elsif @type == :airship
  82.         modX = 0; modY = -42
  83.     else
  84.         modX = 0; modY = 6
  85.     end
  86.     if not @initial_up.nil? and Graphics.frame_count % 2 != 0
  87.         modY += @initial_up.shift
  88.         @initial_up = nil if @initial_up.size == 0
  89.     elsif not @initial_up.nil?
  90.         modY += @initial_up[0]
  91.     end
  92.     for i in 0...MAX_PLAYER_TO_SHOW_IN_VEHICLE
  93.         actor = $game_party.members[i]
  94.         next if actor.nil?
  95.         s = Sprite.new(Viewport.new)
  96.         s.x = (@real_x-$game_map.display_x)*32 + x + modX
  97.         s.y = (@real_y-$game_map.display_y)*32 + y + modY
  98.         s.bush_depth = 2; s.bush_opacity = 160
  99.         case @direction
  100.         when 2; y -= mod;
  101.         if @type == :boat or @type == :airship
  102.             s.ox = -8; s.oy = -5;    
  103.         else
  104.             s.ox = -8; s.oy = 0;
  105.         end
  106.         when 4; s.ox = -4; s.oy = 0;    x += mod;
  107.         when 6; s.ox = -12; s.oy = 0;    x -= mod;
  108.         when 8; y += mod;
  109.         if @type == :boat or @type == :airship
  110.             s.ox = -8; s.oy = 3;     
  111.         else
  112.             s.ox = -8; s.oy = 10;
  113.         end
  114.         end
  115.         if [2,8].include?(@direction)
  116.         s.y += @movement_mini_actors[1][@movement_mini_actors[0]]
  117.         else
  118.         s.x += @movement_mini_actors[1][@movement_mini_actors[0]]
  119.         end
  120.         s.z = 1000
  121.         s.bitmap = get_actor_bitmap(actor)
  122.         actors << s
  123.     end
  124.     if actors.size > 0
  125.         @mini_actors = actors
  126.     end
  127.     if (Graphics.frame_count % 3 == 0 and   @type == :boat and MOVEMENT_IN_BOAT) or
  128.         (Graphics.frame_count % 12 == 0 and @type == :ship and MOVEMENT_IN_SHIP) or
  129.         (Graphics.frame_count % 8 == 0 and  @type == :airship and MOVEMENT_IN_AIRSHIP)
  130.         @movement_mini_actors[0] += 1
  131.         @movement_mini_actors[0] = 1 if @movement_mini_actors[0] >=
  132.         @movement_mini_actors[1].size
  133.     end
  134.     end
  135.     #----------------------------------------------------------------------------
  136.     def get_actor_bitmap(actor)
  137.     character_name = actor.character_name
  138.     index   = actor.character_index
  139.     bitmap = Cache.character(character_name)
  140.     sign = character_name[/^[\!\$]./]
  141.     if sign && sign.include?('$')
  142.         cw = bitmap.width / 3
  143.         ch = bitmap.height / 4
  144.     else
  145.         cw = bitmap.width / 12
  146.         ch = bitmap.height / 8
  147.     end
  148.     dest = Bitmap.new(16,16)
  149.     pattern = 1#actor.pattern < 3 ? actor.pattern : 1
  150.     sx = (index % 4 * 3 + pattern) * cw
  151.     sy = (index / 4 * 4 + (@direction - 2) / 2) * ch
  152.     dest.stretch_blt(dest.rect,bitmap,Rect.new(sx, sy, cw, ch))
  153.     dest
  154.     end
  155.     #----------------------------------------------------------------------------
  156. end
  157. #==============================================================================
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement