Advertisement
Guest User

Fukuyama's Caterpillar walking script

a guest
Jul 9th, 2013
1,206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 18.52 KB | None | 0 0
  1. # train_actor
  2. =begin
  3.  
  4. Caterpillar walking script
  5.  
  6. Copyright (C) 2005 fukuyama
  7.  
  8. This library is free software; you can redistribute it and/or
  9. modify it under the terms of the GNU Lesser General Public
  10. License as published by the Free Software Foundation; either
  11. version 2.1 of the License, or (at your option) any later version.
  12.  
  13. This library is distributed in the hope that it will be useful,
  14. but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  16. Lesser General Public License for more details.
  17.  
  18. You should have received a copy of the GNU Lesser General Public
  19. License along with this library; if not, write to the Free Software
  20. Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
  21.  
  22. http://www.gnu.org/licenses/lgpl.html
  23. http://www.opensource.gr.jp/lesser/lgpl.ja.html
  24.  
  25. =end
  26.  
  27. # Config.rb
  28. #==============================================================================
  29. # ■ Train_Actor::Config
  30. #------------------------------------------------------------------------------
  31. # Caterpillar movement of actor is carried out on map
  32. #==============================================================================
  33.  
  34. module Train_Actor
  35.  
  36. # ●Switch setup for transparent status
  37. # When true, switch control is used
  38. # TRANSPARENT_SWITCH = false
  39. TRANSPARENT_SWITCH = true
  40.  
  41. # ●Switch number for transparent status
  42. # When TRANSPARENT_SWITCH is true, transparency will be activated when the switch of this number is on
  43. TRANSPARENT_SWITCHES_INDEX = 20
  44.  
  45. # ●Maximum number of actors
  46. # There will be support for a large number of people in a party in the future...
  47. TRAIN_ACTOR_SIZE_MAX = 4
  48.  
  49. # Constants
  50. DOWN_LEFT  = 1
  51. DOWN_RIGHT = 3
  52. UP_LEFT    = 7
  53. UP_RIGHT   = 9
  54. JUMP       = 5
  55.  
  56. end
  57.  
  58. # rgss
  59.  
  60. # Spriteset_Map_Module.rb
  61. #==============================================================================
  62. # ■ Spriteset_Map_Module
  63. #------------------------------------------------------------------------------
  64. # Caterpillar movement of actor is carried out on map
  65. #==============================================================================
  66.  
  67. module Train_Actor
  68.  
  69. module Spriteset_Map_Module
  70.   def setup_actor_character_sprites?
  71.     return @setup_actor_character_sprites_flag != nil
  72.   end
  73.   def setup_actor_character_sprites(characters)
  74.     if !setup_actor_character_sprites?
  75.       for character in characters.reverse
  76.         @character_sprites.unshift(
  77.           Sprite_Character.new(@viewport1, character)
  78.         )
  79.       end
  80.       @setup_actor_character_sprites_flag = true
  81.    end
  82.   end
  83. end
  84.  
  85. end
  86.  
  87. class Spriteset_Map
  88.   include Train_Actor::Spriteset_Map_Module
  89. end
  90.  
  91. # Scene_Map_Module.rb
  92. #==============================================================================
  93. # ■ Scene_Map_Module
  94. #------------------------------------------------------------------------------
  95. # Caterpillar movement of actor is carried out on map
  96. #==============================================================================
  97.  
  98. module Train_Actor
  99.  
  100. module Scene_Map_Module
  101.   def setup_actor_character_sprites(characters)
  102.     @spriteset.setup_actor_character_sprites(characters)
  103.   end
  104. end
  105.  
  106. end
  107.  
  108. class Scene_Map
  109.   include Train_Actor::Scene_Map_Module
  110. end
  111.  
  112.  
  113. # Game_Party_Module.rb
  114. #==============================================================================
  115. # ■ Game_Party_Module
  116. #------------------------------------------------------------------------------
  117. # Caterpillar movement of actor is carried out on map
  118. #==============================================================================
  119.  
  120. module Train_Actor
  121.  
  122. module Game_Party_Module
  123.   attr_reader :characters
  124.   def actors_dead?
  125.     for actor in actors
  126.       if actor.dead?
  127.         return true
  128.       end
  129.     end
  130.     return false
  131.   end
  132.   def update_party_order
  133.     if not actors_dead?
  134.       return actors
  135.     end
  136.     alive_actors = []
  137.     dead_actors = []
  138.     for actor in actors
  139.       if actor.dead?
  140.         dead_actors.push actor
  141.       else
  142.         alive_actors.push actor
  143.       end
  144.     end
  145.     return alive_actors + dead_actors
  146.   end
  147.   def setup_actor_character_sprites
  148.     if @characters.nil?
  149.       @characters = []
  150.       for i in 1 ... TRAIN_ACTOR_SIZE_MAX
  151.         @characters.push(Game_Party_Actor.new)
  152.       end
  153.     end
  154.     setup_actors = update_party_order
  155.     for i in 1 ... TRAIN_ACTOR_SIZE_MAX
  156.       @characters[i - 1].setup(setup_actors[i])
  157.     end
  158.     if $scene.class.method_defined?('setup_actor_character_sprites')
  159.       $scene.setup_actor_character_sprites(@characters)
  160.     end
  161.   end
  162.   def update_party_actors
  163.     update_party_order
  164.     setup_actor_character_sprites
  165.     transparent = $game_player.transparent
  166.     if transparent == false
  167.       if TRANSPARENT_SWITCH
  168.         transparent = $game_switches[TRANSPARENT_SWITCHES_INDEX]
  169.       end
  170.     end
  171.     for character in @characters
  172.       character.transparent = transparent
  173.       character.move_speed = $game_player.move_speed
  174.       character.step_anime = $game_player.step_anime
  175.       character.update
  176.     end
  177.   end
  178.   def moveto_party_actors( x, y )
  179.     setup_actor_character_sprites
  180.     for character in @characters
  181.       character.moveto( x, y )
  182.     end
  183.     if @move_list == nil
  184.       @move_list = []
  185.     end
  186.     move_list_setup
  187.   end
  188.   def move_party_actors
  189.     if @move_list == nil
  190.       @move_list = []
  191.       move_list_setup
  192.     end
  193.     @move_list.each_index do |i|
  194.       if @characters[i] != nil
  195.         case @move_list[i].type
  196.           when Input::DOWN
  197.             @characters[i].move_down(@move_list[i].args[0])
  198.           when Input::LEFT
  199.             @characters[i].move_left(@move_list[i].args[0])
  200.           when Input::RIGHT
  201.             @characters[i].move_right(@move_list[i].args[0])
  202.           when Input::UP
  203.             @characters[i].move_up(@move_list[i].args[0])
  204.           when DOWN_LEFT
  205.             @characters[i].move_lower_left
  206.           when DOWN_RIGHT
  207.             @characters[i].move_lower_right
  208.           when UP_LEFT
  209.             @characters[i].move_upper_left
  210.           when UP_RIGHT
  211.             @characters[i].move_upper_right
  212.           when JUMP
  213.             @characters[i].jump(@move_list[i].args[0],@move_list[i].args[1])
  214.         end
  215.       end
  216.     end
  217.   end
  218.   class Move_List_Element
  219.     def initialize(type,args)
  220.       @type = type
  221.       @args = args
  222.     end
  223.     def type() return @type end
  224.     def args() return @args end
  225.   end
  226.   def move_list_setup
  227.     for i in 0 .. TRAIN_ACTOR_SIZE_MAX
  228.       @move_list[i] = nil
  229.     end
  230.   end
  231.   def add_move_list(type,*args)
  232.     @move_list.unshift(Move_List_Element.new(type,args)).pop
  233.   end
  234.   def move_down_party_actors(turn_enabled = true)
  235.     move_party_actors
  236.     add_move_list(Input::DOWN,turn_enabled)
  237.   end
  238.   def move_left_party_actors(turn_enabled = true)
  239.     move_party_actors
  240.     add_move_list(Input::LEFT,turn_enabled)
  241.   end
  242.   def move_right_party_actors(turn_enabled = true)
  243.     move_party_actors
  244.     add_move_list(Input::RIGHT,turn_enabled)
  245.   end
  246.   def move_up_party_actors(turn_enabled = true)
  247.     move_party_actors
  248.     add_move_list(Input::UP,turn_enabled)
  249.   end
  250.   def move_lower_left_party_actors
  251.     move_party_actors
  252.     add_move_list(DOWN_LEFT)
  253.   end
  254.   def move_lower_right_party_actors
  255.     move_party_actors
  256.     add_move_list(DOWN_RIGHT)
  257.   end
  258.   def move_upper_left_party_actors
  259.     move_party_actors
  260.     add_move_list(UP_LEFT)
  261.   end
  262.   def move_upper_right_party_actors
  263.     move_party_actors
  264.     add_move_list(UP_RIGHT)
  265.   end
  266.   def jump_party_actors(x_plus, y_plus)
  267.     move_party_actors
  268.     add_move_list(JUMP,x_plus, y_plus)
  269.   end
  270. end
  271.  
  272. end
  273.  
  274. class Game_Party
  275.   include Train_Actor::Game_Party_Module
  276. end
  277.  
  278. # Game_Player_Module.rb
  279. #==============================================================================
  280. # ■ Game_Player_Module
  281. #------------------------------------------------------------------------------
  282. # Caterpillar movement of actor is carried out on map
  283. #==============================================================================
  284.  
  285. module Train_Actor
  286.  
  287. module Game_Player_Module
  288.   attr_reader :move_speed
  289.   attr_reader :step_anime
  290.  
  291.   def update_party_actors
  292.     $game_party.update_party_actors
  293.     $game_party.actors.each do |actor|
  294.       if actor.dead?
  295.         next
  296.       end
  297.       @character_name = actor.character_name
  298.       @character_hue = actor.character_hue
  299.       break
  300.     end
  301.   end
  302.   def update
  303.     update_party_actors
  304.     super
  305.   end
  306.   def moveto( x, y )
  307.     $game_party.moveto_party_actors( x, y )
  308.     super( x, y )
  309.   end
  310.   def move_down(turn_enabled = true)
  311.     if passable?(@x, @y, Input::DOWN)
  312.       $game_party.move_down_party_actors(turn_enabled)
  313.     end
  314.     super(turn_enabled)
  315.   end
  316.   def move_left(turn_enabled = true)
  317.     if passable?(@x, @y, Input::LEFT)
  318.       $game_party.move_left_party_actors(turn_enabled)
  319.     end
  320.     super(turn_enabled)
  321.   end
  322.   def move_right(turn_enabled = true)
  323.     if passable?(@x, @y, Input::RIGHT)
  324.       $game_party.move_right_party_actors(turn_enabled)
  325.     end
  326.     super(turn_enabled)
  327.   end
  328.   def move_up(turn_enabled = true)
  329.     if passable?(@x, @y, Input::UP)
  330.       $game_party.move_up_party_actors(turn_enabled)
  331.     end
  332.     super(turn_enabled)
  333.   end
  334.   def move_lower_left
  335.     # When possible to move from down→left or from left→down
  336.     if (passable?(@x, @y, Input::DOWN) and passable?(@x, @y + 1, Input::LEFT)) or
  337.        (passable?(@x, @y, Input::LEFT) and passable?(@x - 1, @y, Input::DOWN))
  338.       $game_party.move_lower_left_party_actors
  339.     end
  340.     super
  341.   end
  342.   def move_lower_right
  343.     # When possible to move from down→right or from right→down
  344.     if (passable?(@x, @y, Input::DOWN) and passable?(@x, @y + 1, Input::RIGHT)) or
  345.        (passable?(@x, @y, Input::RIGHT) and passable?(@x + 1, @y, Input::DOWN))
  346.       $game_party.move_lower_right_party_actors
  347.     end
  348.     super
  349.   end
  350.   def move_upper_left
  351.     # When possible to move from up→left or from left→up
  352.     if (passable?(@x, @y, Input::UP) and passable?(@x, @y - 1, Input::LEFT)) or
  353.        (passable?(@x, @y, Input::LEFT) and passable?(@x - 1, @y, Input::UP))
  354.       $game_party.move_upper_left_party_actors
  355.     end
  356.     super
  357.   end
  358.   def move_upper_right
  359.     # When possible to move from up→right or from right→up
  360.     if (passable?(@x, @y, Input::UP) and passable?(@x, @y - 1, Input::RIGHT)) or
  361.        (passable?(@x, @y, Input::RIGHT) and passable?(@x + 1, @y, Input::UP))
  362.       $game_party.move_upper_right_party_actors
  363.     end
  364.     super
  365.   end
  366.   def jump(x_plus, y_plus)
  367.     # New coordinates are calculated
  368.     new_x = @x + x_plus
  369.     new_y = @y + y_plus
  370.     # When addition values are (0,0), it is possible to jump to the destination
  371.     if (x_plus == 0 and y_plus == 0) or passable?(new_x, new_y, 0)
  372.       $game_party.jump_party_actors(x_plus, y_plus)
  373.     end
  374.     super(x_plus, y_plus)
  375.   end
  376. end
  377.  
  378. end
  379.  
  380. class Game_Player
  381.   include Train_Actor::Game_Player_Module
  382. end
  383.  
  384. # Game_Event_Module.rb
  385. #==============================================================================
  386. # ■ Game_Event_Module
  387. #------------------------------------------------------------------------------
  388. # Caterpillar movement of actor is carried out on map
  389. #==============================================================================
  390.  
  391. module Train_Actor
  392.  
  393. module Game_Event_Module
  394.   #--------------------------------------------------------------------------
  395.   # ● Judgement determined
  396.   #     x  : X coordinates
  397.   #     y  : Y coordinates
  398.   #     d  : Direction (0,2,4,6,8)  ※ 0 = Checks if all directions are not able to be passed (for a jump)
  399.   # return : Passing is impossible (false), possible (true)
  400.   #--------------------------------------------------------------------------
  401.   def passable?(x, y, d)
  402.     result = super(x, y, d)
  403.     if result
  404.       # New coordinates are searched for
  405.       new_x = x + (d == 6 ? 1 : d == 4 ? -1 : 0)
  406.       new_y = y + (d == 2 ? 1 : d == 8 ? -1 : 0)
  407.       # Loops for actor in train
  408.       for actor in $game_party.characters
  409.         # When displayed
  410.         if not actor.character_name.empty?
  411.           # When actor's coordinates correspond to the destination
  412.           if actor.x == new_x and actor.y == new_y
  413.             # When event
  414.             if self != $game_player
  415.               # Passing is impossible
  416.               return false
  417.             end
  418.           end
  419.         end
  420.       end
  421.     end
  422.     return result
  423.   end
  424. end
  425.  
  426. end
  427.  
  428. class Game_Event
  429.   include Train_Actor::Game_Event_Module
  430. end
  431.  
  432. # Game_Party_Actor.rb
  433. #==============================================================================
  434. # ■ Game_Party_Actor
  435. #------------------------------------------------------------------------------
  436. # Caterpillar movement of actor is carried out on map
  437. #==============================================================================
  438.  
  439. module Train_Actor
  440.  
  441. class Game_Party_Actor < Game_Character
  442.   attr_writer :move_speed
  443.   attr_writer :step_anime
  444.  
  445.   def initialize
  446.     super()
  447.     @through = true
  448.   end
  449.   def setup(actor)
  450.     # The file name and hue of the character are set
  451.     if actor != nil and (not actor.dead?) # When dead, it is erased for the time being...
  452.       @character_name = actor.character_name
  453.       @character_hue = actor.character_hue
  454.     else
  455.       @character_name = ""
  456.       @character_hue = 0
  457.     end
  458.     # Opacity and blending method are initialized
  459.     @opacity = 255
  460.     @blend_type = 0
  461.   end
  462.   def screen_z(height = 0)
  463.     if $game_player.x == @x and $game_player.y == @y
  464.       return $game_player.screen_z(height) - 1
  465.     end
  466.     super(height)
  467.   end
  468.   #--------------------------------------------------------------------------
  469.   # ● Move down
  470.   #     turn_enabled : Flag that permits direction change on the spot
  471.   #--------------------------------------------------------------------------
  472.   def move_down(turn_enabled = true)
  473.     # Face down
  474.     if turn_enabled
  475.       turn_down
  476.     end
  477.     # When possible to pass
  478.     if passable?(@x, @y, Input::DOWN)
  479.       # Face down
  480.       turn_down
  481.       # Update coordinates
  482.       @y += 1
  483.     end
  484.   end
  485.   #--------------------------------------------------------------------------
  486.   # ● Move left
  487.   #     turn_enabled : Flag that permits direction change on the spot
  488.   #--------------------------------------------------------------------------
  489.   def move_left(turn_enabled = true)
  490.     # Face left
  491.     if turn_enabled
  492.       turn_left
  493.     end
  494.     # When possible to pass
  495.     if passable?(@x, @y, Input::LEFT)
  496.       # Face left
  497.       turn_left
  498.       # Update coordinates
  499.       @x -= 1
  500.     end
  501.   end
  502.   #--------------------------------------------------------------------------
  503.   # ● Move right
  504.   #     turn_enabled : Flag that permits direction change on the spot
  505.   #--------------------------------------------------------------------------
  506.   def move_right(turn_enabled = true)
  507.     # Face right
  508.     if turn_enabled
  509.       turn_right
  510.     end
  511.     # When possible to pass
  512.     if passable?(@x, @y, Input::RIGHT)
  513.       # Face right
  514.       turn_right
  515.       # Update coordinates
  516.       @x += 1
  517.     end
  518.   end
  519.   #--------------------------------------------------------------------------
  520.   # ● Move up
  521.   #     turn_enabled : Flag that permits direction change on the spot
  522.   #--------------------------------------------------------------------------
  523.   def move_up(turn_enabled = true)
  524.     # Face up
  525.     if turn_enabled
  526.       turn_up
  527.     end
  528.     # When possible to pass
  529.     if passable?(@x, @y, Input::UP)
  530.       # Face up
  531.       turn_up
  532.       # Update coordinates
  533.       @y -= 1
  534.     end
  535.   end
  536.   #--------------------------------------------------------------------------
  537.   # ● Move lower left
  538.   #--------------------------------------------------------------------------
  539.   def move_lower_left
  540.     # When no direction fixation
  541.     unless @direction_fix
  542.       # Turn left when facing right, turn down when facing up
  543.       @direction = (@direction == Input::RIGHT ? Input::LEFT : @direction == Input::UP ? Input::DOWN : @direction)
  544.     end
  545.     # When possible to move from down→left or from left→down
  546.     if (passable?(@x, @y, Input::DOWN) and passable?(@x, @y + 1, Input::LEFT)) or
  547.        (passable?(@x, @y, Input::LEFT) and passable?(@x - 1, @y, Input::DOWN))
  548.       # Update coordinates
  549.       @x -= 1
  550.       @y += 1
  551.     end
  552.   end
  553.   #--------------------------------------------------------------------------
  554.   # ● Move lower right
  555.   #--------------------------------------------------------------------------
  556.   def move_lower_right
  557.     # When no direction fixation
  558.     unless @direction_fix
  559.       # Turn right when facing left, turn down when facing up
  560.       @direction = (@direction == Input::LEFT ? Input::RIGHT : @direction == Input::UP ? Input::DOWN : @direction)
  561.     end
  562.     # When possible to move from down→right or from right→down
  563.     if (passable?(@x, @y, Input::DOWN) and passable?(@x, @y + 1, Input::RIGHT)) or
  564.        (passable?(@x, @y, Input::RIGHT) and passable?(@x + 1, @y, Input::DOWN))
  565.       # Update coordinates
  566.       @x += 1
  567.       @y += 1
  568.     end
  569.   end
  570.   #--------------------------------------------------------------------------
  571.   # ● Move upper left
  572.   #--------------------------------------------------------------------------
  573.   def move_upper_left
  574.     # When no direction fixation
  575.     unless @direction_fix
  576.       # Turn left when facing right, turn up when facing down
  577.       @direction = (@direction == Input::RIGHT ? Input::LEFT : @direction == Input::DOWN ? Input::UP : @direction)
  578.     end
  579.     # When possible to move from up→left or from left→up
  580.     if (passable?(@x, @y, Input::UP) and passable?(@x, @y - 1, Input::LEFT)) or
  581.        (passable?(@x, @y, Input::LEFT) and passable?(@x - 1, @y, Input::UP))
  582.       # Update coordinates
  583.       @x -= 1
  584.       @y -= 1
  585.     end
  586.   end
  587.   #--------------------------------------------------------------------------
  588.   # ● Move upper right
  589.   #--------------------------------------------------------------------------
  590.   def move_upper_right
  591.     # When no direction fixation
  592.     unless @direction_fix
  593.       # Turn right when facing left, turn up when facing down
  594.       @direction = (@direction == Input::LEFT ? Input::RIGHT : @direction == Input::DOWN ? Input::UP : @direction)
  595.     end
  596.     # When possible to move from up→right or from right→up
  597.     if (passable?(@x, @y, Input::UP) and passable?(@x, @y - 1, Input::RIGHT)) or
  598.        (passable?(@x, @y, Input::RIGHT) and passable?(@x + 1, @y, Input::UP))
  599.       # Update coordinates
  600.       @x += 1
  601.       @y -= 1
  602.     end
  603.   end
  604. end
  605.  
  606. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement