#=============================================================================
# Atoa Atoa Caterpillar
# Por Atoa
#==============================================================================
# Este script permite vizualizar os membros no mapa, eles irão seguir o herói
# Um pouco diferente dos outros caterpillar, neste os personagens
# Só se movimentam caso necessário (portanto eles não ficam igual "barata tonta"
# se você ficar indo e voltando.
#
# Ele também conta com corrida e movimento em diagonal (ambos podendo ser
# desativados caso não deseje estes efeitos).
#
# A corrida e movimento diagonal também conta com animação diferenciada para.
# Você precisará dos gráficos das animações diferenciadas:
# 1 - Grafico para corrida: um gráfico com o mesmo nome do grafico do charset + Run
# 2 - Grafico para movimento diagonal: um gráfico com o mesmo nome do grafico do charset + Diag
# 3 - Grafico para movimento diagonal com corrida: um gráfico com o mesmo nome do grafico do
# charset + DiagRun
#
# Se o gráfico não for encontrado, o gráfico normal será usado.
#
# Você pode controlar o movimento dos personagens da fila atravéz
# de comandos de evento, usando o comando chamar script.
#
# $game_player.caterpillar[0].x = posição X no mapa
# $game_player.caterpillar[0].y = posição Y no mapa
#
# Para juntar os personagens use o comando: $game_player.caterpillar_gather
#
# Lembre-se de não permitir movimento do personagem se o grupo estiver separado
# Portanto use o comando de reunir o após este tipo de eventos.
#
#==============================================================================
module Atoa
# Numero máximos de personagens seguindo o herói na tela
Max_Caterpillar_Actor = 3
# ID do switch que esconde a vizualização dos personagens quando ativado
Caterpillar_Hide_Switch = 1
# Ocultar membros do grupo que estejam mortos
Hide_Dead = false
# Permitir alterar ordem do grupo apertando-se as teclas Q ou W?
Allow_Reorder = true
# Permitir movimento em diagonal?
Diagonal_Movement = true
# Ativar ajuste de velocidade quando se está andando em diagonal?
Diagonal_Speed_Adjust = true
# Distancia máxima entre os personagens do grupo (valor em pixel)
# Deixe 0 para desativar
Max_Distance = 0
# Importante ressaltar que o sistema de caterpillar desabilita a corrida padrão
# ID da Switch que habilita a corrida, se esta switch estiver off
# o personagem não conseguirá correr
Run_Switch = 2
# ID da Switch que habilita corrida sem a necessidade de se pressionar
# uma tecla. Enquanto ela estiver ligada, o personagem irá sempre correr.
Running_Switch = 3
# Tecla que pressionada permite que o personagem corra.
Run_Key = Input::C
# Input::A >> Teclado:Z
# Input::B >> Teclado:X
# Input::C >> Teclado:C
# Input::X >> Teclado:A
# Input::Y >> Teclado:S
# Input::Z >> Teclado:D
# Input::L >> Teclado:Q
# Input::R >> Teclado:W
end
#==============================================================================
# ■ Atoa Module
#==============================================================================
$atoa_script = {} if $atoa_script.nil?
$atoa_script['Atoa Caterpillar'] = true
#==============================================================================
# ■ Sprite_Character
#==============================================================================
class Sprite_Character
#--------------------------------------------------------------------------
include Atoa
#--------------------------------------------------------------------------
alias atoa_caterpillar_update update
def update
atoa_caterpillar_update
sign = @character_name[/^[\!\$]./]
if (@character.is_a?(Game_Player) or @character.is_a?(Atoa_Caterpillar)) and
(sign != nil and sign.include?('$'))
a = ''
a += 'Diag' if @character.diagonal
a += 'Run' if @character.running
begin
self.bitmap = Cache.character(@character.character_name + a)
rescue
self.bitmap = Cache.character(@character.character_name)
end
@cw = bitmap.width / 3
@ch = bitmap.height / 4
self.ox = @cw / 2
self.oy = @ch
update_src_rect
end
end
end
#==============================================================================
# ■ Game_Character
#==============================================================================
class Game_Character
#--------------------------------------------------------------------------
include Atoa
#--------------------------------------------------------------------------
attr_accessor(:direction, :diagonal, :running)
#--------------------------------------------------------------------------
alias atoa_caterpillar_initialize_gamechar initialize if !method_defined?(:atoa_caterpillar_initialize_gamechar)
def initialize
atoa_caterpillar_initialize_gamechar
@diagonal = @running = false
@base_speed = @move_speed
end
#--------------------------------------------------------------------------
alias move_type_custom_diagrun_gamechar move_type_custom
def move_type_custom
move_type_custom_diagrun_gamechar
@base_speed = [[@move_speed, 1].max, 6].min
end
end
#==============================================================================
# ■ Game_Player
#==============================================================================
class Game_Player < Game_Character
#--------------------------------------------------------------------------
attr_accessor(:caterpillar, :move_speed, :running, :alive_actors)
#--------------------------------------------------------------------------
def run_mode
@running = true
for cat in @caterpillar
cat.running = true
end
end
#--------------------------------------------------------------------------
def walk_mode
@running = false
for cat in @caterpillar
cat.running = false
end
end
#--------------------------------------------------------------------------
alias atoa_caterpillar_refresh refresh if !method_defined?(:atoa_caterpillar_refresh)
def refresh
caterpillar_update
atoa_caterpillar_refresh
end
#--------------------------------------------------------------------------
def caterpillar_update
if @caterpillar == nil
@caterpillar = []
for i in 1...(Max_Caterpillar_Actor + 1)
@caterpillar << Atoa_Caterpillar.new(i)
end
end
for cat in @caterpillar
cat.refresh
end
end
#--------------------------------------------------------------------------
def dash?
return false
end
#--------------------------------------------------------------------------
alias atoa_caterpillar_update update if !method_defined?(:atoa_caterpillar_update)
def update
for cat in @caterpillar
cat.update
end
atoa_caterpillar_update
end
#--------------------------------------------------------------------------
def move_by_input
return unless movable?
return if $game_map.interpreter.running?
input = Diagonal_Movement ? Input.dir8 : Input.dir4
case input
when 1; move_lower_left
when 2; move_down
when 3; move_lower_right
when 4; move_left
when 6; move_right
when 7; move_upper_left
when 8; move_up
when 9; move_upper_right
end
@move_speed = @base_speed
@move_speed += 1 if @running and moving?
@move_speed -= 1 if @diagonal and Diagonal_Speed_Adjust and not $game_map.interpreter.running?
end
#--------------------------------------------------------------------------
def turn_down
unless @direction_fix
@diagonal = false
@direction = 2
@stop_count = 0
end
end
#--------------------------------------------------------------------------
def turn_left
unless @direction_fix
@diagonal = false
@direction = 4
@stop_count = 0
end
end
#--------------------------------------------------------------------------
def turn_right
unless @direction_fix
@diagonal = false
@direction = 6
@stop_count = 0
end
end
#--------------------------------------------------------------------------
def turn_up
unless @direction_fix
@diagonal = false
@direction = 8
@stop_count = 0
end
end
#--------------------------------------------------------------------------
def turn_lower_left
unless @direction_fix
@diagonal = true
@direction = 2
@stop_count = 0
end
end
#--------------------------------------------------------------------------
def turn_lower_right
unless @direction_fix
@diagonal = true
@direction = 6
@stop_count = 0
end
end
#--------------------------------------------------------------------------
def turn_upper_left
unless @direction_fix
@diagonal = true
@direction = 4
@stop_count = 0
end
end
#--------------------------------------------------------------------------
def turn_upper_right
unless @direction_fix
@diagonal = true
@direction = 8
@stop_count = 0
end
end
#--------------------------------------------------------------------------
alias atoa_caterpillar_moveto moveto if !method_defined?(:atoa_caterpillar_moveto)
def moveto(x, y)
atoa_caterpillar_moveto(x, y)
caterpillar_update if @caterpillar.nil? or @move_update.nil?
for i in [email=0...@caterpillar.size]0...@caterpillar.size[/email]
@caterpillar[i].moveto(x, y)
end
end
#--------------------------------------------------------------------------
alias atoa_caterpillar_move_down move_down if !method_defined?(:atoa_caterpillar_move_down)
def move_down(turn_ok = true)
passable = passable?(@x, @y+1)
caterpillar_update if @caterpillar.nil? or @move_update.nil?
atoa_caterpillar_move_down(turn_ok)
add_move_update('move_down') if passable
end
#--------------------------------------------------------------------------
alias atoa_caterpillar_move_left move_left if !method_defined?(:atoa_caterpillar_move_left)
def move_left(turn_ok = true)
passable = passable?(@x-1, @y)
caterpillar_update if @caterpillar.nil? or @move_update.nil?
atoa_caterpillar_move_left(turn_ok)
add_move_update('move_left') if passable
end
#--------------------------------------------------------------------------
alias atoa_caterpillar_move_right move_right if !method_defined?(:atoa_caterpillar_move_right)
def move_right(turn_ok = true)
passable = passable?(@x+1, @y)
caterpillar_update if @caterpillar.nil? or @move_update.nil?
atoa_caterpillar_move_right(turn_ok)
add_move_update('move_right') if passable
end
#--------------------------------------------------------------------------
alias atoa_caterpillar_move_up move_up if !method_defined?(:atoa_caterpillar_move_up)
def move_up(turn_ok = true)
passable = passable?(@x, @y-1)
caterpillar_update if @caterpillar.nil? or @move_update.nil?
atoa_caterpillar_move_up(turn_ok)
add_move_update('move_up') if passable
end
#--------------------------------------------------------------------------
def move_lower_left(turn_enabled = true)
passable = (passable?(@x, @y+1) and passable?(@x-1, @y+1)) or (passable?(@x-1, @y) and passable?(@x-1, @y+1))
caterpillar_update if @caterpillar.nil? or @move_update.nil?
if passable
@x -= 1
@y += 1
increase_steps
end
turn_lower_left if turn_enabled
add_move_update('move_lower_left') if passable
end
#--------------------------------------------------------------------------
def move_lower_right(turn_enabled = true)
passable = (passable?(@x, @y+1) and passable?(@x+1, @y+1)) or (passable?(@x+1, @y) and passable?(@x+1, @y+1))
caterpillar_update if @caterpillar.nil? or @move_update.nil?
if passable
@x += 1
@y += 1
increase_steps
end
turn_lower_right if turn_enabled
add_move_update('move_lower_right') if passable
end
#--------------------------------------------------------------------------
def move_upper_left(turn_enabled = true)
passable = (passable?(@x, @y-1) and passable?(@x-1, @y-1)) or (passable?(@x-1, @y) and passable?(@x-1, @y-1))
caterpillar_update if @caterpillar.nil? or @move_update.nil?
if passable
@x -= 1
@y -= 1
increase_steps
end
turn_upper_left if turn_enabled
add_move_update('move_upper_left') if passable
end
#--------------------------------------------------------------------------
def move_upper_right(turn_enabled = true)
passable = (passable?(@x, @y-1) and passable?(@x+1, @y-1)) or (passable?(@x+1, @y) and passable?(@x+1, @y-1))
caterpillar_update if @caterpillar.nil? or @move_update.nil?
if passable
@x += 1
@y -= 1
increase_steps
end
turn_upper_right if turn_enabled
add_move_update('move_upper_right') if passable
end
#--------------------------------------------------------------------------
def get_on_vehicle
front_x = $game_map.x_with_direction(@x, @direction)
front_y = $game_map.y_with_direction(@y, @direction)
if $game_map.airship.pos?(@x, @y)
prepare_to_enter_vehicle
get_on_airship
return true
elsif $game_map.ship.pos?(front_x, front_y)
prepare_to_enter_vehicle
get_on_ship
return true
elsif $game_map.boat.pos?(front_x, front_y)
prepare_to_enter_vehicle
get_on_boat
return true
end
return false
end
#--------------------------------------------------------------------------
def prepare_to_enter_vehicle
caterpillar_gather
$scene.wait(30)
end
#--------------------------------------------------------------------------
alias atoa_caterpillar_get_off_vehicle get_off_vehicle if !method_defined?(:atoa_caterpillar_get_off_vehicle)
def get_off_vehicle
for i in [email=0...@caterpillar.size]0...@caterpillar.size[/email]
@caterpillar[i].moveto(@x, @y)
end
atoa_caterpillar_get_off_vehicle
caterpillar_gather
end
#--------------------------------------------------------------------------
def caterpillar_gather
for i in [email=0...@caterpillar.size]0...@caterpillar.size[/email]
@caterpillar[i].gather_party
end
end
#--------------------------------------------------------------------------
def add_move_update(move)
if @caterpillar[0] != nil
@caterpillar[0].move_update << move
end
end
#--------------------------------------------------------------------------
def set_alive_actors
@alive_actors = []
for actor in $game_party.members
@alive_actors << actor unless actor.dead?
end
end
end
#==============================================================================
# ■ Atoa_Caterpillar
#==============================================================================
class Atoa_Caterpillar < Game_Character
#--------------------------------------------------------------------------
attr_accessor(:move_update, :member, :next_x, :next_y, :x, :y, :move_speed, :running)
#--------------------------------------------------------------------------
def initialize(member)
super()
@move_update = []
@member = member
moveto($game_player.x, $game_player.y)
@running = false
@through = true
refresh
@next_x = @x
@next_y = @y
end
#--------------------------------------------------------------------------
def moveto(x, y)
super(x, y)
@move_update.clear
end
#--------------------------------------------------------------------------
def refresh
$game_player.set_alive_actors
party = Hide_Dead ? $game_player.alive_actors.dup : $game_party.members
if party.size < @member
@character_name = ""
@character_index = 0
return
end
actor = party[@member]
if actor == nil
@character_name = ""
@character_index = 0
return
end
@character_name = actor.character_name
@character_index = actor.character_index
@opacity = 255
@blend_type = 0
end
#--------------------------------------------------------------------------
def screen_z
if $game_player.x == @x and $game_player.y == @y
return $game_player.screen_z - 1
end
super
end
#--------------------------------------------------------------------------
def check_event_trigger_here(triggers)
return false
end
#--------------------------------------------------------------------------
def check_event_trigger_there(triggers)
return false
end
#--------------------------------------------------------------------------
def check_event_trigger_touch(x, y)
return false
end
#--------------------------------------------------------------------------
def update
member = @member == 1 ? $game_player : $game_player.caterpillar[@member - 2]
diff = (player_distance(member) >= (Max_Distance + 1)) ? 0 : 1
@move_speed = [$game_player.move_speed.to_f - diff, 1].max
move_player(member)
super
@transparent = $game_player.transparent
@transparent = @transparent ? @transparent : $game_switches[Caterpillar_Hide_Switch]
end
#--------------------------------------------------------------------------
def player_distance(member)
dist_x = (member.screen_x - self.screen_x).abs
dist_y = (member.screen_y - self.screen_y).abs
return dist_x if dist_x >= dist_y
return dist_y if dist_y >= dist_x
return 0
end
#--------------------------------------------------------------------------
def move_player(member)
refresh
@move_update.clear if member.x == @x and member.y == @y
return if moving?
return unless need_update(member)
move = @move_update.shift
eval(move) if move != nil
end
#--------------------------------------------------------------------------
def need_update(member)
return false if member.x == @x and member.y == @y
return false if @move_update.empty?
if @move_update[0] == 'move_left'
return false if (member.x + 1 == @x and member.y == @y)
elsif @move_update[0] == 'move_right'
return false if (member.x - 1 == @x and member.y == @y)
elsif @move_update[0] == 'move_up'
return false if (member.y + 1 == @y and member.x == @x)
elsif @move_update[0] == 'move_down'
return false if (member.y - 1 == @y and member.x == @x)
elsif @move_update[0] == 'move_upper_left'
return false if (member.x + 1 == @x and member.y + 1 == @y)
elsif @move_update[0] == 'move_upper_right'
return false if (member.x - 1 == @x and member.y + 1 == @y)
elsif @move_update[0] == 'move_lower_left'
return false if (member.x + 1 == @x and member.y - 1 == @y)
elsif @move_update[0] == 'move_lower_right'
return false if (member.x - 1 == @x and member.y - 1 == @y)
end
return true
end
#--------------------------------------------------------------------------
def add_move_update(move)
member = $game_player.caterpillar[@member]
if member != nil
member.move_update << move
end
end
#--------------------------------------------------------------------------
def gather_party
for i in 0...$game_party.members.size
move_toward_player
end
@x = $game_player.x
@y = $game_player.y
@move_update.clear
end
#--------------------------------------------------------------------------
def turn_down
unless @direction_fix
@diagonal = false
@direction = 2
@stop_count = 0
end
end
#--------------------------------------------------------------------------
def turn_left
unless @direction_fix
@diagonal = false
@direction = 4
@stop_count = 0
end
end
#--------------------------------------------------------------------------
def turn_right
unless @direction_fix
@diagonal = false
@direction = 6
@stop_count = 0
end
end
#--------------------------------------------------------------------------
def turn_up
unless @direction_fix
@diagonal = false
@direction = 8
@stop_count = 0
end
end
#--------------------------------------------------------------------------
def turn_lower_left
unless @direction_fix
@diagonal = true
@direction = 2
@stop_count = 0
end
end
#--------------------------------------------------------------------------
def turn_lower_right
unless @direction_fix
@diagonal = true
@direction = 6
@stop_count = 0
end
end
#--------------------------------------------------------------------------
def turn_upper_left
unless @direction_fix
@diagonal = true
@direction = 4
@stop_count = 0
end
end
#--------------------------------------------------------------------------
def turn_upper_right
unless @direction_fix
@diagonal = true
@direction = 8
@stop_count = 0
end
end
#--------------------------------------------------------------------------
def move_down(turn_enabled = true)
@y += 1 if passable?(@x, @y+1)
turn_down if turn_enabled
add_move_update('move_down')
end
#--------------------------------------------------------------------------
def move_left(turn_enabled = true)
@x -= 1 if passable?(@x-1, @y)
turn_left if turn_enabled
add_move_update('move_left')
end
#--------------------------------------------------------------------------
def move_right(turn_enabled = true)
@x += 1 if passable?(@x+1, @y+1)
turn_right if turn_enabled
add_move_update('move_right')
end
#--------------------------------------------------------------------------
def move_up(turn_enabled = true)
@y -= 1 if passable?(@x, @y-1)
turn_up if turn_enabled
add_move_update('move_up')
end
#--------------------------------------------------------------------------
def move_lower_left(turn_enabled = true)
if (passable?(@x, @y+1) and passable?(@x-1, @y+1)) or
(passable?(@x-1, @y) and passable?(@x-1, @y+1))
@x -= 1
@y += 1
end
turn_lower_left if turn_enabled
add_move_update('move_lower_left')
end
#--------------------------------------------------------------------------
def move_lower_right(turn_enabled = true)
if (passable?(@x, @y+1) and passable?(@x+1, @y+1)) or
(passable?(@x+1, @y) and passable?(@x+1, @y+1))
@x += 1
@y += 1
end
turn_lower_right if turn_enabled
add_move_update('move_lower_right')
end
#--------------------------------------------------------------------------
def move_upper_left(turn_enabled = true)
if (passable?(@x, @y-1) and passable?(@x-1, @y-1)) or
(passable?(@x-1, @y) and passable?(@x-1, @y-1))
@x -= 1
@y -= 1
end
turn_upper_left if turn_enabled
add_move_update('move_upper_left')
end
#--------------------------------------------------------------------------
def move_upper_right(turn_enabled = true)
if (passable?(@x, @y-1) and passable?(@x+1, @y-1)) or
(passable?(@x+1, @y) and passable?(@x+1, @y-1))
@x += 1
@y -= 1
end
turn_upper_right if turn_enabled
add_move_update('move_upper_right')
end
end
#==============================================================================
# ■ Spriteset_Map
#==============================================================================
class Spriteset_Map
#--------------------------------------------------------------------------
include Atoa
#--------------------------------------------------------------------------
alias atoa_caterpillar_create_characters create_characters if !method_defined?(:atoa_caterpillar_create_characters)
def create_characters
atoa_caterpillar_create_characters
for caterpillar in $game_player.caterpillar.reverse
sprite = Sprite_Character.new(@viewport1, caterpillar)
@character_sprites.push(sprite)
end
end
end
#==============================================================================
# ■ Game_Party
#==============================================================================
class Game_Party < Game_Unit
#--------------------------------------------------------------------------
attr_accessor :actors
end
#==============================================================================
# ■ Scene_Map
#==============================================================================
class Scene_Map
#--------------------------------------------------------------------------
include Atoa
#--------------------------------------------------------------------------
alias atoa_caterpillar_main main
def main
$game_player.refresh
atoa_caterpillar_main
end
#--------------------------------------------------------------------------
alias atoa_caterpillar_update update if !method_defined?(:atoa_caterpillar_update)
def update
if (Input.press?(Run_Key) and $game_switches[Run_Switch]) or
$game_switches[Running_Switch]
$game_player.run_mode
else
$game_player.walk_mode
end
atoa_caterpillar_update
if Input.trigger?(Input::L) and Allow_Reorder
$game_system.se_play($data_system.decision_se)
reorder_party(true)
end
if Input.trigger?(Input::R) and Allow_Reorder
$game_system.se_play($data_system.decision_se)
reorder_party(false)
end
if $game_party.members[0].dead?
reorder_party(true)
end
$game_player.refresh if Graphics.frame_count % 5 == 0
end
#--------------------------------------------------------------------------
def wait(duration)
for i in 0...duration
Graphics.update
$game_map.update
for cat in $game_player.caterpillar
cat.update
end
@spriteset.update
end
end
#--------------------------------------------------------------------------
def reorder_party(order)
if order
loop do
party = $game_party.members.shift
$game_party.members << party
break if $game_party.all_dead? or not $game_party.members[0].dead?
end
else
loop do
party = $game_party.members.pop
$game_party.members.unshift(party)
break if $game_party.all_dead? or not $game_party.members[0].dead?
end
end
end
end