Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Object
- def each_var
- self.instance_variables.each do |varsymb|
- yield self.instance_variable_get(varsymb)
- end
- end
- end
- module Theo
- module Movement
- class Move_Object
- def initialize(obj)
- @obj = obj
- clear_move_info
- end
- def clear_move_info
- @to_x = -1
- @to_y = -1
- @real_x = 0.0
- @real_y = 0.0
- @x_speed = 0.0
- @y_speed = 0.0
- @jump = 0.0
- @jump_interval = 0.0
- @offset = 0
- end
- def move_to(x,y,jump,duration)
- @to_x = x
- @to_y = y
- @real_x = @obj.x.to_f
- @real_y = @obj.y.to_f
- determine_speed(duration,jump)
- end
- def determine_speed(duration,jump)
- @x_speed = (@to_x - @obj.x) / duration.to_f
- @y_speed = (@to_y - @obj.y) / duration.to_f
- @jump = jump.to_f
- @jump_interval = @jump/(duration/2.0)
- end
- def moving?
- return false if @to_x == -1 && @to_y == -1
- result = @obj.x != @to_x || @obj.y != @to_y
- return result
- end
- def update_move
- @real_x += @x_speed
- @real_y += @y_speed
- @obj.x = @real_x.round
- @obj.y = @real_y.round + @offset.round
- @jump -= @jump_interval
- @offset -= @jump
- clear_move_info unless moving?
- end
- end
- def initialize(*args)
- super(*args)
- init_move_obj
- end
- def init_move_obj
- @move_obj = {}
- end
- def can_move?(obj)
- return obj.is_a?(Window) || obj.is_a?(Sprite)
- end
- def set_obj(obj)
- @move_obj[obj] = Move_Object.new(obj) if can_move?(obj)
- end
- def del_obj(obj)
- @move_obj.delete(obj)
- end
- def move_to(obj,x,y,jump = 0.0,duration = Graphics.frame_rate)
- return unless can_move?(obj)
- set_obj(obj) unless @move_obj.include?(obj)
- @move_obj[obj].move_to(x,y,jump,duration)
- end
- def update_move_obj
- @move_obj.each_value do |object|
- object.update_move if object.moving?
- end
- end
- def is_moving?(obj)
- return false unless @move_obj.include?(obj)
- return @move_obj[obj].moving?
- end
- end
- end
- class Scene_Base
- include Theo::Movement
- alias theolized_basic_start start
- def start
- theolized_basic_start
- self.each_var do |ivar|
- set_obj(ivar)
- end
- end
- def update
- update_basic
- update_move_obj
- if Input.trigger?(:CTRL)
- self.each_var do |ivar|
- next unless ivar.is_a?(Window) || ivar.is_a?(Sprite)
- next if is_moving?(ivar)
- x_switch = Graphics.width == ivar.width
- y_switch = Graphics.height == ivar.height
- x = x_switch ? 0 : rand(Graphics.width - ivar.width)
- y = y_switch ? 0 : rand(Graphics.height - ivar.height)
- move_to(ivar,x,y,10)
- end
- end
- end
- def system
- $game_system
- end
- def party
- $game_party
- end
- def troop
- $game_troop
- end
- def map
- $game_map
- end
- def tileset
- map.tileset
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment