Submit Your Article


 
RPG Maker

Welcome Guest ( Log In | Register )


  Games Resources RPG Maker VX RPG Maker XP Scripts Tutorials Downloads

 
Closed TopicStart new topic
> Super Simple Swimming System, can be used for climbing too
amaranth
post Mar 11 2009, 10:19 AM
Post #1


Level 6
Group Icon

Group: Member
Posts: 78
Type: Developer
RM Skill: Masterful




Introduction
Version 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.

Demo
Download Swimming System Demo Here

Steps
1. 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/Characters

3. 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 Usage
You 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


__________________________
Go to the top of the page
 
+Quote Post
   
MCgamer
post Mar 11 2009, 12:53 PM
Post #2


Level 3
Group Icon

Group: Member
Posts: 41
Type: Scripter
RM Skill: Skilled




This script is good and remarkably simple though I do have one problem with it. It uses the terrain_tag method provided by the Game_Map class. This is a faulty method. It can't take into account tile overlapping. It ignores any tile that has a terrain tag of zero. If you were to put a land tile on top of a water tile - which though most people don't do that, I have games where tiles get dynamically altered or overlapped, like in an experimental dungeon generator I've been cooking up- you end up with the guy still swimming.

[Show/Hide] Picture of problem




A quick solution would be to paste this following code snippet at the top of your code, so that it could take all possible scripting situations into account, by getting the topmost non blank tile and use that for the game.

CODE

class Game_Map

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 #change was made here from "@terrain_tags[tile_id] > 0"
return @terrain_tags[tile_id]
end
end
end
return 0
end


end



[Show/Hide] Picture of terrain tag with fix





Your script does however, have a problem of its own.
If a map has any events on it at all, besides the player, it generates an error because you have only defined the enter/exit water methods for the player class. Since all of the events inherit from Game_Character, they will make calls to those method as well, which they don't have.
Solution: add dummy methods to your Game_Character class to be overridden.

CODE

class Game_Character
...

def enter_water(swimmer)
#to be overridden by Game_Player
end
def exit_water(swimmer)
#to be over ridden by Game_Player
end
...
end






This post has been edited by MCgamer: Mar 11 2009, 01:35 PM


__________________________
March 4 2012: After 2 years, It's good to be back.
Go to the top of the page
 
+Quote Post
   
amaranth
post Mar 11 2009, 07:59 PM
Post #3


Level 6
Group Icon

Group: Member
Posts: 78
Type: Developer
RM Skill: Masterful




Okay, cool, I'll get this in the demo and script tomorrow w/credits. :-)


__________________________
Go to the top of the page
 
+Quote Post
   
MCgamer
post Mar 11 2009, 11:09 PM
Post #4


Level 3
Group Icon

Group: Member
Posts: 41
Type: Scripter
RM Skill: Skilled




~in a scottish accent~
yes, that's mi laddie over there dancing an irish gig. He says he's made game events swim in the loch, what ever that means huh.gif ?
~~
cool.gif cool.gif cool.gif

I have created a way to use your script so that game events can swim too.
All the programmer has to do is provide a picture of a character swimming, and have the regular walking form of the character go on to water.
The code will make the change to and from swimmer automatically.

It took more than a couple tweaks to the original so
here is the whole script with all the modifications I've made:

[Show/Hide] Swimming System 2.0

CODE


#####################################################
#Swimming System 2.0 By Amaranth
#####################################################


#additions by MCgamer
class Game_Map

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


#now $swimmers holds a list of the names of the game event pictures that have swimmer versions of themselves so
# if their walking form gets used by a map, this array will help make those events into swimmers automatically if on water.



#--------------------------------------------------------------------------
#--------------------------------------------------------------------------
class Game_Character
#--------------------------------------------------------------------------
#--------------------------------------------------------------------------




#--------------------------------------------------------------------------
# * Determine if Moving :note this method, originally provided by Game_Character
# was modified by Amaranth
#--------------------------------------------------------------------------
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 swimmer
#This is made based on an extrapolation of Amaranth's Game_Player changes
#--------------------------------------------------------------------------
def check_terrain_type()
@terrain = $game_map.terrain_tag(@x, @y)

name = @character_name
#check if event already is swimming.
#"swim" will be nill if name does not contain "-SWIM"
swim = name.match("-SWIM")


