IntroductionVersion 2.0
by: Amaranth & MCgamer
This is a really simple script that allows you to make a character (including events) swim when they go into the water.
Note: This script can be easily modified for all sorts of systems: climbing, crawling, etc.DemoDownload Swimming System Demo HereSteps1. Add the
Swimming System script above Main:
CODE
#####################################################
#Swimming System 2.0 By Amaranth & MCgamer
#Last updated March 12, 2009
#####################################################
#--------------------------------------------------------------------------
#--------------------------------------------------------------------------
class Game_Map
#--------------------------------------------------------------------------
#--------------------------------------------------------------------------
#--------------------------------------------------------------------------
# * Return terrain ID for a tile
#--------------------------------------------------------------------------
def terrain_tag(x, y)
if @map_id != 0
for i in [2, 1, 0]
tile_id = data[x, y, i]
if tile_id == nil
return 0
elsif tile_id > 0
return @terrain_tags[tile_id]
end
end
end
return 0
end
end
#--------------------------------------------------------------------------
#--------------------------------------------------------------------------
# establish possible swimmers
#--------------------------------------------------------------------------
#--------------------------------------------------------------------------
$swimmers = []
graphics = []
graphics = Dir.entries("Graphics/Characters")
for file in graphics
if file.include?('-SWIM')
#take out "swim" and file extension
file.gsub!(/-SWIM.*/){||''}
#add name to end of array
$swimmers << file
end
end
#--------------------------------------------------------------------------
#--------------------------------------------------------------------------
class Game_Character
#--------------------------------------------------------------------------
#--------------------------------------------------------------------------
#--------------------------------------------------------------------------
# * Determine if Moving
#--------------------------------------------------------------------------
def moving?
# SWIMMING: Should character swim?
check_terrain_type()
# If logical coordinates differ from real coordinates,
# movement is occurring.
return (@real_x != @x * 128 or @real_y != @y * 128)
end
#--------------------------------------------------------------------------
# * Check the terrain for the character
#--------------------------------------------------------------------------
def check_terrain_type()
#get the terrain tag # upon which character is standing
@terrain = $game_map.terrain_tag(@x, @y)
#get the name of the character's graphic
name = @character_name
#check if character's swimming graphic is currently being used (nil if no)
swim = name.match("-SWIM")
#enter or exit water (change "3" to the tag you want for water)
enter_water(swim) if @terrain == 3
exit_water(swim) if @terrain != 3
end
#--------------------------------------------------------------------------
# * Enter the water (events only)
#--------------------------------------------------------------------------
def enter_water(swim)
# Check if picture exists and not already swimming
if swim == nil and $swimmers.include?(@character_name)
# Switch to swimming graphic
@character_name += "-SWIM"
# Disable menu and save
$game_system.menu_disabled = true
$game_system.save_disabled = true
# Play splash sound
Audio.se_play("Audio/SE/127-Water02", 50, 100)
# Animate sprite
@step_anime = true
# Display swimming event
$game_map.refresh
return true
end
end
#--------------------------------------------------------------------------
# * Exit the water (events only)
#--------------------------------------------------------------------------
def exit_water(swim)
# Check if picture is not walking sprite
if swim != nil
# don't animate player while not in motion
@step_anime = false
# Display walking player
@character_name = @character_name.chomp("-SWIM")
# Display walking event
$game_map.refresh
#Enable menu and save
$game_system.menu_disabled = false
$game_system.save_disabled = false
end
end
end
2. In your game's Graphic/Characters directory, add the swimming graphic for your hero. The swimming graphic MUST have the exact same name as your hero's graphic with "-SWIM" at the end of it. For example:
Hero Graphic:
Hero.png Hero Swimming Graphic:
Hero-SWIM.png Note: In the demo attached to this post, I've included a swimming hero, and two templates that you can use to create your own swim graphics. You can find these in Swimming/Graphic/Characters3. Now you must set the terrain tag for your water tiles. To do this:
-Open your project,
-Click Tools > Database
-Click the Tilesets tab
-In the Tileset list, select the tileset with the water.
-Click the Terrain Tag button. You'll see 0 appear over each tile.
-Click on the water tile until a 3 appears over it.
4. Your done! Test your game!
Credits and UsageYou can use this script in your freeware or commercial game. Please put Amaranth and MCgamer in your credits. Advanced developers, feel free to expand this script to create something even better. This is just a stepping stone for y'all.
Peace!!! :-)
This post has been edited by amaranth: Mar 12 2009, 08:12 PM