Chaos Project

RPG Maker => RPG Maker Scripts => RMXP Script Database => Topic started by: GasolineWaltz on November 19, 2010, 02:36:05 pm

Title: [XP] Run / Dash / Jump
Post by: GasolineWaltz on November 19, 2010, 02:36:05 pm
Run / Dash / Jump
Authors: GasolineWaltz
Version: 1.0
Type: Run and Jump System
Key Term: Custom Movement System



Introduction

This script started as part of a bigger project from a game that I'm working on, but it was getting too big and I decided to break it up for the moment. Basically, this provides the ability to run while pressing the A key, and jump when pressing the S key. For the first few seconds while running, the character is 'dashing' and can bump into things. Also, you can jump one more tile while dashing. The jump feature can be disabled with terrain tag #2.

I'm still kind of new to scripting so I wanted to get some opinions, I'd like to make it better... such as disabling jump when a message box is present but I'm not exactly sure how to do it. any feedback would be appreciated.


Features




Screenshots

<REQUIRED IF IT MAKES SENSE, IF NO PLEASE MENTION IT SO PEOPLE DON'T ASK>


Demo

http://www.mediafire.com/?fifxhfx5jk8fzci (http://www.mediafire.com/?fifxhfx5jk8fzci)



Script

Spoiler: ShowHide

#Run/Dash/Jump by GasolineWaltz
#=================================================
#This script allows you to dash, run and jump by pressing
#  the 'A' and 'S' keys. You can also have events interect
#  while dashing by calling $game_player.hit_wall.
#
#Jump can be disabled with the terrain tag 2.
#Run or Jump can be disabled / enabled by calling
#  $game_player.toggle_act('disable/enable', 'jump/run').
#
#$game_player.run_count accesses the players run counter
#  for status bars / event interactions
#
#$game_player.disable_jump/disable_run returns
#  the status of running of jumping.
#=================================================

class Game_Character
 attr_reader :run_count
 attr_reader :hit_wall
 attr_reader :disable_jump
 attr_reader :disable_run
 

alias move_initialize initialize
def initialize
move_initialize

@disable_jump = false
@disable_jump_check = false
@disable_run = false

@hit_wall = false
@hit_wall_effect = false
@running = false
@run_count = 300

@route = RPG::MoveRoute.new
end
end
#=======================

#=======================
class Game_Player < Game_Character

alias movement_update update
def update
movement_update

terrain_check
input_check
end
#-------------------------------------------------------------------------
def input_check

unless @disable_jump
jump_shoes if Input.trigger?(Input::Y)
end


unless @disable_run
if Input.press?(Input::X)
 if !@hit_wall
@running = true
running_shoes
run_counter(@run_count)
 else
@move_speed = 4
 end
else
 if @run_count < 300
restore_run(@run_count)
 end
 if @running
@move_speed = 4
@running = false
@hit_wall = false
@hit_wall_effect = false
 end
end
end

end
#-------------------------------------------------------------------------
def direction_get
x_dir = (@direction == 6 ? 1 : @direction == 4 ? -1 : 0)
y_dir = (@direction == 2 ? 1 : @direction == 8 ? -1 : 0)
return [x_dir, y_dir]
end
#-------------------------------------------------------------------------
def terrain_tag_get(x = @x,y = @y)
return $game_map.terrain_tag(x,y)
end
#-------------------------------------------------------------------------
def terrain_check
t_tag = terrain_tag_get
dir   = direction_get
case t_tag
when 2           #tiles that cannot be jumped on
if !@disable_jump           #checks to see if jump is already disabled.
@disable_jump = true
@disable_jump_check = true
end
end

if t_tag != 2 && @disable_jump_check == true
@disable_jump = false
@disable_jump_check = false
end

end
#-------------------------------------------------------------------------
def toggle_act(function = '', act = '')
case function
when 'disable'
 a = true
when 'enable'
 a = false
end
case act
when 'jump'
 @disable_jump = a
when 'run'
 @disable_run = a
end
 end


#=============================================
#Jump Shoes
#=============================================

def jump_shoes

x_dir = direction_get[0]
y_dir = direction_get[1]


jump_skill = $game_variables[30]
jump_distance = 0
passable_jump = $game_map.passable?(@x + (x_dir * 2), @y + (y_dir * 2), @direction)
passable_run_jump = $game_map.passable?(@x+(x_dir * 3), @y+(y_dir*3),@direction)
game_events = $game_map.events[$game_map.check_event(@x + (x_dir * 2), @y + (y_dir * 2))]
run_jump_events = $game_map.events[$game_map.check_event(@x+(x_dir*3),@y+(y_dir*3))]
clear_a = true
clear_b = true

if game_events
clear_a = game_events.through
elsif run_jump_events
clear_b = run_jump_events.through
end

if clear_b && passable_run_jump && Input.dir4 > 0 && @move_speed == 6
jump_distance = 3
else
if clear_a && passable_jump && Input.dir4 > 0
jump_distance = 2
else
jump_distance = 0
end
end

jump_move(x_dir, y_dir, jump_distance)
Audio.se_play("Audio/SE/016-jump02")
end
#-------------------------------------------------------------------------
def jump_move(x, y, d)
@route.list.clear
@route.list.push(RPG::MoveCommand.new(37))
@route.list.push(RPG::MoveCommand.new(14, [x * d, y * d]))
@route.list.push(RPG::MoveCommand.new(38))
@route.list.push(RPG::MoveCommand.new(0))
@route.repeat = false


$game_player.force_move_route(@route)
end

#===========================
#Running Shoes
#===========================

def running_shoes

x_dir = direction_get[0]
y_dir = direction_get[1]
hit_wall = $game_map.passable?(@x + x_dir, @y + y_dir, @direction)
hit_event = $game_map.events[$game_map.check_event(@x + x_dir, @y + y_dir)]
event_through = true
if hit_event
event_through = hit_event.through
end

case @run_count
when 260..300
 @move_speed = 6
if !hit_wall && moving?
@hit_wall_effect = true
elsif @hit_wall_effect && !moving?
wall_hit
end

if hit_event && event_through == false && moving?
@hit_wall_effect = true
elsif @hit_wall_effect && !moving?
wall_hit
end
when 2..259
 @move_speed = 5
when 0..1
 @move_speed = 3
end
end
def run_counter(run_time)
if run_time > 0 && moving?
 run_time -= 2
 @run_count = run_time
 return run_time
end
end
def restore_run(run_restore)
 run_restore += 1
 @run_count = run_restore
end
#-------------------------------------------------------------------------
def wall_hit
Audio.se_play("Audio/SE/052-cannon01",80,130)
$game_screen.start_flash(Color.new(200,0,100,35), 2)
$game_screen.start_shake(4, 6, 10)
@hit_wall_effect = false
@hit_wall = true
end
end




Instructions

In the script



Compatibility

No issues known.



Credits and Thanks




Author's Notes

[EDIT]
sorry about not using the template :^_^':

"I would Like to thank Ryex for properly applying the template" or at least that is what I would say ~ Ryex
Title: Re: Run / Dash / Jump
Post by: Blizzard on November 20, 2010, 05:20:59 am
http://forum.chaos-project.com/index.php/topic,17.0.html