module HMRS
module CONFIG
Z_DISTANCE = 100
BOTTOM_LAYER_Z = 1
ROTATION_TINT = true
DEFAULT_ROTATION_TINT_COLOR = 0
end
LAYERS_PATH = "Graphics/Layers/"
FNAME = "map%03d_%d_%d.png"
FNAME_NO_ROTATION = "map%03d_%d.png"
RDIR = [
{2 => 2, 4 => 4, 6 => 6, 8 => 8, 1 => 1, 3 => 3, 7 => 7, 9 => 9},
{2 => 6, 4 => 2, 6 => 8, 8 => 4, 1 => 7, 3 => 1, 7 => 9, 9 => 3},
{2 => 8, 4 => 6, 6 => 4, 8 => 2, 1 => 9, 3 => 7, 7 => 3, 9 => 1},
{2 => 4, 4 => 8, 6 => 2, 8 => 6, 1 => 3, 3 => 9, 7 => 1, 9 => 7},
]
CRTABLE = [
{2 => 2, 4 => 4, 6 => 6, 8 => 8, 1 => 1, 3 => 3, 7 => 7, 9 => 9},
{2 => 4, 4 => 8, 6 => 2, 8 => 6, 1 => 3, 3 => 9, 7 => 1, 9 => 7},
{2 => 8, 4 => 6, 6 => 4, 8 => 2, 1 => 9, 3 => 7, 7 => 3, 9 => 1},
{2 => 6, 4 => 2, 6 => 8, 8 => 4, 1 => 7, 3 => 1, 7 => 9, 9 => 3},
]
COMMENT_LINE = "<HMRS invisible>"
end
class Game_Map
attr_accessor :rotation
attr_reader :hmrs_rcx
attr_reader :hmrs_rcy
attr_reader :hmrs_bottom_z
alias hmrs_setup_old setup
def setup(map_id)
hmrs_setup_old(map_id)
@rotation = 0
set_bottom_layer_z(HMRS::CONFIG::BOTTOM_LAYER_Z)
get_origin_coordinates
end
def get_origin_coordinates
@hmrs_rcx = self.width / 2
@hmrs_rcy = self.height / 2
end
def rotated?
return (rotation > 0)
end
def set_bottom_layer_z(value)
@hmrs_bottom_z = value
end
end
class Game_CharacterBase
attr_reader :rotation
alias hmrs_initialize_old initialize
def initialize
@rotation = 0
hmrs_initialize_old
end
def make_invisible
@opacity = 0
@through = true
end
def make_visible
@opacity = 255
@through = false
end
def rot_visible?(rstr)
flag_is_visible = true
if rstr.include?("HMRS invisible ")
cll = HMRS::COMMENT_LINE.length
rm_num = (rstr.length - cll)/2
rm_index = 0
while (rm_index < rm_num)
if $game_map.rotation == rstr[cll + rm_index*2].to_i
flag_is_visible = false
break
end
rm_index += 1
end
end
return flag_is_visible
end
def calculate_collision_coordinates(old_x, old_y)
x_new = old_x
y_new = old_y
if ($game_map.rotation > 0)
x1 = old_x - $game_map.hmrs_rcx
y1 = old_y - $game_map.hmrs_rcy
case $game_map.rotation
when 1
x_new = y1
y_new = -x1
when 2
x_new = -x1
y_new = -y1
when 3
x_new = -y1
y_new = x1
end
x_new += $game_map.hmrs_rcx
y_new += $game_map.hmrs_rcy
end
return [x_new, y_new]
end
def calculate_new_coordinates(old_x, old_y, rotation)
x_new = old_x
y_new = old_y
if (rotation > 0)
x1 = old_x - $game_map.hmrs_rcx
y1 = old_y - $game_map.hmrs_rcy
case rotation
when 1
x_new = -y1
y_new = x1
when 2
x_new = -x1
y_new = -y1
when 3
x_new = y1
y_new = -x1
end
x_new += $game_map.hmrs_rcx
y_new += $game_map.hmrs_rcy
end
return [x_new, y_new]
end
def rotate_position
rotation_number = $game_map.rotation - self.rotation
if rotation_number < 0
rotation_number += 4
end
new_xy = calculate_new_coordinates(self.x, self.y, rotation_number)
moveto(new_xy[0], new_xy[1])
get_rotated_direction
@rotation = $game_map.rotation
end
def get_rotated_direction
r = $game_map.rotation - @rotation
new_direction = HMRS::CRTABLE[r][self.direction]
@diagonal = HMRS::RDIR[r][self.diagonal]
set_direction(new_direction)
end
def passable?(x, y, d)
if $game_map.free_movement_enabled?
rd = HMRS::RDIR[$game_map.rotation][d]
rd.nil? ? rd = d : nil
horz = (d - 1) % 3 - 1
rhorz = (rd - 1) % 3 - 1
vert = 1 - ((d - 1) / 3)
rvert = 1 - ((rd - 1) / 3)
pixelstep = CXJ::FREE_MOVEMENT::PIXELS_PER_STEP / 32.0
extra_x = (($game_map.rotation%2 == 0) ? rhorz : rvert)
extra_y = (($game_map.rotation%2 == 0) ? rvert : rhorz)
if $game_map.rotation == 1
extra_x = -extra_x
elsif $game_map.rotation == 2
extra_x = -extra_x
extra_y = -extra_y
elsif $game_map.rotation == 3
extra_y = -extra_y
end
x2 = $game_map.round_x(x + horz * pixelstep)
y2 = $game_map.round_y(y + vert * pixelstep)
rx2 = $game_map.round_x(x + extra_x * pixelstep)
ry2 = $game_map.round_y(y + extra_y * pixelstep)
collision_map_xy = calculate_collision_coordinates(x, y)
collision_map_x2y2 = calculate_collision_coordinates(rx2, ry2)
rx = collision_map_xy[0]
ry = collision_map_xy[1]
rx2 = collision_map_x2y2[0]
ry2 = collision_map_x2y2[1]
return false unless $game_map.valid_rect?(x2, y2, collision_rect)
return true if @through || debug_through?
if $game_map.collision_map_enabled?
return false unless map_check_passage_collision_maps(rx, ry, rd, collision_rect)
return false unless map_check_passage_collision_maps(rx2, ry2, reverse_dir(rd), collision_rect)
else
return false unless map_passable_rect?(rx, ry, rd, collision_rect)
return false unless map_passable_rect?(rx2, ry2, reverse_dir(rd), collision_rect)
end
return false if collide_with_characters?(x2, y2)
return true
else
return game_characterbase_passable_cxj_fm?(x, y, d)
end
end
end
class Game_Interpreter
def rotate_map(id, lid_min, lid_max, rotations = 1)
if HMRS::CONFIG::ROTATION_TINT
case HMRS::CONFIG::DEFAULT_ROTATION_TINT_COLOR
when 0
tint_black(60)
when 1
tint_white(60)
else
tint_white(60)
end
end
rotations.times { increase_rotation_variable }
$game_map.events.each do |event|
event[1].rotate_position
if (event[1].list[0].code == 108)
hmrs_rstr = event[1].list[0]
hmrs_rstr.parameters.each do |strp|
event[1].rot_visible?(strp) ? event[1].make_visible : event[1].make_invisible
end
end
end
$game_player.rotate_position
hmrs_setup_map_layers(lid_min, lid_max)
refresh_layers
tint_normal(60) if HMRS::CONFIG::ROTATION_TINT
end
def hmrs_setup_map_layers(lid_min, lid_max)
id = $game_map.map_id
for i in lid_min..lid_max
path_name = "#{HMRS::LAYERS_PATH}"
fname = sprintf(HMRS::FNAME, id, i, $game_map.rotation)
unless File.exists?("#{path_name}#{fname}")
fname = sprintf(HMRS::FNAME_NO_ROTATION, id, i)
end
bz = $game_map.hmrs_bottom_z
z = bz + HMRS::CONFIG::Z_DISTANCE * (i - 1)
z = 0 if z < 0
layer($game_map.map_id, i, [fname,0,0,255,z,0,0,0])
end
refresh_layers
end
def increase_rotation_variable
if [0, 1, 2].include?($game_map.rotation)
$game_map.rotation += 1
else
$game_map.rotation = 0
end
end
def tint_screen(tone, duration)
screen.start_tone_change(tone, duration)
unless (duration == 0)
duration.times { Fiber.yield }
end
end
def tint_black(duration = 0)
black_tone = Tone.new(-255, -255, -255)
tint_screen(black_tone, duration)
end
def tint_normal(duration = 0)
normal_tone = Tone.new
tint_screen(normal_tone, duration)
end
def tint_white(duration = 0)
white_tone = Tone.new(255, 255, 255)
tint_screen(white_tone, duration)
end
def set_map_bottom_layer_z(value)
$game_map.set_bottom_layer_z(value)
end
def hmrs_transfer(map, x, y, d, lid_min, lid_max, fade = "black", r = nil)
if fade == "black"
tint_black(60)
elsif fade == "white"
tint_white(60)
end
Graphics.freeze
$game_temp.fade_type = 2
r.nil? ? r2 = $game_map.rotation : r2 = r
$game_player.reserve_transfer(map, x, y, d)
Fiber.yield while $game_player.transfer?
rotate_map(map, lid_min, lid_max, r2)
if (r.nil? || (r == 0)) && ($game_map.rotation != 0)
player_xy_new = $game_player.calculate_new_coordinates(x, y, $game_map.rotation)
$game_player.moveto(player_xy_new[0], player_xy_new[1])
end
tint_normal
10.times { Fiber.yield }
Graphics.transition(60)
end
end