Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

Player : Dash

Player : Dash
Version: 3.5
By: Kain Nobel

Introduction

This is a running (or "dashing" if we may) system, requested by Reon-Eclispe, which allows the player to dash for a designated period of time until they've depleted their stamina. The settings are instances of Game_Player::Dash, meaning you'll be able to modify, save and load them between game sessions.

I hate to say it but the settings are a bit touchy, you might want to experiment with whatever is suitable for your game. However, I'm sure you'll enjoy it once you get the hang of it!

Features

  • One-button running feature!
  • Easy to setup and control!
  • Customizable speeds for different movement phases
  • Player can be exhausted from running too much
  • Compatable with my Vehicles XP (not yet released)
  • Probably other stuff I'm too lazy to list right now

Script

Code:
#===============================================================================

# ** Player : Dash

#===============================================================================

 

#-------------------------------------------------------------------------------

# * SDK Log

#-------------------------------------------------------------------------------

SDK.log('Player.Dash', 'Kain Nobel ©', 3.5, '2009.06.17')

#-------------------------------------------------------------------------------

# * SDK Enabled Test : Begin

#-------------------------------------------------------------------------------

if SDK.enabled?('Player.Dash')

 

#===============================================================================

# ** Game_Player::Dash

#===============================================================================

 

class Game_Player::Dash

  #-----------------------------------------------------------------------------

  # * Switch which disables the dash system and HUD

  #-----------------------------------------------------------------------------

  Switch_Disable = 1

  #-----------------------------------------------------------------------------

  # * Switch which disables exhaustion

  #-----------------------------------------------------------------------------

  Switch_Exhaust = 2

  #-----------------------------------------------------------------------------

  # * Maps which disable the dash system and HUD

  #-----------------------------------------------------------------------------

  Maps_Disabled  = []

  #-----------------------------------------------------------------------------

  # * Scenes which don't display dash HUD (alternate scenes with Spriteset_Map)

  #-----------------------------------------------------------------------------

  Scenes_Disabled = true

  #-----------------------------------------------------------------------------

  # * Button used for Dashning

  #-----------------------------------------------------------------------------

  Button = Input::C

  #-----------------------------------------------------------------------------

  # * Public Instance Variables

  #-----------------------------------------------------------------------------

  attr_accessor :slow_speed

  attr_accessor :walk_speed

  attr_accessor :dash_speed

  attr_accessor :stamina

  attr_accessor :points

  #-----------------------------------------------------------------------------

  # * Object Initialization

  #-----------------------------------------------------------------------------

  def initialize

    @slow_speed   = 3                       # Speed for when player is exhausted

    @walk_speed   = 3.5                     # Speed for when player is walking

    @dash_speed   = 5                       # Speed for when player is dashing

    @stamina      = 1                       # Steps player can take while dashing

    @stamina_rate = 0.01                    # Frames that stamina is replenished

    @exhersion    = @stamina / 8            # At the point where player exhausted

    @points       = @stamina                # Sets points to stamina (don't touch)

  end

  #-----------------------------------------------------------------------------

  # * Enabled?

  #-----------------------------------------------------------------------------

  def enabled?

    return false if $game_switches[Switch_Disable]

    return false if Maps_Disabled[$game_map.map_id]

    if Scenes_Disabled == true

      return false unless $scene.is_a?(Scene_Map)

    else

      return false if Scenes_Disabled.include?($scene.class.to_s)

    end

    return true

  end

  #-----------------------------------------------------------------------------

  # * Increase Points

  #-----------------------------------------------------------------------------

  def increase_points(n)

    @points = [[@points + n, @stamina].min, 0].max

  end

  #-----------------------------------------------------------------------------

  # * Decrease Points

  #-----------------------------------------------------------------------------

  def decrease_points(n)

    increase_points(-n)

  end

  #-----------------------------------------------------------------------------

  # * Update

  #-----------------------------------------------------------------------------

  def update

    unless enabled?

      update_disabled

      return

    end

    @disabled = false

    if idle?

      update_idle

      return

    elsif exhausted?

      update_exhausted

      return

    elsif walking?

      update_walking

      return

    elsif dashing?

      update_dashing

      return

    end

  end

  #-----------------------------------------------------------------------------

  # * Update Disabled

  #-----------------------------------------------------------------------------

  def update_disabled

    unless @disabled

      $game_player.move_speed = (Game_Player.new).move_speed

      @disabled = true

    end

  end

  #-----------------------------------------------------------------------------

  # * Idle?

  #-----------------------------------------------------------------------------

  def idle?

    !$game_player.moving?

  end

  #-----------------------------------------------------------------------------

  # * Exhausted?

  #-----------------------------------------------------------------------------

  def exhausted?

    @exhausted && !$game_switches[Switch_Exhaust]

  end

  #-----------------------------------------------------------------------------

  # * Walking?

  #-----------------------------------------------------------------------------

  def walking?

    return true if $game_player.move_route_forcing

    $game_player.moving? && !Input.press?(Button)

  end

  #-----------------------------------------------------------------------------

  # * Dashing?

  #-----------------------------------------------------------------------------

  def dashing?

    return false if $game_system.map_interpreter.running?

    return false if $game_temp.message_window_showing

    return false if $game_player.move_route_forcing

    $game_player.moving? && Input.press?(Button)

  end

  #-----------------------------------------------------------------------------

  # * Update Idle

  #-----------------------------------------------------------------------------

  def update_idle

    increase_points(exhausted? ? @stamina_rate * 0.5 : @stamina_rate)

    if @points > (@exhersion)

      @exhausted = false

    end

  end

  #-----------------------------------------------------------------------------

  # * Update Exhausted

  #-----------------------------------------------------------------------------

  def update_exhausted

    $game_player.move_speed = @slow_speed

    increase_points(@stamina_rate * 0.5)

    if @points > (@exhersion)

      @exhausted = false

    end

  end

  #-----------------------------------------------------------------------------

  # * Update Walking

  #-----------------------------------------------------------------------------

  def update_walking

    $game_player.move_speed = @walk_speed

    increase_points(@stamina_rate * 0.5)

  end

  #-----------------------------------------------------------------------------

  # * Update Dashing

  #-----------------------------------------------------------------------------

  def update_dashing

    unless $game_player.move_speed == @dash_speed

      $game_player.move_speed += (@dash_speed * 0.1)

      return

    end

    decrease_points(@stamina_rate * 2)

    if @points.zero?

      @exhausted = true

    end

  end

  #-----------------------------------------------------------------------------

  # * Last Move

  #-----------------------------------------------------------------------------

  def last_move

    return 0 if idle?

    return 1 if exhausted?

    return 2 if walking?

    return 3 if dashing?

  end

end

 

#===============================================================================

# ** Game_Player

#===============================================================================

 

class Game_Player < Game_Character

  #-----------------------------------------------------------------------------

  # * Public Instance Variables

  #-----------------------------------------------------------------------------

  attr_accessor :move_speed

  #-----------------------------------------------------------------------------

  # * Alias Listings

  #-----------------------------------------------------------------------------

  alias_method :dashsystem_gmplayer_updateplayermove, :update_player_movement

  #-----------------------------------------------------------------------------

  # * Dash

  #-----------------------------------------------------------------------------

  def dash

    @dash ||= Game_Player::Dash.new

    @dash

  end

  #-----------------------------------------------------------------------------

  # * Update

  #-----------------------------------------------------------------------------

  def update_player_movement

    dashsystem_gmplayer_updateplayermove

    @dash.update

  end

end

 

#===============================================================================

# ** Window_DashStamina

#===============================================================================

 

class Window_DashStamina < Window_Base

  #-----------------------------------------------------------------------------

  # * Object Initialization

  #-----------------------------------------------------------------------------

  def initialize

    super(0, 416, 160, 64)

    self.contents = Bitmap.new(width - 32, height - 32)

    self.opacity = 0

    refresh

  end

  #-----------------------------------------------------------------------------

  # * Refresh

  #-----------------------------------------------------------------------------

  def refresh

    self.contents.clear

    @points    = $game_player.dash.points

    @last_move = $game_player.dash.last_move

    self.contents.draw_seph_gradient_bar(0, 0, @points,

    $game_player.dash.stamina, 128)

    if $game_player.dash.idle?

      color = ($game_player.dash.exhausted? ? Color.new(255,0,0) : normal_color)

      self.contents.font.color = color

      self.contents.draw_text(0, 0, 128, 32, "Idle", 1)

    elsif $game_player.dash.exhausted?

      self.contents.font.color = Color.new(255,0,0)

      self.contents.draw_text(0, 0, 128, 32, "Exhausted", 1)

    elsif $game_player.dash.walking?

      self.contents.font.color = normal_color

      self.contents.draw_text(0, 0, 128, 32, "Walking", 1)

    elsif $game_player.dash.dashing?

      self.contents.font.color = system_color

      self.contents.draw_text(0, 0, 128, 32, "Dashing", 1)

    end

  end

  #-----------------------------------------------------------------------------

  # * Update?

  #-----------------------------------------------------------------------------

  def update?

    need_update = false

    need_update |= $game_player.dash.points    != @points

    need_update |= $game_player.dash.last_move != @last_move

    (need_update && Graphics.frame_count % 4 == 1)

  end

  #-----------------------------------------------------------------------------

  # * Update

  #-----------------------------------------------------------------------------

  def update

    self.visible = $game_player.dash.enabled?

    if update?

      refresh

    end

  end

end

 

#===============================================================================

# ** Spriteset_Map

#===============================================================================

 

class Spriteset_Map

  #-----------------------------------------------------------------------------

  # * Alias Lisitngs

  #-----------------------------------------------------------------------------

  alias_method :dashsystem_ssmap_initialize, :initialize

  alias_method :dashsystem_ssmap_update,     :update

  alias_method :dashsystem_ssmap_dispose,    :dispose

  #-----------------------------------------------------------------------------

  # * Object Initialization

  #-----------------------------------------------------------------------------

  def initialize

    @window_dashstamina = Window_DashStamina.new

    dashsystem_ssmap_initialize

  end

  #-----------------------------------------------------------------------------

  # * Update

  #-----------------------------------------------------------------------------

  def update

    @window_dashstamina.update

    dashsystem_ssmap_update

  end

  #-----------------------------------------------------------------------------

  # * Dispose

  #-----------------------------------------------------------------------------

  def dispose

    @window_dashstamina.dispose

    dashsystem_ssmap_dispose

  end

end

 

#-------------------------------------------------------------------------------

# * SDK Enabled Test : End

#-------------------------------------------------------------------------------

end

Instructions

Place below SDK/MACL and above Main! Setup is handled by the constants in the top of the script, if you have any questions or are confused don't hesitate to ask! This script uses the following method from MACL's "RGSS.Bitmap.gradient" library...

Bitmap.draw_seph_gradient_bar

Compatibility

Requires SDK stuffs, you can easily alias Game_Player::Dash.enabled? to allow other scripts to disable this system. This script is compatable with my Vehicles XP system (which I haven't released yet.)

Please note, this will corrupt old save files.

Credits and Thanks

Thanks to Reon-Eclispe for making the request, it was fun and I enjoyed doing this one!

Terms and Conditions

Free to use in commercial and non-commercial projects, please credit me for my work!
 
Small update! Player won't run during evented moveroutes or anything anymore! Same update applied to jump script too (no jumping during messages lol) :P

Also, I realised some people might get a problem because Game_Player#@move_speed isn't an attr_accessor, so I updated that too.

Happy 4th people!
 
I'm not sure how you would've gotten the error, do you have any scripts that make a custom initialize method for Game_Player class without calling an alias or alias_method? If you do, you might want to try and put it below those scripts, when in doubt put it as your last custom script but above main.

Also, this snippet might help, place it somewhere within the script itself...

class Game_Player
def dash
@dash ||= Game_Player::Dash.new
@dash
end
end

That'll ensure, if @dash is nil, then it is loaded. If you're still having problems, you might want to list your custom scripts you're using and I'll try and help you out. Best bet would be sending me a demo or just your Scripts.rxdata file, that would be the easiest way for me to find out why it isn't working.
 
I don't know what I'm doing wrong, but I can't get this script to work at all. I'd really like to use it but it just doesn't seem to want to work.

To make sure it wasn't conflicting with anything I made an entirely new project and added the SDK, MACL, and Player : Dash. No matter what I do nothing from this script works except the dash bar and text which appear (and have that irritating flashing thing...). I've tried changing the stamina, and I've even lowered the walking speed to 1 and the character doesn't move any slower.

And the SDK breaks Sideview Battle System Tankentai XP - Version 2.2xp so I'd appreciate it if you could possibly make it compatible without the SDK?

This really is a great idea and if I could get it to work I'd absolutely love it I'm sure. Thank you for your time.
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top