#==============================================================================
# ** Advanced Vehicle System
#------------------------------------------------------------------------------
# © Dargor, 2008
# 31/03/08
# Version 1.1
#------------------------------------------------------------------------------
# VERSION HISTORY:
# - 1.0 (27/03/08), Initial release
# - 1.1 (31/03/08), Flying shadow added
#------------------------------------------------------------------------------
# INSTRUCTIONS:
# 1) Edit the variables in the Vehicle Module
# 2) Edit the new variables in Game_System
#==============================================================================
#==============================================================================
# ** Vehicle Module
#==============================================================================
module Vehicle
Key = Input::SHIFT
Switch = 1
Fly_BGM = RPG::BGM.new('Airship')
end
#==============================================================================
# ** Game_System
#------------------------------------------------------------------------------
# This class handles system-related data. Also manages vehicles and BGM, etc.
# The instance of this class is referenced by $game_system.
#==============================================================================
class Game_System
#--------------------------------------------------------------------------
# * Public Instance Variables
#--------------------------------------------------------------------------
attr_accessor :boat_character
attr_accessor :ship_character
attr_accessor :airship_character
attr_accessor :fly_character
#--------------------------------------------------------------------------
# * Alias Listing
#--------------------------------------------------------------------------
alias dargor_vx_system_vehicle_initialize initialize
#--------------------------------------------------------------------------
# * Object Initialization
#--------------------------------------------------------------------------
def initialize
@boat_character = ['Vehicle',4]
@ship_character = ['Vehicle',5]
@airship_character = ['Vehicle',6]
@fly_character = ['Actor1',0]
dargor_vx_system_vehicle_initialize
end
end
#==============================================================================
# ** Game_Vehicle
#------------------------------------------------------------------------------
# This class handles vehicles. It's used within the Game_Map class. If there
# are no vehicles on the current map, the coordinates is set to (-1,-1).
#==============================================================================
class Game_Vehicle < Game_Character
#--------------------------------------------------------------------------
# * Alias Listing
#--------------------------------------------------------------------------
alias dargor_vx_vehicle_graphic_load_system_settings load_system_settings
alias dargor_vx_vehicle_graphic_get_on get_on
alias dargor_vx_vehicle_graphic_get_off get_off
alias dargor_vx_vehicle_graphic_refresh refresh
alias dargor_vx_vehicle_graphic_upddate update
alias dargor_vx_vehicle_graphic_movable? movable?
#--------------------------------------------------------------------------
# * Load System Settings
#--------------------------------------------------------------------------
def load_system_settings
dargor_vx_vehicle_graphic_load_system_settings
case @type
when 3
$game_player = Game_Player.new if $game_player.nil?
@character_name = $game_system.fly_character[0]
@character_index = $game_system.fly_character[1]
@bgm = Vehicle::Fly_BGM
if $game_map.nil?
@map_id = $data_system.start_map_id
else
@map_id = $game_map.map_id
end
if $game_player.nil?
@x = $data_system.start_x
@y = $data_system.start_y
else
@x = $game_player.x
@y = $game_player.y
end
end
end
#--------------------------------------------------------------------------
# * Refresh
#--------------------------------------------------------------------------
def refresh
dargor_vx_vehicle_graphic_refresh
case @type
when 3
@priority_type = @driving ? 2 : 0
@move_speed = 6
end
end
#--------------------------------------------------------------------------
# * Frame Update
#--------------------------------------------------------------------------
def update
dargor_vx_vehicle_graphic_upddate
if @type == 3 # If flying
if $game_player.pos?(@x, @y) and (@driving or $game_player.vehicle_getting_off)
@character_name = $game_system.fly_character[0]
@character_index = $game_system.fly_character[1]
else
@character_name = ''
@character_index = 0
end
if @driving
if @altitude < MAX_ALTITUDE
@altitude += 1 # Increase altitude
end
elsif @altitude > 0
@altitude -= 1 # Decrease altitude
if @altitude == 0
@priority_type = 0 # Return priority to "Below Characters"
end
end
end
end
#--------------------------------------------------------------------------
# * Determine if Movement is Possible
#--------------------------------------------------------------------------
def movable?
return false if (@type == 3 and @altitude < MAX_ALTITUDE)
dargor_vx_vehicle_graphic_movable?
end
#--------------------------------------------------------------------------
# * Board Vehicle
#--------------------------------------------------------------------------
def get_on
dargor_vx_vehicle_graphic_get_on
if @type == 3 # If flying
@priority_type = 2 # Change priority to "Above Characters"
end
change_graphic
end
#--------------------------------------------------------------------------
# * Get Off Vehicle
#--------------------------------------------------------------------------
def get_off
dargor_vx_vehicle_graphic_get_off
@direction = $game_player.direction if @type == 3
change_graphic
end
#--------------------------------------------------------------------------
# * Change Graphic
#--------------------------------------------------------------------------
def change_graphic
if @driving
case @type
when 0
@character_name = $game_system.boat_character[0]
@character_index = $game_system.boat_character[1]
when 1
@character_name = $game_system.ship_character[0]
@character_index = $game_system.ship_character[1]
when 2
@character_name = $game_system.airship_character[0]
@character_index = $game_system.airship_character[1]
when 3
@character_name = $game_system.fly_character[0]
@character_index = $game_system.fly_character[1]
end
else
load_system_settings
end
refresh
end
end
class Game_Player < Game_Character
#--------------------------------------------------------------------------
# * Public Instance Variables
#--------------------------------------------------------------------------
attr_accessor :vehicle_getting_off
attr_accessor :direction
attr_accessor :vehicle_type
#--------------------------------------------------------------------------
# * Alias Listing
#--------------------------------------------------------------------------
alias dargor_vx_player_vehicle_update update
#--------------------------------------------------------------------------
# * Frame Update
#--------------------------------------------------------------------------
def update
dargor_vx_player_vehicle_update
if Input.trigger?(Vehicle::Key) and $game_switches[Vehicle::Switch]
get_on_fly
end
end
#--------------------------------------------------------------------------
# * Board Airship
#--------------------------------------------------------------------------
def get_on_fly
@vehicle_getting_on = true # Start boarding operation
@vehicle_type = 3 # Set vehicle type
@through = true # Passage ON
@walking_bgm = RPG::BGM::last # Memorize walking BGM
$game_map.fly.get_on # Boarding processing
end
#--------------------------------------------------------------------------
# * Get Off Vehicle
# Assumes that the player is currently riding in a vehicle.
#--------------------------------------------------------------------------
def get_off_vehicle
if in_airship? or @vehicle_type == 3 # Airship
return unless airship_land_ok?(@x, @y) # Can't land?
else # Boat/ship
front_x = $game_map.x_with_direction(@x, @direction)
front_y = $game_map.y_with_direction(@y, @direction)
return unless can_walk?(front_x, front_y) # Can't touch land?
end
$game_map.vehicles[@vehicle_type].get_off # Get off processing
if in_airship? or @vehicle_type == 3 # Airship or Flying
@direction = 2 # Face down
else # Boat/ship
force_move_forward # Move one step forward
@transparent = false # Remove transparency
end
@vehicle_getting_off = true # Start getting off operation
@move_speed = 4 # Return move speed
@through = false # Passage OFF
@walking_bgm.play # Restore walking BGM
make_encounter_count # Initialize encounter
end
end
#==============================================================================
# ** Game_Map
#------------------------------------------------------------------------------
# This class handles maps. It includes scrolling and passage determination
# functions. The instance of this class is referenced by $game_map.
#==============================================================================
class Game_Map
#--------------------------------------------------------------------------
# * Alias Listing
#--------------------------------------------------------------------------
alias dargor_vx_vehicle_map_create_vehicles create_vehicles
#--------------------------------------------------------------------------
# * Create Vehicles
#--------------------------------------------------------------------------
def create_vehicles
dargor_vx_vehicle_map_create_vehicles
@vehicles[3] = Game_Vehicle.new(3) # Fly
end
#--------------------------------------------------------------------------
# * Get Airship
#--------------------------------------------------------------------------
def fly
return @vehicles[3]
end
end
#==============================================================================
# ** Spriteset_Map
#------------------------------------------------------------------------------
# This class brings together map screen sprites, tilemaps, etc. It's used
# within the Scene_Map class.
#==============================================================================
class Spriteset_Map
#--------------------------------------------------------------------------
# * Update Airship Shadow Sprite
#--------------------------------------------------------------------------
def update_shadow
if $game_player.vehicle_type == 3
airship = $game_map.fly
else
airship = $game_map.airship
end
@shadow_sprite.x = airship.screen_x
@shadow_sprite.y = airship.screen_y + airship.altitude
@shadow_sprite.opacity = airship.altitude * 8
@shadow_sprite.update
end
end