Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:
- # DRG - Pixel Movement
- # Version: 1.12
- # Author : LiTTleDRAgo
- #:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:
- ($imported ||= {})[:drg_pixel_movement] = 1.12
- #==============================================================================
- #
- # Introduction :
- #
- # This script makes player's movement became pixel movement.
- # Event pixel movement turned off by default.
- #
- # To activate / deactivate pixel movement
- # - $game_player.pixel_movement = true / false
- # - $game_map.events[ID].pixel_movement = true / false
- #
- #==============================================================================
- #==============================================================================
- # ** Game_Character
- #------------------------------------------------------------------------------
- # This class deals with characters. It's used as a superclass for the
- # Game_Player and Game_Event classes.
- #==============================================================================
- class Game_Character
- #--------------------------------------------------------------------------
- # * Public Instance Variables
- #--------------------------------------------------------------------------
- attr_accessor :pixel_movement, :direction_fix
- #--------------------------------------------------------------------------
- # * Others
- #--------------------------------------------------------------------------
- define_method(:x_with_direction) {|x, d| x + (d==6 ? 1 : d==4 ? -1 : 0)}
- define_method(:y_with_direction) {|y, d| y + (d==2 ? 1 : d==8 ? -1 : 0)}
- 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)}
- define_method(:revise_x) { pixel_disable? ? 0 : @revise_x ||= 0 }
- define_method(:revise_y) { pixel_disable? ? 0 : @revise_y ||= 0 }
- #--------------------------------------------------------------------------
- # * Constant
- #--------------------------------------------------------------------------
- ALIASING_PIXEL = lambda do |x|
- $@ || alias_method(:"update_move_unpixel_#{x}", :update_move)
- $@ || alias_method(:"moving_unpixel_#{x}", :moving?)
- [:move_down,:move_left,:move_right,:move_up].each do |meth|
- $@ || alias_method(:"#{meth}_unpixel_#{x}", :"#{meth}")
- define_method(:"#{meth}") do |*a|
- pixel_disable? ? send(:"#{meth}_unpixel_#{x}",*a) :
- send(:"#{meth}_pixel",*a)
- end
- end
- [:move_lower_left,:move_lower_right,:move_upper_left,
- :move_upper_right].each do |meth|
- $@ || alias_method(:"#{meth}_unpixel_#{x}", :"#{meth}")
- define_method(:"#{meth}") do |*a|
- reset_pixel && send(:"#{meth}_unpixel_#{x}",*a)
- end
- end
- define_method(:update_move) do |*a|
- if pixel_disable?
- reset_pixel && send(:"update_move_unpixel_#{x}",*a)
- else
- if (@x + revise_x) * 128 != @real_x && (@y + revise_y) * 128 != @real_y
- distance = 2 ** @move_speed / Math.sqrt(2)
- else
- distance = 2 ** @move_speed
- end
- if (@y + revise_y) * 128 > @real_y
- @real_y = [@real_y + distance, (@y + revise_y) * 128].min
- end
- if (@x + revise_x) * 128 < @real_x
- @real_x = [@real_x - distance, (@x + revise_x) * 128].max
- end
- if (@x + revise_x) * 128 > @real_x
- @real_x = [@real_x + distance, (@x + revise_x) * 128].min
- end
- if (@y + revise_y) * 128 < @real_y
- @real_y = [@real_y - distance, (@y + revise_y) * 128].max
- end
- if @walk_anime
- @anime_count += 1.5
- elsif @step_anime
- @anime_count += 1
- end
- end
- end
- define_method(:moving?) do |*a|
- if pixel_disable?
- send(:"moving_unpixel_#{x}",*a)
- else
- (@real_x != (@x + revise_x) * 128 || @real_y != (@y + revise_y) * 128)
- end
- end
- end
- #--------------------------------------------------------------------------
- # * xy_pixel_correction
- #--------------------------------------------------------------------------
- def xy_pixel_correction(direction)
- case direction
- when 2
- unless passable?(@x + revise_x.ceil, @y + revise_y.ceil, 2)
- if passable?(@x + @revise_x.floor, @y + @revise_y.ceil, 2)
- (@x += @revise_x.floor) && @revise_x = 0
- end
- end
- unless passable?(@x + revise_x.floor, @y + revise_y.ceil, 2)
- if passable?(@x + @revise_x.ceil, @y + @revise_y.ceil, 2)
- (@x += @revise_x.ceil) && @revise_x = 0
- end
- end
- when 4
- unless passable?(@x + revise_x.floor, @y + revise_y.ceil, 4)
- if passable?(@x + @revise_x.ceil, @y + @revise_y.ceil, 4)
- (@x += @revise_x.floor) && @revise_x = 0
- end
- end
- unless passable?(@x + revise_x.floor, @y + revise_y.ceil, 4)
- if passable?(@x + @revise_x.floor, @y + @revise_y.floor, 4)
- (@y += @revise_y.floor) && @revise_y = 0
- end
- end
- unless passable?(@x + revise_x.floor, @y + revise_y.floor, 4)
- if passable?(@x + @revise_x.floor, @y + @revise_y.ceil, 4)
- (@y += @revise_y.ceil) && @revise_y = 0
- end
- end
- when 6
- unless passable?(@x + revise_x.floor, @y + revise_y.ceil, 6)
- if passable?(@x + @revise_x.floor, @y + @revise_y.floor, 6)
- (@y += @revise_y.floor) && @revise_y = 0
- end
- end
- unless passable?(@x + revise_x.ceil, @y + revise_y.floor, 6)
- if passable?(@x + @revise_x.ceil, @y + @revise_y.ceil, 6)
- (@y += @revise_y.ceil) && @revise_y = 0
- end
- end
- when 8
- unless passable?(@x + revise_x.floor, @y + revise_y.floor, 8)
- if passable?(@x + @revise_x.floor, @y + @revise_y.ceil, 8)
- (@y += @revise_y.floor) && @revise_y = 0
- end
- end
- unless passable?(@x + revise_x.ceil, @y + revise_y.floor, 8)
- if passable?(@x + @revise_x.floor, @y + @revise_y.floor, 8)
- (@x += @revise_x.floor) && @revise_x = 0
- end
- end
- unless passable?(@x + revise_x.floor, @y + revise_y.floor, 8)
- if passable?(@x + @revise_x.ceil, @y + @revise_y.floor, 8)
- (@x += @revise_x.ceil) && @revise_x = 0
- end
- end
- end
- direction
- end
- #--------------------------------------------------------------------------
- # * add_revise_coord
- #--------------------------------------------------------------------------
- def add_revise_coord
- @revise_x % 1 == 0 && (@x += @revise_x.round) && (@revise_x = 0)
- @revise_y % 1 == 0 && (@y += @revise_y.round) && (@revise_y = 0)
- end
- #--------------------------------------------------------------------------
- # * Pixel Disable
- #--------------------------------------------------------------------------
- def pixel_disable?
- return true unless self.pixel_movement
- return true if @move_route_forcing && @move_route.list.any? do |s|
- (1..14).include?(s.code)
- end
- return false
- end
- #--------------------------------------------------------------------------
- # * reset_pixel
- #--------------------------------------------------------------------------
- def reset_pixel
- return 0 if (@revise_x ||= 0) == 0 && (@revise_y ||= 0) == 0
- xy_pixel_correction(@direction)
- @x, @y = (@x + revise_x).floor, (@y + revise_y).floor
- @revise_x = @revise_y = 0
- end
- #--------------------------------------------------------------------------
- # * Move Down
- # turn_enabled : a flag permits direction change on that spot
- #--------------------------------------------------------------------------
- def move_down_pixel(turn_enabled = true)
- @quarter = false
- turn_enabled && turn_down
- if passable?(@x, @y, xy_pixel_correction(2))
- turn_down
- @revise_y = y_pixel_direction(@revise_y,2)
- add_revise_coord
- increase_steps
- else
- check_event_trigger_touch(@x, y_with_direction(@y,2))
- end
- end
- #--------------------------------------------------------------------------
- # * Move Left
- # turn_enabled : a flag permits direction change on that spot
- #--------------------------------------------------------------------------
- def move_left_pixel(turn_enabled = true)
- @quarter = false
- turn_enabled && turn_left
- if passable?(@x, @y, xy_pixel_correction(4))
- turn_left
- @revise_x = x_pixel_direction(@revise_x,4)
- add_revise_coord
- increase_steps
- else
- check_event_trigger_touch(x_with_direction(@x,4), @y)
- end
- end
- #--------------------------------------------------------------------------
- # * Move Right
- # turn_enabled : a flag permits direction change on that spot
- #--------------------------------------------------------------------------
- def move_right_pixel(turn_enabled = true)
- @quarter = false
- turn_enabled && turn_right
- if passable?(@x, @y, xy_pixel_correction(6))
- turn_right
- @revise_x = x_pixel_direction(@revise_x,6)
- add_revise_coord
- increase_steps
- else
- check_event_trigger_touch(x_with_direction(@x,6), @y)
- end
- end
- #--------------------------------------------------------------------------
- # * Move up
- # turn_enabled : a flag permits direction change on that spot
- #--------------------------------------------------------------------------
- def move_up_pixel(turn_enabled = true)
- @quarter = false
- turn_enabled && turn_up
- if passable?(@x, @y, xy_pixel_correction(8))
- turn_up
- @revise_y = y_pixel_direction(@revise_y, 8)
- add_revise_coord
- increase_steps
- else
- check_event_trigger_touch(@x, y_with_direction(@y,8))
- end
- end
- end
- #==============================================================================
- # ** Game_Player
- #------------------------------------------------------------------------------
- # This class handles the player. Its functions include event starting
- # determinants and map scrolling. Refer to "$game_player" for the one
- # instance of this class.
- #==============================================================================
- class Game_Player
- #--------------------------------------------------------------------------
- # * Constant
- #--------------------------------------------------------------------------
- ALIASING_PIXEL.call(0)
- #--------------------------------------------------------------------------
- # * Alias Method
- #--------------------------------------------------------------------------
- $@ || alias_method(:pixel_initialize,:initialize)
- #--------------------------------------------------------------------------
- # * Pixel Movement
- #--------------------------------------------------------------------------
- def initialize(*args)
- pixel_initialize(*args)
- @pixel_movement = true
- end
- end
- #==============================================================================
- # ** Game_Event
- #------------------------------------------------------------------------------
- # This class deals with events. It handles functions including event page
- # switching via condition determinants, and running parallel process events.
- # It's used within the Game_Map class.
- #==============================================================================
- class Game_Event
- #--------------------------------------------------------------------------
- # * Constant
- #--------------------------------------------------------------------------
- ALIASING_PIXEL.call(1)
- #--------------------------------------------------------------------------
- # * Alias Method
- #--------------------------------------------------------------------------
- unless method_defined?(:pixel_check_touch)
- alias_method :pixel_initialize, :initialize
- end
- #--------------------------------------------------------------------------
- # * Pixel Movement
- #--------------------------------------------------------------------------
- def initialize(*args)
- pixel_initialize(*args)
- @pixel_movement = false
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement