#==============================================================================
# ■ Sideview battle system[Motion Control] Ver.2.0.2 by Claimh
# Translated by Naridar
#------------------------------------------------------------------------------
# Control actors' behavior here.
#------------------------------------------------------------------------------
#【Redefines】
# Sprite_Battler : initialize
# update
#==============================================================================
module SideView
#----------------------------------------------------------------------------
# You can use seperate pictures for KOd actors.
# Set them here.
# Have the image you want in the Graphics\Characters folder
CORPSE_F = {
# How to set another one up:
# Actor ID => ["Image name", X, Y] (X and Y range from 0 to 3)
1 => ["189-Down01", 0, 0],
2 => ["189-Down01", 1, 2],
3 => ["189-Down01", 0, 3],
4 => ["190-Down02", 2, 0],
5 => ["190-Down02", 1, 1],
6 => ["190-Down02", 2, 1],
7 => ["190-Down02", 0, 3],
8 => ["191-Down03", 3, 1]
}
# Set the directon the characters are facing.
# Use variable 10 for this!
# 2:down, 4:left, 6:right, 8:up
#----------------------------------------------------------------------------
#----------------------------------------------------------------------------
# Do not change these lines.
M_MODE_WAIT = 0
M_MODE_MAGI = 1
M_MODE_DAMG = 2
M_MODE_WIN = 3
M_MODE_ATK1 = 4
M_MODE_ATK2 = 5
M_MODE_ATK3 = 6
module_function
#--------------------------------------------------------------------------
# 移動位置計算
#--------------------------------------------------------------------------
def set_target_point(attacker, target)
case target
when Game_Actor
bits = RPG::Cache.character(target.character_name, target.character_hue)
attacker.target_x = target.screen_x + (bits.width /
attacker.target_y = target.screen_y
when Game_Enemy
bits = RPG::Cache.battler(target.battler_name, target.battler_hue)
attacker.target_x = target.screen_x + (bits.width / 2)
attacker.target_y = target.screen_y
end
end
end
#==============================================================================
# ¡ Sprite_Battler
#==============================================================================
class Sprite_Battler < RPG::Sprite
#--------------------------------------------------------------------------
# Redefine object initialization
# viewport
# battler (Game_Battler)
#--------------------------------------------------------------------------
def initialize(viewport, battler = nil)
super(viewport)
@battler = battler
@battler_visible = false
@battler_corpse = false
@first_dead = false
@pattern = 0
@direction = 0
@moving_mode = 0
init_direct_attack
end
#--------------------------------------------------------------------------
# Direct attack initialization
#--------------------------------------------------------------------------
def init_direct_attack
@direct_attack_cnt = 0
@direct_attack_phase = 0
@direct_move_cnt = 0
@battler_x_plus = 0
@battler_y_plus = 0
end
#--------------------------------------------------------------------------
# Not attacking?
#--------------------------------------------------------------------------
def effect?
ret = super
return ret if @battler.nil?
if @direct_attack_phase == 0
return ret
else
return false
end
end
#--------------------------------------------------------------------------
# Redefine current frame
#--------------------------------------------------------------------------
def update
super
# If battler is nil
if @battler == nil
self.bitmap = nil
loop_animation(nil)
return
end
# If battler's alive
unless @battler_corpse
# Is anything different
if @battler.battler_name != @battler_name or
@battler.battler_hue != @battler_hue or
@battler.move_mode != @moving_mode
# Motion control
motion_control
# Set opacity to 0 if status is special
if (@battler.dead? or @battler.hidden) and !@battler.dead_delay
self.opacity = 0
end
end
end
# Is animation different
if @battler.damage == nil and
@battler.state_animation_id != @state_animation_id
@state_animation_id = @battler.state_animation_id
loop_animation($data_animations[@state_animation_id])
end
# If blinking is on
if @battler.blink
blink_on
else
blink_off
end
# Is invisible?
unless @battler_visible
if not @battler.hidden and not @battler.dead? and
(@battler.damage == nil or @battler.damage_pop)
appear
@battler_visible = true
@battler.dead_delay = true
end
if @battler.dead? and (@battler.damage == nil or @battler.damage_pop)
if @battler.is_a?(Game_Actor)
appear
update_dead
@battler_visible = true
@battler_corpse = true
end
@battler.dead_delay = true
@battler.revive_delay = false
end
end
# If visible
if @battler_visible and !@battler_corpse
# Escaping
if @battler.hidden
$game_system.se_play($data_system.escape_se)
escape
@battler_visible = false
end
if @battler.white_flash
whiten
@battler.white_flash = false
end
if @battler.animation_id != 0
animation = $data_animations[@battler.animation_id]
animation(animation, @battler.animation_hit)
@battler.animation_id = 0
end
if @battler.damage_pop
damage(@battler.damage, @battler.critical)
@battler.damage = nil
@battler.critical = false
@battler.damage_pop = false
end
if @battler.damage == nil and @battler.dead?
if @battler.is_a?(Game_Enemy)
$game_system.se_play($data_system.enemy_collapse_se)
else
$game_system.se_play($data_system.actor_collapse_se)
end
if @battler.dead_delay
if @battler.is_a?(Game_Actor)
unless @first_dead
appear
update_dead
@battler_corpse = true
else
@first_daed = false
end
else
@battler_corpse = true
@first_daed = false
collapse
end
else
collapse
end
end
end
# ‘h¶ˆ’u
if !@battler.dead? and @battler_corpse and @battler.revive_delay
appear
case @battler
when Game_Actor
draw_pre_character
draw_character
when Game_Enemy
draw_battler
end
@battler.dead_delay = true
@battler.revive_delay = false
@battler_corpse = false
end
# Set sprite coordinates
self.x = @battler.screen_x + @battler_x_plus
self.y = @battler.screen_y + @battler_y_plus
self.z = @battler.screen_z
end
#--------------------------------------------------------------------------
# Drawing dead actors
#--------------------------------------------------------------------------
def update_dead
self.bitmap = RPG::Cache.character(SideView::CORPSE_F[@battler.id][0], @battler.character_hue)
cw = self.bitmap.width / 4
ch = self.bitmap.height / 4
x_index = cw * (SideView::CORPSE_F[@battler.id][1])
y_index = ch * (SideView::CORPSE_F[@battler.id][2])
@width = cw
@height = ch
# Set source rectangle
self.src_rect.set(x_index, y_index, cw, ch)
self.ox = @width / 2
self.oy = @height
end
#--------------------------------------------------------------------------
# Battler drawing
#--------------------------------------------------------------------------
def draw_battler
# Get bitmap
@battler_name = @battler.battler_name
@battler_hue = @battler.battler_hue
self.bitmap = RPG::Cache.battler(@battler_name, @battler_hue)
@width = bitmap.width
@height = bitmap.height
self.ox = @width / 2
self.oy = @height
end
#--------------------------------------------------------------------------
# Draw character - preparation
#--------------------------------------------------------------------------
def draw_pre_character
# Get bitmap set
@battler_name = @battler.character_name
@battler_hue = @battler.character_hue
# Draw walking sprite
self.bitmap = RPG::Cache.character(@battler_name, @battler_hue)
@width = self.bitmap.width / 4
@height = self.bitmap.height / 4
self.ox = @width / 2
self.oy = @height
end
#--------------------------------------------------------------------------
# Draw character
#--------------------------------------------------------------------------
def draw_character
# Set source rectangle
sx = @pattern * @width
sy = (@direction - 2) / 2 * @height
self.src_rect.set(sx, sy, @width, @height)
end
#--------------------------------------------------------------------------
# Motion control
#--------------------------------------------------------------------------
def motion_control
# Moving mode
@moving_mode = @battler.move_mode
# Draw battler
case @battler
when Game_Actor
actor_motion_control
when Game_Enemy
enemy_motion_control
end
end
#--------------------------------------------------------------------------
# ● Actor motion control
#--------------------------------------------------------------------------
def actor_motion_control
draw_pre_character
# Change behavior
case @moving_mode
when SideView::M_MODE_WAIT # Wait
init_direct_attack
@battler_x_plus = 0
@direction = $game_variables[10]
@pattern = 1
when SideView::M_MODE_MAGI # Magic
#@battler_x_plus = -10
@battler_y_plus = -10
@direction = $game_variables[10]
@pattern = 3
when SideView::M_MODE_DAMG # Damage
#@battler_x_plus = 10
@battler_y_plus = 10
@direction = $game_variables[10]
@pattern = 3
when SideView::M_MODE_WIN # Victory
@direction = 2
@pattern = 1
when SideView::M_MODE_ATK1 # Attack
exe_moving_attack_start
@moving_mode = 10
@end_pos_x = @battler_x_plus
@end_pos_y = @battler_y_plus
when SideView::M_MODE_ATK2
@battler_y_plus = @end_pos_y - 10
when SideView::M_MODE_ATK3
exe_moving_attack_end
@moving_mode = 10
else
p "error:Sprite_Battler>> @moving_mode"
end
draw_character
end
#--------------------------------------------------------------------------
# Motion control (enemy)
#--------------------------------------------------------------------------
def enemy_motion_control
# Change behavior
case @moving_mode
when SideView::M_MODE_WAIT # Wait
init_direct_attack
when SideView::M_MODE_MAGI # Magic
@battler_x_plus = 10
when SideView::M_MODE_DAMG # Damage
@battler_x_plus = -10
@shake_flg = true
when SideView::M_MODE_ATK1 # Attack
exe_moving_attack_start
@moving_mode = 10
@end_pos_x = @battler_x_plus
when SideView::M_MODE_ATK2
@battler_x_plus = @end_pos_x + 10
when SideView::M_MODE_ATK3
exe_moving_attack_end
@moving_mode = 10
else
p "error:Sprite_Battler>> @moving_mode", @moving_mode
end
draw_battler
end
#--------------------------------------------------------------------------
# Moving attack
#--------------------------------------------------------------------------
def exe_moving_attack_start
return unless @battler.motion_stop
case @direct_attack_phase
when 0 # Ready
diratk_start
when 1 # Moving
diratk_move
when 2 # Waiting
diratk_wait
end
end
def exe_moving_attack_end
case @direct_attack_phase
when 0 # Attack
diratk_attack
when 1 # Return
diratk_back
when 2 # End
diratk_end
end
end
#--------------------------------------------------------------------------
# Perform direct attack
#--------------------------------------------------------------------------
def diratk_start
# Pose change
@pattern = 1
# Determine duration in frames
pos_x = @battler.target_x - self.x
pos_y = @battler.target_y - self.y
# Calculate frames
@direct_move_cnt = @direct_attack_cnt = (pos_x.abs / 40).round
# Next phase
@direct_attack_phase += 1
end
#--------------------------------------------------------------------------
# Moving attack
#--------------------------------------------------------------------------
def diratk_move
case @battler
when Game_Actor
x_plus = 20
y_plus = 0
when Game_Enemy
bitmap = RPG::Cache.battler(@battler_name, @battler_hue)
x_plus = -(bitmap.width/2 + 25)
y_plus = 20
end
# Determine next move
pos_x = @battler.target_x - self.x + x_plus
pos_y = @battler.target_y - self.y + y_plus
@battler_x_plus += pos_x / @direct_attack_cnt if @direct_attack_cnt != 0
@battler_y_plus += pos_y / @direct_attack_cnt if @direct_attack_cnt != 0
# Counting
@direct_attack_cnt -= 1
# Moving on
if @direct_attack_cnt <= 0
@battler_x_plus = @battler.target_x - @battler.screen_x + x_plus
@battler_y_plus = @battler.target_y - @battler.screen_y + y_plus
# Next phase
@direct_attack_cnt = 5
@direct_attack_phase += 1
end
end
#--------------------------------------------------------------------------
# Wait for attack
#--------------------------------------------------------------------------
def diratk_wait
# Break counting
@direct_attack_cnt -= 1
# Move on
if @direct_attack_cnt <= 0
# Change pose
@pattern = 3
# End phase
@direct_attack_phase = 0
@battler.motion_stop = false
end
end
#--------------------------------------------------------------------------
# Direct attack
#--------------------------------------------------------------------------
def diratk_attack
# Change pose
@pattern = 1
# Counting
@direct_attack_cnt = (@direct_move_cnt/2).round
# Next phase
@direct_attack_phase += 1
end
#--------------------------------------------------------------------------
# Returning
#--------------------------------------------------------------------------
def diratk_back
# Determine next location
pos_x = @battler.screen_x - self.x
pos_y = @battler.screen_y - self.y
@battler_x_plus += pos_x / @direct_attack_cnt if @direct_attack_cnt != 0
@battler_y_plus += pos_y / @direct_attack_cnt if @direct_attack_cnt != 0
# Stop counting
@direct_attack_cnt -= 1
# Move on
if @direct_attack_cnt <= 0
@battler_x_plus = 0
@battler_y_plus = 0
# Next phase
@direct_attack_phase += 1
end
end
#--------------------------------------------------------------------------
# End action
#--------------------------------------------------------------------------
def diratk_end
init_direct_attack
# End phase
@direct_attack_phase = 0
end
end
class Game_Battler
attr_accessor :dead_delay # Death delay
attr_accessor :revive_delay # Revive delay
attr_accessor :move_mode # Moving mode
# 0:Standby 1:Attack 2:other 3:Victory
attr_accessor :motion_stop # Stop during movement
attr_accessor :target_x # Destination X
attr_accessor :target_y # Destination Y
#--------------------------------------------------------------------------
# Object initialization
#--------------------------------------------------------------------------
alias initialize_sdva_corpse initialize
def initialize
initialize_sdva_corpse
@dead_delay = false
@revive_delay = false
@move_mode = 0
end
end
class Scene_Battle
#--------------------------------------------------------------------------
# Start normal battle phase
#--------------------------------------------------------------------------
alias start_phase1_sidew start_phase1
def start_phase1
for battler in $game_party.actors + $game_troop.enemies
battler.move_mode = SideView::M_MODE_WAIT
end
start_phase1_sidew
end
#--------------------------------------------------------------------------
# Start after-battle phase
#--------------------------------------------------------------------------
alias start_phase5_sidew start_phase5
def start_phase5
for actor in $game_party.actors
actor.move_mode = SideView::M_MODE_WIN
end
start_phase5_sidew
end
#--------------------------------------------------------------------------
# Current frame in phase 4
#--------------------------------------------------------------------------
alias update_phase4_step2_sidew update_phase4_step2
def update_phase4_step2
update_phase4_step2_sidew
@motion_flag = false
@active_battler.motion_stop = false
@active_battler.move_mode = SideView::M_MODE_WAIT
end
#--------------------------------------------------------------------------
# Current frame in phase 4: animation
#--------------------------------------------------------------------------
alias update_phase4_step3_sidew update_phase4_step3
def update_phase4_step3
if @motion_flag
unless @active_battler.motion_stop
@motion_flag = false
@phase4_step = 4
return
end
@active_battler.move_mode = SideView::M_MODE_ATK1
return
end
update_phase4_step3_sidew
# Normal attack
if @active_battler.current_action.kind == 0 and @active_battler.current_action.basic == 0
SideView.set_target_point(@active_battler, @target_battlers[0])
@active_battler.motion_stop = true
@motion_flag = true
@phase4_step = 3
end
end
#--------------------------------------------------------------------------
# Animation target
#--------------------------------------------------------------------------
alias update_phase4_step4_sidew update_phase4_step4
def update_phase4_step4
update_phase4_step4_sidew
case @active_battler.current_action.kind
when 0 # Normal attack
if @active_battler.current_action.basic == 0
@active_battler.move_mode = SideView::M_MODE_ATK2
end
when 1..2 # Skills or items
@active_battler.move_mode = SideView::M_MODE_MAGI
end
for target in @target_battlers
if target.damage.is_a?(Numeric)
target.move_mode = SideView::M_MODE_DAMG if target.damage > 0
end
end
end
#--------------------------------------------------------------------------
# Damage exhibition
#--------------------------------------------------------------------------
alias update_phase4_step5_sdva_corpse update_phase4_step5
def update_phase4_step5
update_phase4_step5_sdva_corpse
if @active_battler.move_mode == SideView::M_MODE_ATK2
@active_battler.move_mode = SideView::M_MODE_ATK3
end
for target in @target_battlers
target.move_mode = SideView::M_MODE_WAIT
if target.dead?
target.dead_delay = true
target.revive_delay = false
elsif !target.revive_delay and !target.dead?
# Delayed revive effect
target.revive_delay = true
end
end
end
#--------------------------------------------------------------------------
# Refreshing screen: phase 6
#--------------------------------------------------------------------------
alias update_phase4_step6_sidew update_phase4_step6
def update_phase4_step6
@active_battler.move_mode = SideView::M_MODE_WAIT
for target in @target_battlers
target.move_mode = 0
end
update_phase4_step6_sidew
end
end