Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

Follow Script help

I'm having trouble making the character that follows you change graphic when I run. I'm using common events to run and am not sure how to change the follower. Please help.

Edit: If it helps here's the script I used.
# rgss-lib
=begin

‚c‚pƒVƒXƒeƒ€ƒXƒNƒŠƒvƒg Train_Actor
Author:: yf30 at users.sourceforge.jp (http://sourceforge.jp/users/yf30/)
Date:: 2009/02/26
Copyright:: Copyright (C) 2004-2009 rgss-lib
URL:: http://sourceforge.jp/projects/rgss-lib/

=end

# dq

# train_actor

# Config.rb
#==============================================================================
# ¡ Train_Actor::Config
#------------------------------------------------------------------------------
# ƒ}ƒbƒvã‚ŃAƒNƒ^[‚ð‘à—ñˆÚ“®‚³‚¹‚é
#==============================================================================

module Train_Actor

# œ“§–¾ó‘Ô—pƒXƒCƒbƒ`Ý’è
# true ‚¾‚ƃXƒCƒbƒ`§Œä‚ðs‚¤
#TRANSPARENT_SWITCH = true
TRANSPARENT_SWITCH = false

# œ“§–¾ó‘Ô—pƒXƒCƒbƒ`”ԍ†
# TRANSPARENT_SWITCH ‚ª true ‚ŁA‚±‚̔ԍ†‚̃XƒCƒbƒ`‚ªON‚¾‚Æ“§–¾‚É‚È‚é
TRANSPARENT_SWITCHES_INDEX = 20

# œƒAƒNƒ^[‚̍ő吔
# «—ˆ“I‚É‘½l”ƒp[ƒeƒB‚ªo—ˆ‚é‚悤‚É‚È‚Á‚½‚çc
TRAIN_ACTOR_SIZE_MAX = 4

# Ž€–SŽž‚̃Lƒƒƒ‰ƒNƒ^[ƒOƒ‰ƒtƒBƒbƒN–¼
#DEAD_CHARACTER_NAME = "Coffin"
DEAD_CHARACTER_NAME = ""

# ’萔
DOWN_LEFT = 1
DOWN_RIGHT = 3
UP_LEFT = 7
UP_RIGHT = 9
JUMP = 5
STOP = 0

end

# rgss

# Game_Event_Module.rb
# Game_Event_Module
# ƒ}ƒbƒvã‚ŃAƒNƒ^[‚ð‘à—ñˆÚ“®‚³‚¹‚é
# Author:: fukuyama
# Date:: 2006/03/05
# Copyright:: Copyright (C) 2005 fukuyama

module Train_Actor

module Game_Event_Module
# ’ʍs‰Â”\”»’è
# x:: X À•W
# y:: Y À•W
# d:: •ûŒü (0,2,4,6,8) ¦ 0 = ‘S•ûŒü’ʍs•s‰Â‚̏ꍇ‚ð”»’è (ƒWƒƒƒ“ƒv—p)
# return:: ’ʍs•s‰Â false ‰Â”\ true
def passable?(x, y, d)
result = super(x, y, d)
return result if @through
if result
# V‚µ‚¢À•W‚ð‹‚ß‚é
new_x = x + (d == 6 ? 1 : d == 4 ? -1 : 0)
new_y = y + (d == 2 ? 1 : d == 8 ? -1 : 0)
# ƒgƒŒƒCƒ“ƒAƒNƒ^[‚̃‹[ƒv
for actor in $game_party.characters
# •\Ž¦‚³‚ê‚Ä‚¢‚éê‡
if (not actor.character_name.empty?) and (not actor.transparent)
# ƒAƒNƒ^[‚̍À•W‚ªˆÚ“®æ‚ƈê’v‚µ‚½ê‡
if actor.x == new_x and actor.y == new_y
# Ž©•ª‚ªƒCƒxƒ“ƒg‚̏ꍇ
if self != $game_player
# ’ʍs•s‰Â
return false
end
end
end
end
end
return result
end
end

end

class Game_Event
include Train_Actor::Game_Event_Module
end

# Game_Party_Module.rb
# Train_Actor::Game_Party_Module
# Game_Party—p‘à—ñ•àsƒ‚ƒWƒ…[ƒ‹
# Author:: fukuyama
# Date:: 2007/12/31
# Copyright:: Copyright (C) 2005-2007 rgss-lib

module Train_Actor

module Game_Party_Module
attr_reader :characters
def dead_actor_include?
for actor in actors
if actor.dead?
return true
end
end
return false
end
def get_active_party_order
if not dead_actor_include?
return actors
end
alive_actors = []
dead_actors = []
for actor in actors
if actor.dead?
dead_actors.push actor
else
alive_actors.push actor
end
end
return alive_actors + dead_actors
end
def setup_actor_character_sprites
if @characters.nil?
@characters = []
for i in 1 ... TRAIN_ACTOR_SIZE_MAX
@characters.push(Game_Party_Actor.new(i - 1))
end
end
setup_actors = get_active_party_order
for i in 1 .. @characters.size
@characters[i - 1].setup(setup_actors)
end
if $scene.class.method_defined?('setup_actor_character_sprites')
$scene.setup_actor_character_sprites(@characters)
end
end
def transparent_switch
if TRANSPARENT_SWITCH
unless $game_player.transparent
return $game_switches[TRANSPARENT_SWITCHES_INDEX]
end
end
return $game_player.transparent
end
def update_party_actors
setup_actor_character_sprites
transparent = transparent_switch
for character in @characters
character.transparent = transparent
character.update
end
end
def moveto_party_actors( x, y )
setup_actor_character_sprites
for character in @characters
character.moveto( x, y )
end
@move_list = []
move_list_setup
end
def move_party_actors
if @move_list == nil
@move_list = []
move_list_setup
end
@move_list.each_index do |i|
if not @characters.nil?
@characters.add_move_list_element(@move_list)
end
end
end
class Move_List_Element
def initialize(type,args)
@type = type
@args = args
end
def type() return @type end
def args() return @args end
end
def move_list_setup
for i in 0 .. TRAIN_ACTOR_SIZE_MAX
@move_list = nil
end
end
def add_move_list(type,*args)
@move_list.unshift(Move_List_Element.new(type,args)).pop
end
def move_down_party_actors(turn_enabled = true)
move_party_actors
add_move_list(Input::DOWN,turn_enabled)
end
def move_left_party_actors(turn_enabled = true)
move_party_actors
add_move_list(Input::LEFT,turn_enabled)
end
def move_right_party_actors(turn_enabled = true)
move_party_actors
add_move_list(Input::RIGHT,turn_enabled)
end
def move_up_party_actors(turn_enabled = true)
move_party_actors
add_move_list(Input::UP,turn_enabled)
end
def move_lower_left_party_actors
move_party_actors
add_move_list(DOWN_LEFT)
end
def move_lower_right_party_actors
move_party_actors
add_move_list(DOWN_RIGHT)
end
def move_upper_left_party_actors
move_party_actors
add_move_list(UP_LEFT)
end
def move_upper_right_party_actors
move_party_actors
add_move_list(UP_RIGHT)
end
def jump_party_actors(x_plus, y_plus)
move_party_actors
add_move_list(JUMP,x_plus, y_plus)
move_stop_party_actors
end
def move_stop_party_actors
actors.each do |a|
move_party_actors
add_move_list(STOP)
end
end
end

end

class Game_Party
include Train_Actor::Game_Party_Module

# ƒAƒNƒ^[‚ð‰Á‚¦‚é
# actor_id:: ƒAƒNƒ^[ ID
def add_actor(actor_id)
# ƒAƒNƒ^[‚ðŽæ“¾
actor = $game_actors[actor_id]
# ƒp[ƒeƒBl”‚ª 4 l–¢–ž‚ŁA‚±‚̃AƒNƒ^[‚ªƒp[ƒeƒB‚É‚¢‚È‚¢ê‡
if @actors.size < Train_Actor::TRAIN_ACTOR_SIZE_MAX and not @actors.include?(actor)
# ƒAƒNƒ^[‚ð’ljÁ
@actors.push(actor)
# ƒvƒŒƒCƒ„[‚ðƒŠƒtƒŒƒbƒVƒ…
$game_player.refresh
end
end
end

# Game_Player_Module.rb
# Train_Actor::Game_Player_Module
# Game_Player—p‘à—ñ•àsƒ‚ƒWƒ…[ƒ‹
# Author:: fukuyama
# Date:: 2007/12/31
# Copyright:: Copyright (C) 2005-2007 rgss-lib

module Train_Actor

module Game_Player_Module
attr_reader :move_speed
attr_reader :step_anime
attr_reader :direction_fix

def update_party_actors
if $game_party.actors.empty?
return
end
$game_party.update_party_actors
actor = $game_party.actors[0]
if not actor.dead?
if not @prev_dead.nil?
@character_name = actor.character_name
@character_hue = actor.character_hue
@prev_dead = nil
end
return
end
@prev_dead = true
$game_party.actors.each do |actor|
if not actor.dead?
@character_name = actor.character_name
@character_hue = actor.character_hue
break
end
end
end
def update
update_party_actors
super
end
def moveto( x, y )
$game_party.moveto_party_actors( x, y )
super( x, y )
end
def move_down(turn_enabled = true)
if passable?(@x, @y, Input::DOWN)
$game_party.move_down_party_actors(turn_enabled)
end
super(turn_enabled)
end
def move_left(turn_enabled = true)
if passable?(@x, @y, Input::LEFT)
$game_party.move_left_party_actors(turn_enabled)
end
super(turn_enabled)
end
def move_right(turn_enabled = true)
if passable?(@x, @y, Input::RIGHT)
$game_party.move_right_party_actors(turn_enabled)
end
super(turn_enabled)
end
def move_up(turn_enabled = true)
if passable?(@x, @y, Input::UP)
$game_party.move_up_party_actors(turn_enabled)
end
super(turn_enabled)
end
def move_lower_left
# ‰º¨¶A¶¨‰º ‚Ì‚Ç‚¿‚ç‚©‚̃R[ƒX‚ª’ʍs‰Â”\‚ȏꍇ
if (passable?(@x, @y, Input::DOWN) and passable?(@x, @y + 1, Input::LEFT)) or
(passable?(@x, @y, Input::LEFT) and passable?(@x - 1, @y, Input::DOWN))
$game_party.move_lower_left_party_actors
end
super
end
def move_lower_right
# ‰º¨‰EA‰E¨‰º ‚Ì‚Ç‚¿‚ç‚©‚̃R[ƒX‚ª’ʍs‰Â”\‚ȏꍇ
if (passable?(@x, @y, Input::DOWN) and passable?(@x, @y + 1, Input::RIGHT)) or
(passable?(@x, @y, Input::RIGHT) and passable?(@x + 1, @y, Input::DOWN))
$game_party.move_lower_right_party_actors
end
super
end
def move_upper_left
# ã¨¶A¶¨ã ‚Ì‚Ç‚¿‚ç‚©‚̃R[ƒX‚ª’ʍs‰Â”\‚ȏꍇ
if (passable?(@x, @y, Input::UP) and passable?(@x, @y - 1, Input::LEFT)) or
(passable?(@x, @y, Input::LEFT) and passable?(@x - 1, @y, Input::UP))
$game_party.move_upper_left_party_actors
end
super
end
def move_upper_right
# ã¨‰EA‰E¨ã ‚Ì‚Ç‚¿‚ç‚©‚̃R[ƒX‚ª’ʍs‰Â”\‚ȏꍇ
if (passable?(@x, @y, Input::UP) and passable?(@x, @y - 1, Input::RIGHT)) or
(passable?(@x, @y, Input::RIGHT) and passable?(@x + 1, @y, Input::UP))
$game_party.move_upper_right_party_actors
end
super
end
def jump(x_plus, y_plus)
# V‚µ‚¢À•W‚ðŒvŽZ
new_x = @x + x_plus
new_y = @y + y_plus
# ‰ÁŽZ’l‚ª (0,0) ‚̏ꍇ‚©AƒWƒƒƒ“ƒvæ‚ª’ʍs‰Â”\‚ȏꍇ
if (x_plus == 0 and y_plus == 0) or passable?(new_x, new_y, 0)
$game_party.jump_party_actors(x_plus, y_plus)
end
super(x_plus, y_plus)
end
end

end

class Game_Player
include Train_Actor::Game_Player_Module
end

# Scene_Map_Module.rb
# Train_Actor::Scene_Map_Module
# Scene_Map—p‘à—ñ•àsƒ‚ƒWƒ…[ƒ‹
# Author:: fukuyama
# Date:: 2007/12/31
# Copyright:: Copyright (C) 2005-2007 rgss-lib

module Train_Actor

module Scene_Map_Module
def setup_actor_character_sprites(characters)
@spriteset.setup_actor_character_sprites(characters)
end
end

end

class Scene_Map
include Train_Actor::Scene_Map_Module
end

# Spriteset_Map_Module.rb
# Train_Actor::Spriteset_Map_Module
# Spriteset_Map—p‘à—ñ•àsƒ‚ƒWƒ…[ƒ‹
# Author:: fukuyama
# Date:: 2007/12/31
# Copyright:: Copyright (C) 2005-2007 rgss-lib

module Train_Actor

module Spriteset_Map_Module
def setup_actor_character_sprites?
return @setup_actor_character_sprites_flag != nil
end
def setup_actor_character_sprites(characters)
if not setup_actor_character_sprites?
for character in characters.reverse
@character_sprites.unshift(Sprite_Character.new(@viewport1, character))
end
@setup_actor_character_sprites_flag = true
end
end
end

end

class Spriteset_Map
include Train_Actor::Spriteset_Map_Module
end

# Game_Party_Actor.rb
# Train_Actor::Game_Party_Actor
# ƒ}ƒbƒvã‚̃p[ƒeƒB—pƒLƒƒƒ‰ƒNƒ^[
# Author:: fukuyama
# Date:: 2007/12/31
# Copyright:: Copyright (C) 2005-2007 rgss-lib

module Train_Actor

class Game_Party_Actor < Game_Character
def initialize(character_index)
super()
@character_index = character_index
@character_wait = 0
@through = true
# •s“§–¾“x‚ƍ‡¬•û–@‚ð‰Šú‰»
@opacity = 255
@blend_type = 0
@move_list = []
end
def setup(actor)
# ƒLƒƒƒ‰ƒNƒ^[‚̃tƒ@ƒCƒ‹–¼‚ƐF‘Š‚ðÝ’è
if actor.nil?
@character_name = ""
@character_hue = 0
elsif not actor.dead? # Ž€‚ñ‚Å‚éê‡‚Æ‚è‚ ‚¦‚¸AÁ‚µ‚Æ‚±c
@character_name = actor.character_name
@character_hue = actor.character_hue
else
@character_name = DEAD_CHARACTER_NAME
@character_hue = 0
end
end
def update
@move_speed = $game_player.move_speed
@step_anime = $game_player.step_anime
@opacity = $game_player.opacity
@blend_type = $game_player.blend_type
@direction_fix = $game_player.direction_fix
if @direction_fix
@direction = $game_player.direction
end
update_move_list()
super
end
def screen_z(height = 0)
if $game_player.screen_z(height) == 999
return 998
end
if $game_player.x == @x and $game_player.y == @y
super(height) - 1
else
super(height)
end
end
def add_move_list_element(element)
@move_list.push(element)
if @move_list.size == 1
update_move_list()
end
end
def move_list_size
return @move_list.size
end
def update_move_list()
return if moving?
return if @move_list.empty?
if @move_list[0].type == STOP
if @character_index != 0
character = $game_party.characters[@character_index - 1]
if character.x == @x and character.y == @y and character.direction == @direction
@character_wait = 128 / (2 ** @move_speed) + 1
while character.move_list_size < @move_list.size and @move_list[0].type == STOP
@move_list.shift
end
end
end
else
@character_wait = 0
end
if @character_wait > 0
@character_wait -= 1
return
end
element = @move_list.shift
while element.type == STOP
element = @move_list.shift
end
case element.type
when Input::DOWN
move_down(element.args[0])
when Input::LEFT
move_left(element.args[0])
when Input::RIGHT
move_right(element.args[0])
when Input::UP
move_up(element.args[0])
when DOWN_LEFT
move_lower_left
when DOWN_RIGHT
move_lower_right
when UP_LEFT
move_upper_left
when UP_RIGHT
move_upper_right
when JUMP
jump(element.args[0],element.args[1])
end
end
def moveto( x, y )
@move_list.clear
super(x, y)
end
#--------------------------------------------------------------------------
# œ ‰º‚Ɉړ®
# turn_enabled : ‚»‚̏ê‚Å‚ÌŒü‚«•ÏX‚ð‹–‰Â‚·‚éƒtƒ‰ƒO
#--------------------------------------------------------------------------
def move_down(turn_enabled = true)
# ‰º‚ðŒü‚­
if turn_enabled
turn_down
end
# ’ʍs‰Â”\‚ȏꍇ
if passable?(@x, @y, Input::DOWN)
# ‰º‚ðŒü‚­
turn_down
# À•W‚ðXV
@y = (@y + 1 + $game_map.height) % ($game_map.height)
@real_y = (@y - 1) * 128
end
end
#--------------------------------------------------------------------------
# œ ¶‚Ɉړ®
# turn_enabled : ‚»‚̏ê‚Å‚ÌŒü‚«•ÏX‚ð‹–‰Â‚·‚éƒtƒ‰ƒO
#--------------------------------------------------------------------------
def move_left(turn_enabled = true)
# ¶‚ðŒü‚­
if turn_enabled
turn_left
end
# ’ʍs‰Â”\‚ȏꍇ
if passable?(@x, @y, Input::LEFT)
# ¶‚ðŒü‚­
turn_left
# À•W‚ðXV
@x = (@x - 1 + $game_map.width) % ($game_map.width)
@real_x = (@x + 1) * 128
end
end
#--------------------------------------------------------------------------
# œ ‰E‚Ɉړ®
# turn_enabled : ‚»‚̏ê‚Å‚ÌŒü‚«•ÏX‚ð‹–‰Â‚·‚éƒtƒ‰ƒO
#--------------------------------------------------------------------------
def move_right(turn_enabled = true)
# ‰E‚ðŒü‚­
if turn_enabled
turn_right
end
# ’ʍs‰Â”\‚ȏꍇ
if passable?(@x, @y, Input::RIGHT)
# ‰E‚ðŒü‚­
turn_right
# À•W‚ðXV
@x = (@x + 1 + $game_map.width) % ($game_map.width)
@real_x = (@x - 1) * 128
end
end
#--------------------------------------------------------------------------
# œ ã‚Ɉړ®
# turn_enabled : ‚»‚̏ê‚Å‚ÌŒü‚«•ÏX‚ð‹–‰Â‚·‚éƒtƒ‰ƒO
#--------------------------------------------------------------------------
def move_up(turn_enabled = true)
# ã‚ðŒü‚­
if turn_enabled
turn_up
end
# ’ʍs‰Â”\‚ȏꍇ
if passable?(@x, @y, Input::UP)
# ã‚ðŒü‚­
turn_up
# À•W‚ðXV
@y = (@y - 1 + $game_map.height) % ($game_map.height)
@real_y = (@y + 1) * 128
end
end
end

end
 

Atoa

Member

Try my Caterpillar, it's on brasillian portuguese, but it's almost plug an play with just small settings, so you can try google to translate it.

It has 8 directions, run (both can be turned OFF) with animation for run and diagonal move (if you don't have diagonal and/or run grapchis, no error will occur) and also has a better moving for the followers. (they will walk only when really needed, so they won't spin like dumbs XD)

Here's the code:

Code:
#=============================================================================

# 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

 

  # 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

 

#==============================================================================

# ■ Sprite_Character

#==============================================================================

class Sprite_Character

  #--------------------------------------------------------------------------

  include Atoa

  #--------------------------------------------------------------------------

  alias atoa_caterpillar_update update

  def update

    atoa_caterpillar_update

    if @character.is_a?(Game_Player) or @character.is_a?(Atoa_Catterpillar)

      a = ''

      a += 'Diag' if @character.diagonal

      a += 'Run' if @character.running

      begin

        self.bitmap = RPG::Cache.character(@character.character_name + a, @character.character_hue)

      rescue

        self.bitmap = RPG::Cache.character(@character.character_name, @character.character_hue)

      end

      @cw = bitmap.width / 4

      @ch = bitmap.height / 4

      self.ox = @cw / 2

      self.oy = @ch

      sx = @character.pattern * @cw

      sy = (@character.direction - 2) / 2 * @ch

      self.src_rect.set(sx, sy, @cw, @ch)

    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_Catterpillar.new(i)

      end

    end

    for cat in @caterpillar

      cat.refresh

    end

  end

  #--------------------------------------------------------------------------

  alias atoa_caterpillar_update update if !method_defined?(:atoa_caterpillar_update)

  def update

    for cat in @caterpillar

      cat.update

    end

    last_moving = moving?

    unless moving? or $game_system.map_interpreter.running? or

           @move_route_forcing or $game_temp.message_window_showing

      input = Diagonal_Movement ? Input.dir8 : Input.dir4

      case input

      when 2

        move_down

      when 4

        move_left

      when 6

        move_right

      when 8

        move_up

      when 1

        move_lower_left

      when 3

        move_lower_right

      when 7

        move_upper_left

      when 9

        move_upper_right

      end

    end

    @move_speed = @base_speed

    @move_speed += 1 if @running and moving?

    @move_speed -= 1 if @diagonal and Diagonal_Speed_Adjust and not $game_system.map_interpreter.running?

    last_real_x = @real_x

    last_real_y = @real_y

    super

    if @real_y > last_real_y and @real_y - $game_map.display_y > CENTER_Y

      $game_map.scroll_down(@real_y - last_real_y)

    end

    if @real_x < last_real_x and @real_x - $game_map.display_x < CENTER_X

      $game_map.scroll_left(last_real_x - @real_x)

    end

    if @real_x > last_real_x and @real_x - $game_map.display_x > CENTER_X

      $game_map.scroll_right(@real_x - last_real_x)

    end

    if @real_y < last_real_y and @real_y - $game_map.display_y < CENTER_Y

      $game_map.scroll_up(last_real_y - @real_y)

    end

    unless moving?

      if last_moving

        result = check_event_trigger_here([1,2])

        if result == false

          unless $DEBUG and Input.press?(Input::CTRL)

            @encounter_count -= 1 if @encounter_count > 0

          end

        end

      end

      if Input.trigger?(Input::C)

        check_event_trigger_here([0])

        check_event_trigger_there([0,1,2])

      end

    end

  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

    passable = passable?(@x, @y, 2)

    caterpillar_update if @caterpillar.nil? or @move_update.nil?

    atoa_caterpillar_move_down

    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

    passable = passable?(@x, @y, 4)

    caterpillar_update if @caterpillar.nil? or @move_update.nil?

    atoa_caterpillar_move_left

    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

    passable = passable?(@x, @y, 6)

    caterpillar_update if @caterpillar.nil? or @move_update.nil?

    atoa_caterpillar_move_right

    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

    passable = passable?(@x, @y, 8)

    caterpillar_update if @caterpillar.nil? or @move_update.nil?

    atoa_caterpillar_move_up

    add_move_update('move_up') if passable

  end

  #--------------------------------------------------------------------------

  def move_lower_left(turn_enabled = true)

    passable = (passable?(@x, @y, 2) and passable?(@x, @y + 1, 4)) or (passable?(@x, @y, 4) and passable?(@x - 1, @y, 2))

    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, 2) and passable?(@x, @y + 1, 6)) or (passable?(@x, @y, 6) and passable?(@x + 1, @y, 2))

    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, 8) and passable?(@x, @y - 1, 4)) or (passable?(@x, @y, 4) and passable?(@x - 1, @y, 8))

    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, 8) and passable?(@x, @y - 1, 6)) or (passable?(@x, @y, 6) and passable?(@x + 1, @y, 8))

    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 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.actors

      @alive_actors << actor unless actor.dead?

    end

  end

