Advertisement
LiTTleDRAgo

[RGSS3] Drago - Pixel Movement Ace

Aug 11th, 2014
896
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 8.59 KB | None | 0 0
  1. #:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:
  2. # DRG - Pixel Movement Ace
  3. # Version: 1.06
  4. # Author : LiTTleDRAgo
  5. #:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:
  6. ($imported ||= {})[:drg_pixel_movement_vxa] = 1.06
  7.  
  8. core = "This script needs Drago - Core Engine ver 1.52 or above"
  9. rmvxa = "This script only for VXAce"
  10.  
  11. ($imported[:drg_core_engine]||0) >= 1.52 || raise(core)
  12. LiTTleDRAgo::VXA                         || raise(rmvxa)
  13. #==============================================================================
  14. # ** Game_Character
  15. #------------------------------------------------------------------------------
  16. #  A character class with mainly movement route and other such processing
  17. # added. It is used as a super class of Game_Player, Game_Follower,
  18. # GameVehicle, and Game_Event.
  19. #==============================================================================
  20.  
  21. class Game_Character
  22.   #--------------------------------------------------------------------------
  23.   # * Public Instance Variables
  24.   #--------------------------------------------------------------------------
  25.   attr_accessor    :pixel_movement
  26.   #--------------------------------------------------------------------------
  27.   # * Constant
  28.   #--------------------------------------------------------------------------
  29.   ALIASING_PIXEL = carrot do |x|
  30.     [:move_straight,:move_diagonal].each do |meth|
  31.       $@ || alias_method(:"#{meth}_unpixel_#{x}", :"#{meth}")
  32.       define_method(:"#{meth}") do |*a|
  33.         pixel_disable? ? reset_pixel && send(:"#{meth}_unpixel_#{x}",*a) :
  34.         send(:"#{meth}_pixel",*a)
  35.       end
  36.     end
  37.   end
  38.   PIXEL_PASSABLE = carrot do |x,y,dir|
  39.     dir == 2 ? [x.floor,y.floor,dir] : dir == 4 ? [x.ceil, y.floor,dir] :
  40.     dir == 6 ? [x.floor,y.floor,dir] : dir == 8 ? [x.floor,y.ceil, dir] : nil
  41.   end
  42.   ALIASING_PIXEL.call(0)
  43.   #--------------------------------------------------------------------------
  44.   # * Move Straight Pixel
  45.   #     d:        Direction (2,4,6,8)
  46.   #     turn_ok : Allows change of direction on the spot
  47.   #--------------------------------------------------------------------------
  48.   def move_straight_pixel(d, t = true)  
  49.     xy_pixel_correction(d)
  50.     @move_succeed = passable?(*PIXEL_PASSABLE.call(@x, @y, d))
  51.     if @move_succeed
  52.       set_direction(d)
  53.       @x = $game_map.round_x(x_pixel_direction(@x, d))
  54.       @y = $game_map.round_y(y_pixel_direction(@y, d))
  55.       @real_x = x_pixel_direction(@x, reverse_dir(d))
  56.       @real_y = y_pixel_direction(@y, reverse_dir(d))
  57.       increase_steps
  58.     elsif t
  59.       set_direction(d)
  60.       check_event_trigger_touch_front
  61.     end
  62.   end
  63.   #--------------------------------------------------------------------------
  64.   # * Move Diagonally Pixel
  65.   #     horz:  Horizontal (4 or 6)
  66.   #     vert:  Vertical (2 or 8)
  67.   #--------------------------------------------------------------------------
  68.   def move_diagonal_pixel(horz, vert)
  69.     xy_pixel_correction(horz)
  70.     xy_pixel_correction(vert)
  71.     passable = PIXEL_PASSABLE.call(@x, @y, horz) << vert
  72.     @move_succeed = diagonal_passable?(*passable)
  73.     if @move_succeed
  74.       @x = $game_map.round_x(x_pixel_direction(@x, horz))
  75.       @y = $game_map.round_y(y_pixel_direction(@y, vert))
  76.       @real_x = x_pixel_direction(@x, reverse_dir(horz))
  77.       @real_y = y_pixel_direction(@y, reverse_dir(vert))
  78.       increase_steps
  79.     end
  80.     set_direction(horz) if @direction == reverse_dir(horz)
  81.     set_direction(vert) if @direction == reverse_dir(vert)
  82.   end
  83.   #--------------------------------------------------------------------------
  84.   # * Calculate X and Y Coordinate Shifted Half Tile in Specific Direction
  85.   #   (No Loop Adjustment)
  86.   #--------------------------------------------------------------------------
  87.   define_method(:x_pixel_direction) {|x,d| x + (d==6 ? 0.5 : d==4 ? -0.5 : 0)}
  88.   define_method(:y_pixel_direction) {|y,d| y + (d==2 ? 0.5 : d==8 ? -0.5 : 0)}
  89.   #--------------------------------------------------------------------------
  90.   # * Pixel Disable
  91.   #--------------------------------------------------------------------------
  92.   def pixel_disable?
  93.     return true unless pixel_movement  
  94.     return true if @move_route_forcing
  95.     return false
  96.   end
  97.   #--------------------------------------------------------------------------
  98.   # * reset_pixel
  99.   #--------------------------------------------------------------------------
  100.   def reset_pixel
  101.     xy_pixel_correction(@direction)
  102.     @x, @y = @x.floor, @y.floor
  103.   end
  104.   #--------------------------------------------------------------------------
  105.   # * xy_pixel_correction
  106.   #--------------------------------------------------------------------------
  107.   def xy_pixel_correction(direction)
  108.     return if (@x + @y).is_a?(Integer)
  109.     case direction
  110.     when 2
  111.       unless passable?(@x.ceil, @y.ceil, 2)
  112.         @x = @x.floor  if passable?(@x.floor, @y.ceil, 2)
  113.       end
  114.       unless passable?(@x.floor, @y.ceil, 2)
  115.         @x = @x.ceil   if passable?(@x.ceil, @y.ceil, 2)
  116.       end
  117.     when 4
  118.       unless passable?(@x.floor, @y.ceil, 4)
  119.         @x = @x.floor  if passable?(@x.ceil, @y.ceil, 4)
  120.       end
  121.       unless passable?(@x.floor, @y.ceil, 4)
  122.         @y = @y.floor  if passable?(@x.floor,@y.floor, 4)
  123.       end
  124.       unless passable?(@x.floor, @y.floor, 4)
  125.         @y = @y.ceil  if passable?(@x.floor, @y.ceil, 4)
  126.       end
  127.     when 6
  128.       unless passable?(@x.floor, @y.ceil, 6)
  129.         @y = @y.floor if passable?(@x.floor,@y.floor, 6)
  130.       end
  131.       unless passable?(@x.ceil, @y.floor, 6)
  132.         @y = @y.ceil  if passable?(@x.ceil, @y.ceil, 6)
  133.       end
  134.     when 8
  135.       unless passable?(@x.floor, @y.floor, 8)
  136.         @y = @y.floor if passable?(@x.floor,@y.ceil, 8)
  137.       end
  138.       unless passable?(@x.ceil, @y.floor, 8)
  139.         @x = @x.floor if passable?(@x.floor,@y.floor, 8)
  140.       end
  141.       unless passable?(@x.floor, @y.floor, 8)
  142.         @x = @x.ceil  if passable?(@x.ceil, @y.floor, 8)
  143.       end
  144.     end
  145.   end
  146. end
  147.  
  148. #==============================================================================
  149. # ** Game_Player
  150. #------------------------------------------------------------------------------
  151. #  This class handles the player. It includes event starting determinants and
  152. # map scrolling functions. The instance of this class is referenced by
  153. # $game_player.
  154. #==============================================================================
  155. class Game_Player
  156.   #--------------------------------------------------------------------------
  157.   # * Pixel Movement
  158.   #--------------------------------------------------------------------------
  159.   define_post_alias(:initialize)   { @pixel_movement = true }
  160. end
  161.  
  162. #==============================================================================
  163. # ** Game_Follower
  164. #------------------------------------------------------------------------------
  165. #  This class handles followers. A follower is an allied character, other than
  166. # the front character, displayed in the party. It is referenced within the
  167. # Game_Followers class.
  168. #==============================================================================
  169. if defined?(Game_Follower)
  170.   class Game_Follower
  171.     #-------------------------------------------------------------------------
  172.     # * Pixel Movement
  173.     #-------------------------------------------------------------------------
  174.     define_method(:pixel_movement) do
  175.       $game_player.pixel_movement &&
  176.       !$game_player.followers.gathering?
  177.     end
  178.     define_post_alias(:initialize) { @through = false }
  179.     #--------------------------------------------------------------------------
  180.     # * Pursue Preceding Character
  181.     #--------------------------------------------------------------------------
  182.     def chase_preceding_character
  183.       unless moving?
  184.         sx = distance_x_from(@preceding_character.x)
  185.         sy = distance_y_from(@preceding_character.y)
  186.         if $game_player.followers.gathering? && (sx+sy).is_a?(Float)
  187.           [self, $game_player].reset_pixel
  188.         end
  189.         move = false
  190.         if sx.truncate != 0 && sy.truncate != 0
  191.           move = [move_diagonal(sx > 0 ? 4 : 6, sy > 0 ? 8 : 2)]
  192.         elsif sx.truncate != 0
  193.           move = [move_straight(sx > 0 ? 4 : 6)]
  194.         elsif sy.truncate != 0
  195.           move = [move_straight(sy > 0 ? 8 : 2)]
  196.         end
  197.         if move && !moving?
  198.           move_toward_character(@preceding_character)
  199.           sx = distance_x_from(@preceding_character.x)
  200.           sy = distance_y_from(@preceding_character.y)          
  201.           jump(-sx,-sy) if Math.hypot(sx,sy) > 2
  202.         end
  203.       end
  204.     end
  205.   end  
  206. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement