Advertisement
Demonicskyers

RPG maker XP - Gąsienica v2

May 25th, 2013
1,085
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 13.26 KB | None | 0 0
  1. # Gąsienica [XP] ~ Train Actor
  2. # Copyright © 2005 fukuyama
  3. # Tłumaczenie by Ayene
  4.  
  5. #==============================================================================
  6. # KONFIGURACJA
  7. #==============================================================================
  8. module Train_Actor
  9.   # NIWIDZIALNOŚĆ? (true / false)
  10.   # Umożliwia aktywację niewidzialności bohaterów w gąsienicy
  11.   TRANSPARENT_SWITCH = false
  12.  
  13.   # PRZEŁĄCZNIK NIWIDZIALNOŚCI
  14.   # Kiedy TRANSPARENT_SWITCH jest 'true', po aktywacji tego przełącznika
  15.   # bohaterowie w gąsienicy staną się niewidzialni.
  16.   TRANSPARENT_SWITCHES_INDEX = 21
  17.  
  18.   # MAKSYMALNA ILOŚĆ BOHATERÓW W DRUŻYNIE
  19.   TRAIN_ACTOR_SIZE_MAX = 4
  20.  
  21.   # STAŁE
  22.   DOWN_LEFT = 1
  23.   DOWN_RIGHT = 3
  24.   UP_LEFT = 7
  25.   UP_RIGHT = 9
  26.   JUMP = 5
  27. end
  28.  
  29. #==============================================================================
  30. # Spriteset_Map_Module
  31. #==============================================================================
  32.  
  33. module Train_Actor
  34.  
  35.   module Spriteset_Map_Module
  36.     def setup_actor_character_sprites?
  37.       return @setup_actor_character_sprites_flag != nil
  38.     end
  39.    
  40.     def setup_actor_character_sprites(characters)
  41.       if !setup_actor_character_sprites?
  42.         for character in characters.reverse
  43.           @character_sprites.unshift(
  44.           Sprite_Character.new(@viewport1, character)
  45.           )
  46.         end
  47.         @setup_actor_character_sprites_flag = true
  48.       end
  49.     end
  50.   end
  51. end
  52.  
  53. class Spriteset_Map
  54.   include Train_Actor::Spriteset_Map_Module
  55. end
  56.  
  57. #==============================================================================
  58. # Scene_Map_Module
  59. #==============================================================================
  60.  
  61. module Train_Actor
  62.   module Scene_Map_Module
  63.     def setup_actor_character_sprites(characters)
  64.       @spriteset.setup_actor_character_sprites(characters)
  65.     end
  66.   end
  67. end
  68.  
  69. class Scene_Map
  70.   include Train_Actor::Scene_Map_Module
  71. end
  72.  
  73. #==============================================================================
  74. # Game_Party_Module
  75. #==============================================================================
  76.  
  77. module Train_Actor
  78.   module Game_Party_Module
  79.     attr_reader :characters
  80.     def actors_dead?    
  81.       for actor in actors
  82.         if actor.dead?
  83.           return true
  84.         end
  85.       end
  86.       return false
  87.     end
  88.    
  89.     def update_party_order
  90.       if not actors_dead?
  91.         return actors
  92.       end
  93.       alive_actors = []
  94.       dead_actors = []
  95.       for actor in actors
  96.         if actor.dead?
  97.           dead_actors.push actor
  98.         else
  99.           alive_actors.push actor
  100.         end
  101.       end
  102.       return alive_actors + dead_actors
  103.     end
  104.    
  105.     def setup_actor_character_sprites
  106.       if @characters.nil?
  107.         @characters = []
  108.         for i in 1 ... TRAIN_ACTOR_SIZE_MAX
  109.           @characters.push(Game_Party_Actor.new)
  110.         end
  111.       end
  112.       setup_actors = update_party_order
  113.       for i in 1 ... TRAIN_ACTOR_SIZE_MAX
  114.         @characters[i - 1].setup(setup_actors[i])
  115.       end
  116.       if $scene.class.method_defined?('setup_actor_character_sprites')
  117.         $scene.setup_actor_character_sprites(@characters)
  118.       end
  119.     end
  120.    
  121.     def update_party_actors
  122.       update_party_order
  123.       setup_actor_character_sprites
  124.       transparent = $game_player.transparent
  125.       if transparent == false
  126.         if TRANSPARENT_SWITCH
  127.         transparent = $game_switches[TRANSPARENT_SWITCHES_INDEX]
  128.         end
  129.       end
  130.       for character in @characters
  131.         character.transparent = transparent
  132.         character.move_speed = $game_player.move_speed
  133.         character.step_anime = $game_player.step_anime
  134.         character.update
  135.       end
  136.     end
  137.    
  138.     def moveto_party_actors( x, y )
  139.       setup_actor_character_sprites
  140.       for character in @characters
  141.         character.moveto( x, y )
  142.       end
  143.       if @move_list == nil
  144.         @move_list = []
  145.       end
  146.       move_list_setup
  147.     end
  148.    
  149.     def move_party_actors
  150.       if @move_list == nil
  151.         @move_list = []
  152.         move_list_setup
  153.       end
  154.       @move_list.each_index do |i|
  155.       if @characters[i] != nil
  156.         case @move_list[i].type
  157.         when Input::DOWN
  158.           @characters[i].move_down(@move_list[i].args[0])
  159.         when Input::LEFT
  160.           @characters[i].move_left(@move_list[i].args[0])
  161.         when Input::RIGHT
  162.           @characters[i].move_right(@move_list[i].args[0])
  163.         when Input::UP
  164.           @characters[i].move_up(@move_list[i].args[0])
  165.         when DOWN_LEFT
  166.           @characters[i].move_lower_left
  167.         when DOWN_RIGHT
  168.           @characters[i].move_lower_right
  169.         when UP_LEFT
  170.           @characters[i].move_upper_left
  171.         when UP_RIGHT
  172.           @characters[i].move_upper_right
  173.         when JUMP
  174.           @characters[i].jump(@move_list[i].args[0],@move_list[i].args[1])
  175.         end
  176.       end
  177.     end
  178.   end
  179.  
  180.   class Move_List_Element
  181.     def initialize(type,args)
  182.       @type = type
  183.       @args = args
  184.     end
  185.     def type() return @type end
  186.     def args() return @args end
  187.   end
  188.    
  189.   def move_list_setup
  190.     for i in 0 .. TRAIN_ACTOR_SIZE_MAX
  191.     @move_list[i] = nil
  192.     end
  193.     end
  194.     def add_move_list(type,*args)
  195.     @move_list.unshift(Move_List_Element.new(type,args)).pop
  196.     end
  197.     def move_down_party_actors(turn_enabled = true)
  198.     move_party_actors
  199.     add_move_list(Input::DOWN,turn_enabled)
  200.     end
  201.     def move_left_party_actors(turn_enabled = true)
  202.     move_party_actors
  203.     add_move_list(Input::LEFT,turn_enabled)
  204.     end
  205.     def move_right_party_actors(turn_enabled = true)
  206.     move_party_actors
  207.     add_move_list(Input::RIGHT,turn_enabled)
  208.     end
  209.     def move_up_party_actors(turn_enabled = true)
  210.     move_party_actors
  211.     add_move_list(Input::UP,turn_enabled)
  212.     end
  213.     def move_lower_left_party_actors
  214.     move_party_actors
  215.     add_move_list(DOWN_LEFT)
  216.     end
  217.     def move_lower_right_party_actors
  218.     move_party_actors
  219.     add_move_list(DOWN_RIGHT)
  220.     end
  221.     def move_upper_left_party_actors
  222.     move_party_actors
  223.     add_move_list(UP_LEFT)
  224.     end
  225.     def move_upper_right_party_actors
  226.     move_party_actors
  227.     add_move_list(UP_RIGHT)
  228.     end
  229.     def jump_party_actors(x_plus, y_plus)
  230.     move_party_actors
  231.     add_move_list(JUMP,x_plus, y_plus)
  232.     end
  233.   end
  234. end
  235.  
  236. class Game_Party
  237.   include Train_Actor::Game_Party_Module
  238. end
  239.  
  240. #==============================================================================
  241. # Game_Player_Module
  242. #==============================================================================
  243.  
  244. module Train_Actor
  245.   module Game_Player_Module
  246.     attr_reader :move_speed
  247.     attr_reader :step_anime
  248.  
  249.     def update_party_actors
  250.       $game_party.update_party_actors
  251.       $game_party.actors.each do |actor|
  252.         if actor.dead?
  253.           next
  254.         end
  255.         @character_name = actor.character_name
  256.         @character_hue = actor.character_hue
  257.         break
  258.       end
  259.     end
  260.     def update
  261.       update_party_actors
  262.       super
  263.     end
  264.    
  265.     def moveto( x, y )
  266.       $game_party.moveto_party_actors( x, y )
  267.       super( x, y )
  268.     end
  269.     def move_down(turn_enabled = true)
  270.       if passable?(@x, @y, Input::DOWN)
  271.         $game_party.move_down_party_actors(turn_enabled)
  272.       end
  273.       super(turn_enabled)
  274.     end
  275.     def move_left(turn_enabled = true)
  276.       if passable?(@x, @y, Input::LEFT)
  277.         $game_party.move_left_party_actors(turn_enabled)
  278.       end
  279.       super(turn_enabled)
  280.     end
  281.     def move_right(turn_enabled = true)
  282.       if passable?(@x, @y, Input::RIGHT)
  283.         $game_party.move_right_party_actors(turn_enabled)
  284.       end
  285.       super(turn_enabled)
  286.     end
  287.     def move_up(turn_enabled = true)
  288.       if passable?(@x, @y, Input::UP)
  289.         $game_party.move_up_party_actors(turn_enabled)
  290.       end
  291.       super(turn_enabled)
  292.     end
  293.     def move_lower_left
  294.       if (passable?(@x, @y, Input::DOWN) and passable?(@x, @y + 1, Input::LEFT)) or
  295.         (passable?(@x, @y, Input::LEFT) and passable?(@x - 1, @y, Input::DOWN))
  296.         $game_party.move_lower_left_party_actors
  297.       end
  298.       super
  299.     end
  300.     def move_lower_right
  301.       if (passable?(@x, @y, Input::DOWN) and passable?(@x, @y + 1, Input::RIGHT)) or
  302.         (passable?(@x, @y, Input::RIGHT) and passable?(@x + 1, @y, Input::DOWN))
  303.         $game_party.move_lower_right_party_actors
  304.       end
  305.       super
  306.     end
  307.     def move_upper_left
  308.       if (passable?(@x, @y, Input::UP) and passable?(@x, @y - 1, Input::LEFT)) or
  309.         (passable?(@x, @y, Input::LEFT) and passable?(@x - 1, @y, Input::UP))
  310.         $game_party.move_upper_left_party_actors
  311.       end
  312.       super
  313.     end
  314.     def move_upper_right
  315.       if (passable?(@x, @y, Input::UP) and passable?(@x, @y - 1, Input::RIGHT)) or
  316.         (passable?(@x, @y, Input::RIGHT) and passable?(@x + 1, @y, Input::UP))
  317.         $game_party.move_upper_right_party_actors
  318.       end
  319.       super
  320.     end
  321.     def jump(x_plus, y_plus)
  322.       new_x = @x + x_plus
  323.       new_y = @y + y_plus
  324.       if (x_plus == 0 and y_plus == 0) or passable?(new_x, new_y, 0)
  325.         $game_party.jump_party_actors(x_plus, y_plus)
  326.       end
  327.       super(x_plus, y_plus)
  328.     end
  329.   end
  330. end
  331.  
  332. class Game_Player
  333.   include Train_Actor::Game_Player_Module
  334. end
  335.  
  336. #==============================================================================
  337. # Game_Event_Module
  338. #==============================================================================
  339.  
  340. module Train_Actor
  341.   module Game_Event_Module  
  342.     def passable?(x, y, d)
  343.       result = super(x, y, d)
  344.       if result
  345.         new_x = x + (d == 6 ? 1 : d == 4 ? -1 : 0)
  346.         new_y = y + (d == 2 ? 1 : d == 8 ? -1 : 0)
  347.         for actor in $game_party.characters
  348.           if not actor.character_name.empty?
  349.             if actor.x == new_x and actor.y == new_y
  350.               if self != $game_player
  351.                 return false
  352.               end
  353.             end
  354.           end
  355.         end
  356.       end
  357.       return result
  358.     end
  359.   end
  360. end
  361.  
  362. class Game_Event
  363.   include Train_Actor::Game_Event_Module
  364. end
  365.  
  366. #==============================================================================
  367. # Game_Party_Actor
  368. #==============================================================================
  369.  
  370. module Train_Actor
  371.  
  372.   class Game_Party_Actor < Game_Character
  373.     attr_writer :move_speed
  374.     attr_writer :step_anime
  375.    
  376.     def initialize
  377.       super()
  378.       @through = true
  379.     end
  380.     def setup(actor)
  381.       if actor != nil and (not actor.dead?)
  382.         @character_name = actor.character_name
  383.         @character_hue = actor.character_hue
  384.       else
  385.         @character_name = ""
  386.         @character_hue = 0
  387.       end
  388.       @opacity = 255
  389.       @blend_type = 0
  390.     end
  391.    
  392.     def screen_z(height = 0)
  393.       if $game_player.x == @x and $game_player.y == @y
  394.         return $game_player.screen_z(height) - 1
  395.       end
  396.       super(height)
  397.     end
  398.  
  399.     def move_down(turn_enabled = true)
  400.       if turn_enabled
  401.         turn_down
  402.       end
  403.       if passable?(@x, @y, Input::DOWN)
  404.         turn_down
  405.         @y += 1
  406.       end
  407.     end
  408.    
  409.     def move_left(turn_enabled = true)
  410.       if turn_enabled
  411.         turn_left
  412.       end
  413.       if passable?(@x, @y, Input::LEFT)
  414.         turn_left
  415.         @x -= 1
  416.       end
  417.     end
  418.    
  419.     def move_right(turn_enabled = true)
  420.       if turn_enabled
  421.         turn_right
  422.       end
  423.       if passable?(@x, @y, Input::RIGHT)
  424.         turn_right
  425.         @x += 1
  426.       end
  427.     end
  428.    
  429.     def move_up(turn_enabled = true)
  430.       if turn_enabled
  431.         turn_up
  432.       end
  433.       if passable?(@x, @y, Input::UP)
  434.         turn_up
  435.         @y -= 1
  436.       end
  437.     end
  438.    
  439.     def move_lower_left
  440.       unless @direction_fix
  441.         @direction = (@direction == Input::RIGHT ? Input::LEFT : @direction == Input::UP ? Input::DOWN : @direction)
  442.       end
  443.       if (passable?(@x, @y, Input::DOWN) and passable?(@x, @y + 1, Input::LEFT)) or
  444.         (passable?(@x, @y, Input::LEFT) and passable?(@x - 1, @y, Input::DOWN))
  445.         @x -= 1
  446.         @y += 1
  447.       end
  448.     end
  449.    
  450.     def move_lower_right
  451.       unless @direction_fix
  452.         @direction = (@direction == Input::LEFT ? Input::RIGHT : @direction == Input::UP ? Input::DOWN : @direction)
  453.       end
  454.       if (passable?(@x, @y, Input::DOWN) and passable?(@x, @y + 1, Input::RIGHT)) or
  455.         (passable?(@x, @y, Input::RIGHT) and passable?(@x + 1, @y, Input::DOWN))
  456.         @x += 1
  457.         @y += 1
  458.       end
  459.     end
  460.    
  461.     def move_upper_left
  462.       unless @direction_fix
  463.         @direction = (@direction == Input::RIGHT ? Input::LEFT : @direction == Input::DOWN ? Input::UP : @direction)
  464.       end
  465.       if (passable?(@x, @y, Input::UP) and passable?(@x, @y - 1, Input::LEFT)) or
  466.         (passable?(@x, @y, Input::LEFT) and passable?(@x - 1, @y, Input::UP))
  467.         @x -= 1
  468.         @y -= 1
  469.       end
  470.     end
  471.    
  472.     def move_upper_right
  473.       unless @direction_fix
  474.         @direction = (@direction == Input::LEFT ? Input::RIGHT : @direction == Input::DOWN ? Input::UP : @direction)
  475.       end
  476.       if (passable?(@x, @y, Input::UP) and passable?(@x, @y - 1, Input::RIGHT)) or
  477.         (passable?(@x, @y, Input::RIGHT) and passable?(@x + 1, @y, Input::UP))
  478.         @x += 1
  479.         @y -= 1
  480.       end
  481.     end
  482.   end
  483. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement