class Game_Map
Maps_Depth = {}
# To add depth to a map, you must write below :
# Maps_Depth[id] = [max, min, factor, origin, default]
# id => id of the map
# max => The maximum zoom is used to limit the increase of the characters. (in %, 1 = 100%)
# min => The minimum zoom is used to limit the decrease of the characters. (in %)
# factor => The zoom factor is the value which the character zoom will be increased by when he moves of one tile verticaly. (in %)
# origin => The origin of the zoom is the location on the map where the characters will have their default zoom. (in % from the bottom)
# Below the origin the zoom increase, over it decrease.
# default => The default zoom. (in %)
#
# Example :
# Maps_Depth[1] = [2, 0.2, 0.05, 0, 1]
attr_reader :amsu_depth
alias amsu_game_map_setup setup
def setup(map_id)
if Maps_Depth.include?(map_id)
map = load_data("Data/Map%03d.rvdata" % map_id)
@amsu_depth = Maps_Depth[map_id].dup
@amsu_depth[3] = (1-@amsu_depth[3]) * (map.height-1)
else @amsu_depth = nil
end
amsu_game_map_setup(map_id)
end
end
class Game_Character
attr_reader :x2, :y2, :zoom
alias amsu_game_character_initialize initialize
def initialize
amsu_game_character_initialize
@x2, @y2, @zoom, @real_move_speed = 0, 0, 1, @move_speed
end
def moving?
return (@real_x != @x2 or @real_y != @y2)
end
alias amsu_moveto moveto
def moveto(x, y)
amsu_moveto(x, y)
@x2, @y2, @zoom, @last_real_y = x*256, y*256, 1
update_zoom
end
alias amsu_update update
def update
amsu_update
update_zoom
end
def update_jump
@jump_count -= 1
@real_x = (@real_x * @jump_count + @x2) / (@jump_count + 1)
@real_y = (@real_y * @jump_count + @y2) / (@jump_count + 1)
update_bush_depth
end
def update_move
distance = 2 ** @real_move_speed
x256 = @x*256; y256 = @y*256
@y2 = Math.max(@y2 - distance, y256) if @y2 > y256 and !passable?(@x, @y+1)
@x2 = Math.min(@x2 + distance, x256) if @x2 < x256 and !passable?(@x-1, @y)
@x2 = Math.max(@x2 - distance, x256) if @x2 > x256 and !passable?(@x+1, @y)
@y2 = Math.min(@y2 + distance, y256) if @y2 < y256 and !passable?(@x, @y-1)
@real_y = Math.min(@real_y + distance, @y2) if @y2 > @real_y
@real_x = Math.max(@real_x - distance, @x2) if @x2 < @real_x
@real_x = Math.min(@real_x + distance, @x2) if @x2 > @real_x
@real_y = Math.max(@real_y - distance, @y2) if @y2 < @real_y
update_bush_depth unless moving?
if @walk_anime
@anime_count += 1.5
elsif @step_anime
@anime_count += 1
end
end
alias amsu_move_type_random move_type_random
def move_type_random
if @move_frequency == 5
case rand(10)
when 9; @stop_count = 0
when 0; move_random(Math.max(@real_move_speed, 5))
else ; move_forward(Math.max(@real_move_speed, 5))
end
else amsu_move_type_random
end
end
alias amsu_move_type_toward_player move_type_toward_player
def move_type_toward_player
if @move_frequency == 5
if (@x - $game_player.x).abs + (@y - $game_player.y).abs < 20
then rand(6) < 4 ? move_toward_player(@real_move_speed) : move_forward(@real_move_speed)
else move_type_random
end
else amsu_move_type_toward_player
end
end
def update_zoom
if depth = $game_map.amsu_depth
if @last_real_y != @real_y
@last_real_y = @real_y
@zoom = Math.middle(depth[1], depth[4] - (depth[3]-@real_y/256.0) * depth[2], depth[0])
end
@real_move_speed = Math.middle(0, (@move_speed+(dash? ? 1 : 0))*@zoom, 8)
else @real_move_speed = Math.middle(0, @move_speed+(dash? ? 1 : 0), 8)
end
end
def move_down(turn_ok = true, speed = 8)
new_y = @y+1
unless passable?(@x, new_y)
if @y2 == @y*256
turn_down if turn_ok
check_event_trigger_touch(@x, new_y)
return @move_failed = true
else speed -= 1; new_y = @y
end
end
turn_down
if (@y = ((@y2 = Math.min(@y2+2**speed, new_y*256))/256.0).round) > $game_map.height
@y -= $game_map.height
@y2 -= $game_map.height*256
@real_y -= $game_map.height*256
end
increase_steps
@move_failed = false
end
def move_left(turn_ok = true, speed = 8)
new_x = @x-1
unless passable?(new_x, @y)
if @x2 == @x*256
turn_left if turn_ok
check_event_trigger_touch(new_x, @y)
return @move_failed = true
else speed -= 1; new_x = @x
end
end
turn_left
if (@x = ((@x2 = Math.max(@x2-2**speed, new_x*256))/256.0).round) < 0
@x += $game_map.width
@x2 += $game_map.width*256
@real_x += $game_map.width*256
end
increase_steps
@move_failed = false
end
def move_right(turn_ok = true, speed = 8)
new_x = @x+1
unless passable?(new_x, @y)
if @x2 == @x*256
turn_right if turn_ok
check_event_trigger_touch(new_x, @y)
return @move_failed = true
else speed -= 1; new_x = @x
end
end
turn_right
if (@x = ((@x2 = Math.min(@x2+2**speed, new_x*256))/256.0).round) > $game_map.width
@x -= $game_map.width
@x2 -= $game_map.width*256
@real_x -= $game_map.width*256
end
increase_steps
@move_failed = false
end
def move_up(turn_ok = true, speed = 8)
new_y = @y-1
unless passable?(@x, new_y)
if @y2 == @y*256
turn_up if turn_ok
check_event_trigger_touch(@x, new_y)
return @move_failed = true
else speed -= 1; new_y = @y
end
end
turn_up
if (@y = ((@y2 = Math.max(@y2-2**speed, new_y*256))/256.0).round) < 0
@y += $game_map.height
@y2 += $game_map.height*256
@real_y += $game_map.height*256
end
increase_steps
@move_failed = false
end
def move_lower_left(speed = 8)
las_dir = @direction
move1 = move_down(false, speed)
move2 = move_left(false, speed)
las_dir == 6 ? turn_left : las_dir == 8 ? turn_down : nil if move1 == move2
@move_failed = move1 && move2
end
def move_lower_right(speed = 8)
las_dir = @direction
move1 = move_down(false, speed)
move2 = move_right(false, speed)
las_dir == 4 ? turn_right : las_dir == 8 ? turn_down : nil if move1 == move2
@move_failed = move1 && move2
end
def move_upper_left(speed = 8)
las_dir = @direction
move1 = move_up(false, speed)
move2 = move_left(false, speed)
las_dir == 6 ? turn_left : las_dir == 2 ? turn_up : nil if move1 == move2
@move_failed = move1 && move2
end
def move_upper_right(speed = 8)
las_dir = @direction
move1 = move_up(false, speed)
move2 = move_right(false, speed)
las_dir == 4 ? turn_right : las_dir == 2 ? turn_up : nil if move1 == move2
@move_failed = move1 && move2
end
def move_random(speed = 8)
case rand(4)
when 0; move_down(false, speed)
when 1; move_left(false, speed)
when 2; move_right(false, speed)
when 3; move_up(false, speed)
end
end
def move_toward_player(speed = 8)
sx = distance_x_from_player
sy = distance_y_from_player
if sx != 0 or sy != 0
if sx.abs > sy.abs
sx > 0 ? move_left(true, speed) : move_right(true, speed)
sy > 0 ? move_up(true, speed) : move_down(true, speed) if @move_failed and sy != 0
else
sy > 0 ? move_up(true, speed) : move_down(true, speed)
sx > 0 ? move_left(true, speed) : move_right(true, speed) if @move_failed and sx != 0
end
end
end
def move_forward(speed = 8)
case @direction
when 2; move_down(false, speed)
when 4; move_left(false, speed)
when 6; move_right(false, speed)
when 8; move_up(false, speed)
end
end
alias amsu_jump jump
def jump(x_plus, y_plus)
amsu_jump(x_plus, y_plus)
@x2 += x_plus*256
@y2 += y_plus*256
end
end
class Game_Player
def move_by_input
return if $game_map.interpreter.running? or !movable?
case Input.dir8
when 1; move_lower_left(@real_move_speed)
when 2; move_down(true, @real_move_speed)
when 3; move_lower_right(@real_move_speed)
when 4; move_left(true, @real_move_speed)
when 6; move_right(true, @real_move_speed)
when 7; move_upper_left(@real_move_speed)
when 8; move_up(true, @real_move_speed)
when 9; move_upper_right(@real_move_speed)
end
end
end
class Sprite_Character
alias amsu_update update
def update
amsu_update
self.zoom_x = self.zoom_y = @tile_id == 0 ? @character.zoom : 1
end
end
module Math
def self.min(x, max) x < max ? x : max end
def self.max(x, min) x > min ? x : min end
def self.middle(min, x, max) x > min ? x < max ? x : max : min end
end