Advertisement
LiTTleDRAgo

[RGSS] Drago Pixel Movement 1.15

Jul 15th, 2017
708
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 16.55 KB | None | 0 0
  1. #:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:
  2. # DRG - Pixel Movement
  3. # Version: 1.15
  4. # Author : LiTTleDRAgo
  5. #:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:
  6. ($imported ||= {})[:drg_pixel_movement] = 1.15
  7. #==============================================================================
  8. #
  9. # Introduction :
  10. #
  11. #   This script makes player's movement became pixel movement.
  12. #   Event pixel movement turned off by default.
  13. #
  14. #   To activate / deactivate pixel movement
  15. #   - $game_player.pixel_movement               = true / false
  16. #   - $game_map.events[EVENT_ID].pixel_movement = true / false
  17. #
  18. #   If used in Script call
  19. #   - get_character(ID).pixel_movement = true / false
  20. #   where ID : -1 (player),
  21. #               0 (self event),
  22. #               1.. (event ID)
  23. #
  24. #==============================================================================
  25. #==============================================================================
  26. # ** Game_Character
  27. #------------------------------------------------------------------------------
  28. #  This class deals with characters. It's used as a superclass for the
  29. #  Game_Player and Game_Event classes.
  30. #==============================================================================
  31.  
  32. class Game_Character
  33.   #--------------------------------------------------------------------------
  34.   # * Public Instance Variables
  35.   #--------------------------------------------------------------------------
  36.   attr_accessor :pixel_movement, :direction_fix
  37.   attr_writer   :revise_x,       :revise_y
  38.   #--------------------------------------------------------------------------
  39.   # * Others
  40.   #--------------------------------------------------------------------------
  41.   define_method(:x_with_direction)  {|x, d| x + (d==6 ?   1 : d==4 ?   -1 : 0)}
  42.   define_method(:y_with_direction)  {|y, d| y + (d==2 ?   1 : d==8 ?   -1 : 0)}
  43.   define_method(:x_pixel_direction) {|x, d| x + (d==6 ? 0.5 : d==4 ? -0.5 : 0)}
  44.   define_method(:y_pixel_direction) {|y, d| y + (d==2 ? 0.5 : d==8 ? -0.5 : 0)}
  45.   define_method(:revise_x)          { pixel_disable? ? 0    : @revise_x ||= 0 }
  46.   define_method(:revise_y)          { pixel_disable? ? 0    : @revise_y ||= 0 }
  47.   #--------------------------------------------------------------------------
  48.   # * Constant
  49.   #--------------------------------------------------------------------------
  50.   ALIASING_PIXEL = lambda do |x|
  51.     [:move_down,:move_left,:move_right,:move_up, :move_lower_left,
  52.     :move_lower_right,:move_upper_left,:move_upper_right].each do |meth|
  53.       $@ || alias_method(:"#{meth}_unpixel_#{x}", :"#{meth}")
  54.       define_method(:"#{meth}") do |*args|
  55.         respond_to?(:"#{meth}_pixel") && !pixel_disable? ?
  56.         send(:"#{meth}_pixel",*args) :
  57.         reset_pixel && send(:"#{meth}_unpixel_#{x}",*args)
  58.       end
  59.     end
  60.   end  
  61.   #--------------------------------------------------------------------------
  62.   # * Alias Listing
  63.   #--------------------------------------------------------------------------
  64.   $@ || alias_method(:update_move_unpixel, :update_move)
  65.   $@ || alias_method(:moving_unpixel, :"moving?")
  66.   unless $Modular_Passable
  67.     $@ || alias_method(:passable_unpixel, :passable?)
  68.   else
  69.     $@ || alias_method(:passable_conditions_unpixel, :"passable_conditions?")
  70.     $@ || alias_method(:player_conditions_unpixel,   :"player_conditions?")
  71.   #--------------------------------------------------------------------------
  72.   # * Aliased method: passable_conditions?
  73.   #--------------------------------------------------------------------------
  74.     def passable_conditions?(x, y, d, new_x, new_y, event, *args)
  75.       result = passable_conditions_unpixel(x, y, d, new_x, new_y, event, *args)
  76.       unless result
  77.         if ((event.x + event.revise_x) - new_x).abs < 1 and
  78.             ((event.y + event.revise_y) - new_y).abs < 1 and
  79.               not event.through and event != self
  80.           return true
  81.         end
  82.       end
  83.       return result
  84.     end
  85.   #--------------------------------------------------------------------------
  86.   # * Aliased method: player_conditions?
  87.   #--------------------------------------------------------------------------
  88.     def player_conditions?(x, y, d, *args)
  89.       result = player_conditions_unpixel(x, y, d, *args)
  90.       return true unless result || player_collition_passable?(x,y,d)
  91.       return result
  92.     end  
  93.   end
  94.   #--------------------------------------------------------------------------
  95.   # * Aliased method: passable?
  96.   #--------------------------------------------------------------------------
  97.   unless $Modular_Passable
  98.     def passable?(x, y, d)
  99.       result = passable_unpixel(x, y, d)
  100.       unless @through || !result
  101.         return false unless pixel_disable? || passable_pixel?(x, y, d)
  102.       end
  103.       return result
  104.     end
  105.   end
  106.   #--------------------------------------------------------------------------
  107.   # * Passable Pixel
  108.   #--------------------------------------------------------------------------
  109.   def passable_pixel?(x, y, d)
  110.     event_collition_passable?(x, y, d) && player_collition_passable?(x, y, d)
  111.   end
  112.   #--------------------------------------------------------------------------
  113.   # * Determine if Collided with Events
  114.   #--------------------------------------------------------------------------
  115.   def event_collition_passable?(x, y, d)
  116.     unless @through
  117.       new_x = x_with_direction(x, d)
  118.       new_y = y_with_direction(y, d)
  119.       for event in $game_map.events.values
  120.         #----------------------------------------------------------
  121.         unless event.through || (self == event)
  122.           if ((event.x + event.revise_x) - new_x).abs < 1 and
  123.             ((event.y + event.revise_y) - new_y).abs < 1
  124.         #----------------------------------------------------------
  125.             return false if self != $game_player
  126.             return false if event.character_name != ""
  127.           end
  128.         end
  129.       end
  130.     end
  131.     return true
  132.   end
  133.   #--------------------------------------------------------------------------
  134.   # * Determine if Collided with Player
  135.   #--------------------------------------------------------------------------
  136.   def player_collition_passable?(x,y,d)
  137.     unless self == (pl = $game_player) || @through
  138.       new_x = x_with_direction(x,d)
  139.       new_y = y_with_direction(y,d)
  140.       #----------------------------------------------------------
  141.       if @character_name != "" && !pl.through &&
  142.         ((pl.x + pl.revise_x) - new_x).abs < 1 &&
  143.         ((pl.y + pl.revise_y) - new_y).abs < 1
  144.       #----------------------------------------------------------
  145.         return false
  146.       end
  147.     end
  148.     return true
  149.   end
  150.   #--------------------------------------------------------------------------
  151.   # * Aliased method: update_move
  152.   #--------------------------------------------------------------------------
  153.   def update_move
  154.     if pixel_disable?
  155.       reset_pixel && update_move_unpixel
  156.     else
  157.       distance = 2 ** @move_speed
  158.       _x,_y = (@x + revise_x), (@y + revise_y)
  159.       @real_y = [@real_y + distance, _y * 128].min if _y * 128 > @real_y
  160.       @real_x = [@real_x - distance, _x * 128].max if _x * 128 < @real_x
  161.       @real_x = [@real_x + distance, _x * 128].min if _x * 128 > @real_x
  162.       @real_y = [@real_y - distance, _y * 128].max if _y * 128 < @real_y
  163.       @anime_count += @walk_anime ? 1.5 : @step_anime ? 1 : 0
  164.     end
  165.   end
  166.   #--------------------------------------------------------------------------
  167.   # * Aliased method: moving?
  168.   #--------------------------------------------------------------------------
  169.   def moving?
  170.     if pixel_disable?
  171.       moving_unpixel
  172.     else
  173.       (@real_x != (@x + revise_x) * 128 || @real_y != (@y + revise_y) * 128)
  174.     end
  175.   end
  176.   #--------------------------------------------------------------------------
  177.   # * xy_pixel_correction
  178.   #--------------------------------------------------------------------------
  179.   def xy_pixel_correction(direction)
  180.     _x, _y = (@x + revise_x), (@y + revise_y)
  181.     case direction
  182.     when 2
  183.       if revise_x % 1 != 0
  184.         unless passable?(_x.ceil,_y.floor, 2) or passable?(_x.ceil,_y.ceil, 2)
  185.           if passable?(_x.floor,_y.floor, 2) or passable?(_x.floor,_y.ceil, 2)
  186.             @revise_x = (_x = (@x += revise_x.floor)) * 0
  187.           end
  188.         end
  189.       end
  190.       if revise_x % 1 != 0
  191.         unless passable?(_x.floor,_y.floor, 2) or passable?(_x.floor,_y.ceil, 2)
  192.           if passable?(_x.ceil,_y.floor, 2) or  passable?(_x.ceil,_y.ceil, 2)
  193.             @revise_x = (_x = (@x += revise_x.ceil)) * 0  
  194.           end
  195.         end
  196.       end
  197.     when 4
  198.       if revise_y % 1 != 0
  199.         unless passable?(_x.ceil,_y.ceil, 4) or passable?(_x.floor,_y.ceil, 4)
  200.           if passable?(_x.ceil,_y.floor, 4) or passable?(_x.floor,_y.floor, 4)
  201.             @revise_y = (_y = (@y += revise_y.floor)) * 0
  202.           end
  203.         end
  204.       end
  205.       if revise_y % 1 != 0
  206.         unless passable?(_x.ceil,_y.floor, 4) or passable?(_x.floor,_y.floor, 4)
  207.           if passable?(_x.ceil,_y.ceil, 4) or passable?(_x.floor,_y.ceil, 4)
  208.             @revise_y = (_y = (@y += revise_y.ceil)) * 0
  209.           end
  210.         end
  211.       end
  212.     when 6
  213.       if revise_y % 1 != 0
  214.         unless passable?(_x.floor,_y.ceil, 6) or passable?(_x.ceil,_y.ceil, 6)
  215.           if passable?(_x.floor,_y.floor, 6) or passable?(_x.ceil,_y.floor, 6)
  216.             @revise_y = (_y = (@y += revise_y.floor)) * 0
  217.           end
  218.         end
  219.       end
  220.       if revise_y % 1 != 0
  221.         unless passable?(_x.floor,_y.floor, 6) or passable?(_x.ceil,_y.floor, 6)
  222.           if passable?(_x.floor,_y.ceil, 6) or passable?(_x.ceil,_y.ceil, 6)
  223.             @revise_y = (_y = (@y += revise_y.ceil)) * 0
  224.           end
  225.         end
  226.       end
  227.     when 8
  228.       if revise_x % 1 != 0
  229.         unless passable?(_x.ceil,_y.ceil, 8) or passable?(_x.ceil,_y.floor, 8)
  230.           if passable?(_x.floor,_y.ceil, 8) or passable?(_x.floor,_y.floor, 8)
  231.             @revise_x = (_x = (@x += revise_x.floor)) * 0
  232.           end
  233.         end
  234.       end
  235.       if revise_x % 1 != 0
  236.         unless passable?(_x.floor,_y.ceil, 8) or passable?(_x.floor,_y.floor, 8)
  237.           if passable?(_x.ceil,_y.ceil, 8) or passable?(_x.ceil,_y.floor, 8)
  238.             @revise_x = (_x = (@x += revise_x.ceil)) * 0
  239.           end
  240.         end
  241.       end
  242.     end  
  243.     direction
  244.   end
  245.   #--------------------------------------------------------------------------
  246.   # * add_revise_coord
  247.   #--------------------------------------------------------------------------
  248.   def add_revise_coord
  249.     @revise_x % 1 == 0 && @revise_x = (@x += @revise_x.round) * 0
  250.     @revise_y % 1 == 0 && @revise_y = (@y += @revise_y.round) * 0
  251.   end
  252.   #--------------------------------------------------------------------------
  253.   # * Pixel Disable
  254.   #--------------------------------------------------------------------------
  255.   def pixel_disable?
  256.     return true unless self.pixel_movement  
  257.     return true if @move_route_forcing && @move_route.list.any? do |s|
  258.       (1..14).include?(s.code)
  259.     end
  260.     return false
  261.   end
  262.   #--------------------------------------------------------------------------
  263.   # * reset_pixel
  264.   #--------------------------------------------------------------------------
  265.   def reset_pixel
  266.     return 0 if (@revise_x ||= 0) == 0 && (@revise_y ||= 0) == 0
  267.     xy_pixel_correction(@direction)
  268.     @revise_x = (@x += revise_x.floor) * 0
  269.     @revise_y = (@y += revise_y.floor) * 0
  270.   end
  271.   #--------------------------------------------------------------------------
  272.   # * Move Down
  273.   #     turn_enabled : a flag permits direction change on that spot
  274.   #--------------------------------------------------------------------------
  275.   def move_down_pixel(turn_enabled = true)
  276.     @quarter = false
  277.     turn_enabled && turn_down
  278.     if passable?(@x, ((@y + revise_y).floor), xy_pixel_correction(2)) or
  279.        passable?(@x, ((@y + revise_y).ceil), 2)
  280.       turn_down
  281.       @revise_y = y_pixel_direction(@revise_y,2)
  282.       add_revise_coord
  283.       increase_steps
  284.     else
  285.       @revise_y = revise_y.ceil
  286.       add_revise_coord
  287.       check_event_trigger_touch(@x, y_with_direction(@y,2))
  288.     end
  289.   end
  290.   #--------------------------------------------------------------------------
  291.   # * Move Left
  292.   #     turn_enabled : a flag permits direction change on that spot
  293.   #--------------------------------------------------------------------------
  294.   def move_left_pixel(turn_enabled = true)
  295.     @quarter = false
  296.     turn_enabled && turn_left
  297.     if passable?((@x + revise_x).ceil, @y, xy_pixel_correction(4)) or
  298.        passable?((@x + revise_x).floor, @y, 4)
  299.       turn_left
  300.       @revise_x = x_pixel_direction(@revise_x,4)
  301.       add_revise_coord
  302.       increase_steps
  303.     else
  304.       @revise_x = @revise_x.floor
  305.       add_revise_coord
  306.       check_event_trigger_touch(x_with_direction(@x,4), @y)
  307.     end
  308.   end
  309.   #--------------------------------------------------------------------------
  310.   # * Move Right
  311.   #     turn_enabled : a flag permits direction change on that spot
  312.   #--------------------------------------------------------------------------
  313.   def move_right_pixel(turn_enabled = true)
  314.     @quarter = false
  315.     turn_enabled && turn_right
  316.     if passable?((@x + revise_x).floor, @y, xy_pixel_correction(6)) or
  317.        passable?((@x + revise_x).ceil, @y, 6)
  318.       turn_right
  319.       @revise_x = x_pixel_direction(@revise_x,6)
  320.       add_revise_coord
  321.       increase_steps
  322.     else
  323.       @revise_x = @revise_x.ceil
  324.       add_revise_coord
  325.       check_event_trigger_touch(x_with_direction(@x,6), @y)
  326.     end
  327.   end
  328.   #--------------------------------------------------------------------------
  329.   # * Move up
  330.   #     turn_enabled : a flag permits direction change on that spot
  331.   #--------------------------------------------------------------------------
  332.   def move_up_pixel(turn_enabled = true)
  333.     @quarter = false
  334.     turn_enabled && turn_up
  335.     if passable?(@x, (@y + revise_y).ceil, xy_pixel_correction(8)) or
  336.        passable?(@x, (@y + revise_y).floor, 8)
  337.       turn_up
  338.       @revise_y = y_pixel_direction(@revise_y, 8)
  339.       add_revise_coord
  340.       increase_steps
  341.     else
  342.       @revise_y = revise_y.floor
  343.       add_revise_coord
  344.       check_event_trigger_touch(@x, y_with_direction(@y,8))
  345.     end
  346.   end    
  347. end
  348.  
  349. #==============================================================================
  350. # ** Game_Player
  351. #------------------------------------------------------------------------------
  352. #  This class handles the player. Its functions include event starting
  353. #  determinants and map scrolling. Refer to "$game_player" for the one
  354. #  instance of this class.
  355. #==============================================================================
  356. class Game_Player
  357.   #--------------------------------------------------------------------------
  358.   # * Constant
  359.   #--------------------------------------------------------------------------
  360.   ALIASING_PIXEL.call(0)
  361.   #--------------------------------------------------------------------------
  362.   # * Alias Method
  363.   #--------------------------------------------------------------------------
  364.   $@ || alias_method(:pixel_initialize, :initialize)
  365.   #--------------------------------------------------------------------------
  366.   # * Pixel Movement
  367.   #--------------------------------------------------------------------------
  368.   def initialize(*args)
  369.     pixel_initialize(*args)
  370.     @pixel_movement = true
  371.   end
  372. end
  373.  
  374. #==============================================================================
  375. # ** Game_Event
  376. #------------------------------------------------------------------------------
  377. #  This class deals with events. It handles functions including event page
  378. #  switching via condition determinants, and running parallel process events.
  379. #  It's used within the Game_Map class.
  380. #==============================================================================
  381. class Game_Event
  382.   #--------------------------------------------------------------------------
  383.   # * Constant
  384.   #--------------------------------------------------------------------------
  385.   ALIASING_PIXEL.call(1)
  386.   #--------------------------------------------------------------------------
  387.   # * Alias Method
  388.   #--------------------------------------------------------------------------
  389.   $@ || alias_method(:pixel_initialize, :initialize)
  390.   #--------------------------------------------------------------------------
  391.   # * Pixel Movement
  392.   #--------------------------------------------------------------------------
  393.   def initialize(*args)
  394.     pixel_initialize(*args)
  395.     @pixel_movement = false
  396.   end
  397. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement