#==============================================================================
# ** Swimming System v1.0
#==============================================================================
# Author: Diagostimo
#==============================================================================
module Swim_Config
#----------------------------------------------------------------------------
# BEGIN CONFIGURATION
#----------------------------------------------------------------------------
SWIMABLE_EVENTS = {
#MAP_ID => [ARRAY OF EVENT ID'S]
1 => [1, 2, 3, 4, 5, 6],
2 => []
}
#Extension of the filename to change the swimming graphic
SWIM_EXTENSION = '_swim'
#Terrain tag of water to swim on
WATER_TERRAIN = 2
#----------------------------------------------------------------------------
# END CONFIGURATION
#----------------------------------------------------------------------------
end
#==============================================================================
# ** Game Character
#==============================================================================
class Game_Character
#----------------------------------------------------------------------------
# * Public Instance Variables
#----------------------------------------------------------------------------
attr_accessor :swimming
#----------------------------------------------------------------------------
# * Object Initialization
#----------------------------------------------------------------------------
alias init_diag_swim initialize
def initialize
init_diag_swim
@swimming = false
end
#----------------------------------------------------------------------------
# * Passable?
#----------------------------------------------------------------------------
alias passable_diag_swim passable?
def passable?(x, y, d)
target_x = @x + (d == 6 ? 1 : d == 4 ? -1 : 0)
target_y = @y + (d == 2 ? 1 : d == 8 ? -1 : 0)
return false if !@swimming && $game_map.terrain_tag(target_x, target_y) == 2
passable_diag_swim(x, y, d)
end
end
#==============================================================================
# ** Game Player
#==============================================================================
class Game_Player < Game_Character
#----------------------------------------------------------------------------
# * Frame Update
#----------------------------------------------------------------------------
alias update_player_diag_swim update
def update
if Input.trigger?(Input::C) && !@swimming
d = @direction
target_x = @x + (d == 6 ? 1 : d == 4 ? -1 : 0)
target_y = @y + (d == 2 ? 1 : d == 8 ? -1 : 0)
if $game_map.terrain_tag(target_x, target_y) == 2
player = $game_party.actors[0]
swim_graphic = player.character_name + Swim_Config::SWIM_EXTENSION
player.set_graphic(swim_graphic, player.character_hue,
player.battler_name, player.battler_hue)
refresh
@step_anime = true
@swimming = true
move_forward
end
end
update_player_diag_swim
if @swimming && $game_map.terrain_tag(@x, @y) != 2
@swimming = false
@step_anime = false
player = $game_party.actors[0]
orig_name = player.character_name.split(Swim_Config::SWIM_EXTENSION)
player.set_graphic(orig_name[0], player.character_hue,
player.battler_name, player.battler_hue)
refresh
end
end
end
#==============================================================================
# ** Game Event
#==============================================================================
class Game_Event < Game_Character
#----------------------------------------------------------------------------
# * Move Down
#----------------------------------------------------------------------------
def move_down(turn_enabled = true)
if $game_map.terrain_tag(@x, @y + 1) == 2 && !@swimming &&
Swim_Config::SWIMABLE_EVENTS[$game_
map.map_id].include?(@id) &&
$game_map.passable?(@x, @y, 2, self)
@swimming = true
@step_anime = true
@character_name += Swim_Config::SWIM_EXTENSION
elsif $game_map.terrain_tag(@x, @y + 1) == 2 && !@swimming &&
Swim_Config::SWIMABLE_EVENTS[$game_
map.map_id].include?(@id) &&
!$game_map.passable?(@x, @y, 2, self)
return
end
super(turn_enabled)
end
#----------------------------------------------------------------------------
# Move Left
#----------------------------------------------------------------------------
def move_left(turn_enabled = true)
if $game_map.terrain_tag(@x - 1, @y) == 2 && !@swimming &&
Swim_Config::SWIMABLE_EVENTS[$game_
map.map_id].include?(@id) &&
$game_map.passable?(@x, @y, 4, self)
@swimming = true
@step_anime = true
@character_name += Swim_Config::SWIM_EXTENSION
end
super(turn_enabled)
end
#----------------------------------------------------------------------------
# Move Right
#----------------------------------------------------------------------------
def move_right(turn_enabled = true)
if $game_map.terrain_tag(@x + 1, @y) == 2 && !@swimming &&
Swim_Config::SWIMABLE_EVENTS[$game_
map.map_id].include?(@id) &&
$game_map.passable?(@x, @y, 6, self)
@swimming = true
@step_anime = true
@character_name += Swim_Config::SWIM_EXTENSION
end
super(turn_enabled)
end
#----------------------------------------------------------------------------
# Move Up
#----------------------------------------------------------------------------
def move_up(turn_enabled = true)
if $game_map.terrain_tag(@x, @y - 1) == 2 && !@swimming &&
Swim_Config::SWIMABLE_EVENTS[$game_
map.map_id].include?(@id) &&
$game_map.passable?(@x, @y, 8, self)
@swimming = true
@step_anime = true
@character_name += Swim_Config::SWIM_EXTENSION
end
super(turn_enabled)
end
#----------------------------------------------------------------------------
# Frame Update
#----------------------------------------------------------------------------
alias update_event update
def update
update_event
if @swimming && $game_map.terrain_tag(@x, @y) != 2
@swimming = false
@step_anime = false
orig_name = @character_name.split(Swim_Config::SWIM_EXTENSION)
@character_name = orig_name[0]
refresh
end
end
end