end

 

#==============================================================================

# ■ Atoa_Catterpillar

#==============================================================================

class Atoa_Catterpillar < 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.actors

    if party.size < @member

      @character_name = ""

      @character_hue = 0

      return

    end

    actor = party[@member]

    if actor == nil

      @character_name = ""

      @character_hue = 0

      return

    end

    @character_name = actor.character_name

    @character_hue = actor.character_hue

    @opacity = 255

    @blend_type = 0

  end

  #--------------------------------------------------------------------------

  def screen_z(height = 0)

    if $game_player.x == @x and $game_player.y == @y

      return $game_player.screen_z - 1

    end

    super(height)

  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.actors.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, 2)

    turn_down if turn_enabled

    add_move_update('move_down')

  end

  #--------------------------------------------------------------------------

  def move_left(turn_enabled = true)

    @x -= 1 if passable?(@x, @y, 4)

    turn_left  if turn_enabled

    add_move_update('move_left')

  end

  #--------------------------------------------------------------------------

  def move_right(turn_enabled = true)

    @x += 1 if passable?(@x, @y, 6)

    turn_right if turn_enabled

    add_move_update('move_right')

  end

  #--------------------------------------------------------------------------

  def move_up(turn_enabled = true)

    @y -= 1 if passable?(@x, @y, 8)

    turn_up if turn_enabled

    add_move_update('move_up')

  end

  #--------------------------------------------------------------------------

  def move_lower_left(turn_enabled = true)

    if (passable?(@x, @y, 2) and passable?(@x, @y + 1, 4)) or

       (passable?(@x, @y, 4) and passable?(@x - 1, @y, 2))

      @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, 2) and passable?(@x, @y + 1, 6)) or

       (passable?(@x, @y, 6) and passable?(@x + 1, @y, 2))

      @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, 8) and passable?(@x, @y - 1, 4)) or

       (passable?(@x, @y, 4) and passable?(@x - 1, @y, 8))

      @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, 8) and passable?(@x, @y - 1, 6)) or

       (passable?(@x, @y, 6) and passable?(@x + 1, @y, 8))

      @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_initialize initialize if !method_defined?(:atoa_caterpillar_initialize)

  def initialize

    atoa_caterpillar_initialize

    for caterpillar in $game_player.caterpillar.reverse

      sprite = Sprite_Character.new(@viewport1, caterpillar)

      @character_sprites.push(sprite)

    end

  end

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.actors[0].dead?

      reorder_party(true)

    end

    $game_player.refresh if Graphics.frame_count % 5 == 0

  end

  #--------------------------------------------------------------------------

  def reorder_party(order)

    if order

      loop do

        party = $game_party.actors.shift

        $game_party.actors << party

        break if $game_party.all_dead? or not $game_party.actors[0].dead?

      end

    else

      loop do

        party = $game_party.actors.pop

        $game_party.actors.unshift(party)

        break  if $game_party.all_dead? or not $game_party.actors[0].dead?

      end

    end

  end

end
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top