#:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=: # DRG - Pixel Movement Ace # Version: 1.06 # Author : LiTTleDRAgo #:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=: ($imported ||= {})[:drg_pixel_movement_vxa] = 1.06 core = "This script needs Drago - Core Engine ver 1.52 or above" rmvxa = "This script only for VXAce" ($imported[:drg_core_engine]||0) >= 1.52 || raise(core) LiTTleDRAgo::VXA || raise(rmvxa) #============================================================================== # ** Game_Character #------------------------------------------------------------------------------ # A character class with mainly movement route and other such processing # added. It is used as a super class of Game_Player, Game_Follower, # GameVehicle, and Game_Event. #============================================================================== class Game_Character #-------------------------------------------------------------------------- # * Public Instance Variables #-------------------------------------------------------------------------- attr_accessor :pixel_movement #-------------------------------------------------------------------------- # * Constant #-------------------------------------------------------------------------- ALIASING_PIXEL = carrot do |x| [:move_straight,:move_diagonal].each do |meth| $@ || alias_method(:"#{meth}_unpixel_#{x}", :"#{meth}") define_method(:"#{meth}") do |*a| pixel_disable? ? reset_pixel && send(:"#{meth}_unpixel_#{x}",*a) : send(:"#{meth}_pixel",*a) end end end PIXEL_PASSABLE = carrot do |x,y,dir| dir == 2 ? [x.floor,y.floor,dir] : dir == 4 ? [x.ceil, y.floor,dir] : dir == 6 ? [x.floor,y.floor,dir] : dir == 8 ? [x.floor,y.ceil, dir] : nil end ALIASING_PIXEL.call(0) #-------------------------------------------------------------------------- # * Move Straight Pixel # d: Direction (2,4,6,8) # turn_ok : Allows change of direction on the spot #-------------------------------------------------------------------------- def move_straight_pixel(d, t = true) xy_pixel_correction(d) @move_succeed = passable?(*PIXEL_PASSABLE.call(@x, @y, d)) if @move_succeed set_direction(d) @x = $game_map.round_x(x_pixel_direction(@x, d)) @y = $game_map.round_y(y_pixel_direction(@y, d)) @real_x = x_pixel_direction(@x, reverse_dir(d)) @real_y = y_pixel_direction(@y, reverse_dir(d)) increase_steps elsif t set_direction(d) check_event_trigger_touch_front end end #-------------------------------------------------------------------------- # * Move Diagonally Pixel # horz: Horizontal (4 or 6) # vert: Vertical (2 or 8) #-------------------------------------------------------------------------- def move_diagonal_pixel(horz, vert) xy_pixel_correction(horz) xy_pixel_correction(vert) passable = PIXEL_PASSABLE.call(@x, @y, horz) << vert @move_succeed = diagonal_passable?(*passable) if @move_succeed @x = $game_map.round_x(x_pixel_direction(@x, horz)) @y = $game_map.round_y(y_pixel_direction(@y, vert)) @real_x = x_pixel_direction(@x, reverse_dir(horz)) @real_y = y_pixel_direction(@y, reverse_dir(vert)) increase_steps end set_direction(horz) if @direction == reverse_dir(horz) set_direction(vert) if @direction == reverse_dir(vert) end #-------------------------------------------------------------------------- # * Calculate X and Y Coordinate Shifted Half Tile in Specific Direction # (No Loop Adjustment) #-------------------------------------------------------------------------- define_method(:x_pixel_direction) {|x,d| x + (d==6 ? 0.5 : d==4 ? -0.5 : 0)} define_method(:y_pixel_direction) {|y,d| y + (d==2 ? 0.5 : d==8 ? -0.5 : 0)} #-------------------------------------------------------------------------- # * Pixel Disable #-------------------------------------------------------------------------- def pixel_disable? return true unless pixel_movement return true if @move_route_forcing return false end #-------------------------------------------------------------------------- # * reset_pixel #-------------------------------------------------------------------------- def reset_pixel xy_pixel_correction(@direction) @x, @y = @x.floor, @y.floor end #-------------------------------------------------------------------------- # * xy_pixel_correction #-------------------------------------------------------------------------- def xy_pixel_correction(direction) return if (@x + @y).is_a?(Integer) case direction when 2 unless passable?(@x.ceil, @y.ceil, 2) @x = @x.floor if passable?(@x.floor, @y.ceil, 2) end unless passable?(@x.floor, @y.ceil, 2) @x = @x.ceil if passable?(@x.ceil, @y.ceil, 2) end when 4 unless passable?(@x.floor, @y.ceil, 4) @x = @x.floor if passable?(@x.ceil, @y.ceil, 4) end unless passable?(@x.floor, @y.ceil, 4) @y = @y.floor if passable?(@x.floor,@y.floor, 4) end unless passable?(@x.floor, @y.floor, 4) @y = @y.ceil if passable?(@x.floor, @y.ceil, 4) end when 6 unless passable?(@x.floor, @y.ceil, 6) @y = @y.floor if passable?(@x.floor,@y.floor, 6) end unless passable?(@x.ceil, @y.floor, 6) @y = @y.ceil if passable?(@x.ceil, @y.ceil, 6) end when 8 unless passable?(@x.floor, @y.floor, 8) @y = @y.floor if passable?(@x.floor,@y.ceil, 8) end unless passable?(@x.ceil, @y.floor, 8) @x = @x.floor if passable?(@x.floor,@y.floor, 8) end unless passable?(@x.floor, @y.floor, 8) @x = @x.ceil if passable?(@x.ceil, @y.floor, 8) end end end end #============================================================================== # ** Game_Player #------------------------------------------------------------------------------ # This class handles the player. It includes event starting determinants and # map scrolling functions. The instance of this class is referenced by # $game_player. #============================================================================== class Game_Player #-------------------------------------------------------------------------- # * Pixel Movement #-------------------------------------------------------------------------- define_post_alias(:initialize) { @pixel_movement = true } end #============================================================================== # ** Game_Follower #------------------------------------------------------------------------------ # This class handles followers. A follower is an allied character, other than # the front character, displayed in the party. It is referenced within the # Game_Followers class. #============================================================================== if defined?(Game_Follower) class Game_Follower #------------------------------------------------------------------------- # * Pixel Movement #------------------------------------------------------------------------- define_method(:pixel_movement) do $game_player.pixel_movement && !$game_player.followers.gathering? end define_post_alias(:initialize) { @through = false } #-------------------------------------------------------------------------- # * Pursue Preceding Character #-------------------------------------------------------------------------- def chase_preceding_character unless moving? sx = distance_x_from(@preceding_character.x) sy = distance_y_from(@preceding_character.y) if $game_player.followers.gathering? && (sx+sy).is_a?(Float) [self, $game_player].reset_pixel end move = false if sx.truncate != 0 && sy.truncate != 0 move = [move_diagonal(sx > 0 ? 4 : 6, sy > 0 ? 8 : 2)] elsif sx.truncate != 0 move = [move_straight(sx > 0 ? 4 : 6)] elsif sy.truncate != 0 move = [move_straight(sy > 0 ? 8 : 2)] end if move && !moving? move_toward_character(@preceding_character) sx = distance_x_from(@preceding_character.x) sy = distance_y_from(@preceding_character.y) jump(-sx,-sy) if Math.hypot(sx,sy) > 2 end end end end end