#feel free to change "3" to what ever tag you want
enter_water(swim) if @terrain == 3
exit_water(swim) if @terrain != 3

end

def enter_water(swim)
#The player class uses its own version of this method


#check if picture exists and not already swimming
if swim == nil and $swimmers.include?(@character_name)
@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 player
@step_anime = true
# Display swimming event
$game_map.refresh
return true
end

end

def exit_water(swim)

if swim != nil

# don't animate player while not in motion
@step_anime = false

# Display walking player
@character_name = @character_name.chomp("-SWIM")

$game_map.refresh

#Enable menu and save
$game_system.menu_disabled = false
$game_system.save_disabled = false

end

end

end

#########################################
#script created by Amaranth
#########################################


class Game_Player < Game_Character

#--------------------------------------------------------------------------
# * Refresh
#--------------------------------------------------------------------------
def refresh
# If party members = 0
if $game_party.actors.size == 0
# Clear character file name and hue
@character_name = ""
@character_hue = 0
# End method
return
end

# Get lead actor & show on map
actor = $game_party.actors[0]
if ($leader == 0)
@character_name = actor.character_name
else
@character_name = $leader
end
@character_hue = actor.character_hue

# Initialize opacity level and blending method
@opacity = 255
@blend_type = 0
end


#--------------------------------------------------------------------------
# * Enter water
#--------------------------------------------------------------------------
def enter_water(swim)

if swim == nil

#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 player
@step_anime = true

# Display swimming player
newname = $game_player.character_name + "-SWIM"
$leader = newname
$game_player.refresh
$game_map.refresh

return true

end

end

#--------------------------------------------------------------------------
# * Exit water
#--------------------------------------------------------------------------
def exit_water(swim)

if swim != nil

# don't animate player while not in motion
@step_anime = false

# Display walking player
newname = $game_player.character_name.chomp("-SWIM")

$leader = newname
$game_player.refresh
$game_map.refresh

#Enable menu and save
$game_system.menu_disabled = false
$game_system.save_disabled = false

end

end


end



To use just supply the Graphics/Character folder with a picture of the swimmer, like what was done before
If you export character pictures, leave the file's name unchanged (with one exception, you add "-SWIM" to it between the name and the type extension)

[Show/Hide] Picture of it working




This post has been edited by MCgamer: Mar 11 2009, 11:48 PM


__________________________
March 4 2012: After 2 years, It's good to be back.
Go to the top of the page
 
+Quote Post
   
amaranth
post Mar 12 2009, 07:29 PM
Post #5


Level 6
Group Icon

Group: Member
Posts: 78
Type: Developer
RM Skill: Masterful




That is awesome!!! Updating the first post and demo now. smile.gif


__________________________
Go to the top of the page
 
+Quote Post
   
CelestOrion
post Apr 15 2009, 12:15 PM
Post #6


Level 8
Group Icon

Group: Revolutionary
Posts: 119
Type: Writer
RM Skill: Intermediate




This is a great system, I can see myself using this for my Sonic RPG that I'm working on.


__________________________
Go to the top of the page
 
+Quote Post
   
Gary200
post Apr 16 2009, 12:55 AM
Post #7



Group Icon

Group: Member
Posts: 1
Type: None
RM Skill: Intermediate




This works really well. I love it, thanks!
Go to the top of the page
 
+Quote Post
   
Puppet Of Fate
post Apr 30 2009, 07:28 AM
Post #8


Please join my site!
Group Icon

Group: Revolutionary
Posts: 675
Type: Mapper
RM Skill: Advanced




It works quite nicely for what i'm cooking up.


__________________________
Go to the top of the page
 
+Quote Post
   
basicna
post May 8 2009, 03:49 AM
Post #9



Group Icon

Group: Member
Posts: 1
Type: None
RM Skill: Undisclosed




wow it nice.I'm love it.
Go to the top of the page
 
+Quote Post
   
Aqua7KH
post Sep 19 2011, 12:31 PM
Post #10



Group Icon

Group: Member
Posts: 3
Type: None
RM Skill: Undisclosed




would i be able to use this for a water world? (example: Atlantica in KH 1 and 2.)


__________________________
LOL RED RANGER.
Go to the top of the page
 
+Quote Post
   

Closed TopicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 

Lo-Fi Version Time is now: 20th May 2013 - 07:49 AM
RPG RPG Revolution is an Privacy Policy and Legal
eXTReMe Tracker