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.

Dashing with stamina bar and "level-up" ability

Dashing with stamina bar and "level-up" ability

Hi, I've been in need of a dash script and have found like 5 different ones made by different people, but all of them are tied to other scripts, change sprites, have no limit, or lack the visual stamina bar feature I need (and some other stuff). it's hard to explain directly, I'll just break it down. The best example is the diablo 2 stamina system except this one doesn't toggle and you can't use potions.

~Detailed Description~
â–º Hold a button to dash (Left Shift would be nice), this would simply increase movement speed to 4*
â–º It will utilize a dash level system in which the max stamina points increase with each level, and some other things
- at dash level 1 you have 100 stamina points*
â–º Dash Leveling up can be done by calling a method (via an event or another script)
â–º Have not decided on a straight forward amount to increment the stamina points and replenish rates per level, testing will be needed, but for now a level up will do the following: *
- stamina_points = stamina_points * 1.25
- stand_replenish_rate = stand_rep_rate * 1.25
â–º your stamina will always deplete at a rate of 20 points/s regardless of level*
â–º If you don't move your stamina bar replenishes at a rate with respect to your dash level
- at dash level 1 it replenishes at a rate of 5 points a second (5 point/s) *
- NOTE: Of course, when dashing make sure it doesn't replenish, but if the player is holding the dash button while standing still it will replenish normally
â–º If you walk your stamina bar replenishes 1/4 as fast as standing still *
- walk_replenish_rate = stand_replenish_rate / 4
- so for level 1 it would be 5/4 (1 point/s)
â–º Stamina bar will be pretty much like any other stat bar in the game (but doesn't show any numbers), it will show up on the top left corner about 15 pixels from the top and left of the screen
- it could be moved/hidden by modifying variables through a script call in an event (for cut scenes, world map, crippled, etc...)
- colors could be similar to the color I have in the example.
- the bar should be drawn the same way an HP/MP bar is drawn (or nicer then that if you feel creative)
â–º If the player hits 0 stamina then he gets penalized:
- unable to dash for 20 seconds; however replenishes stamina normally.
- moves slower for 20 seconds (speed 2)
- stamina bar color changes to red for 20 seconds
Note: I guess it's because were on the temporary host or whatever, but the '-' are sub-points and are supposed to be indented a little to show that... Just a heads-up.
* These can be hard coded but have them in variables so I can change them easily if necessary.
Note 2: All variables should be integers, if using doubles in the formulas then we can type cast the integer and then let the stuff after the decimal get truncated.

~Example picture~
Yea it sucks, anyways we can draw the bar using RGSS right?
barirb.jpg


~Other Scripts~
● SDK 1.5
● AMS R4 [Update #2]
● AutoLife Skill by シムナフ
● Limit Break -SDK- v1 by SephirothSpawn
● Particle Engine -SDK- v2 by Near Fantastica
● Ring Menu Release #1 (Enhanced By Dubealex) by 和希
● View/Sound Range v2 by Near Fantastica
● Weapon Unleashed
● Path Finding v1 by Near Fantastica
● Distance Checking by DrakoShade
● Quest Log by coolmariner98 and Jaberwocky
● SBS v2.1xp (Atoa) by Enu

I am aware there are newer releases of a lot of these scripts but I have tried updating most of them and it has lead to problems or me having to modify over 500 events because the the way to use the script was changed. So far I have not run into any issues with them and probably will not since I have used them extensively in my project.


Thanks!
 
this is probably totally wrong but it's pretty much all I can do at the moment. I have no idea how to use it.
-Do I need to create an object through an event?
-Am I actually supposed to overload another class or is making my own fine?
-I have no clue how to draw the stamina bar because most tutorials only show how to do it in a window (creating a class which inherits window_base or whatever) which I don't want, I just want the bar on the top left and nothing else, no text, no window.
-Another problem is that if the player is running/walking into a wall the script thinks he is moving in that direction, I'm not sure on how to test if the player is actually moving or not. would probably add that as a conditions.
-also I don't understand why rpg maker wants another "end" at the end... I made sure to balance the "end" stuff

Thanks!

[rgss]class Realistic_Dash
 
  #-----------------------------------------------------------------------------
  def initialize
    @current_speed = 3      #Speed when not dashing
    @dash_speed = 4      #Speed when dashing
    @allow_dash = true      #Player can dash?
    @show_bar = true      #Show stamina bar?
    @penalized = false      #Player penalized?
    @penalize_time = 20      #How long player will stay penalized (seconds)
    @penalize_counter = 0
    @stamina_depletion_rate = 20      #points per second
    @stamina_replenish_rate = 5      #points per sec (not moving)
    @dash_level = 1      #initial dash level only purpuse is displaying the level
    @max_stamina = 100      #max stamina for first level
    @current_stamina = @max_stamina
  end
 
  #-----------------------------------------------------------------------------
  def update
    if(@allow_dash)
      if Input.press?(Input::A && !@penalized)
        @current_speed = @dash_speed
        update_stamina(true)
        if(@show_bar) then update_stamina_bar() end
      else if(@penalized)
        @current_speed = 2
        update_stamina(true)
        if(@show_bar) then update_stamina_bar() end
      else
        @current_speed = 3
        update_stamina(true)
        if(@show_bar) then update_stamina_bar() end
      end
    end
  end
 
 #------------------------------------------------------------------------------
 #   Stamina updater accepts a boolean as a parameter, then checks to see
 #   exactly what the player is doing and replenishes or depletes stamina
 #   accordingly. Also penalizes the player if stamina hits 0.
 #------------------------------------------------------------------------------
  def update_stamina(dashing)
    #If player is holding the dash button
    if(dashing)
      if Input.press?(Input::UP || Input::DOWN || Input::LEFT || Input::RIGHT)
        if(Graphics.frame_count/Graphics.frame_rate == 1)      #exec per second
          if(!@penalized)
            @current_stamina -= @stamina_depletion_rate
            if(@current_stamina <= 0)      #has stamina hit 0 yet?
              @current_stamina = 0
              penalized = true
            end
          else
            @penalize_counter++
            if(@penalize_counter >= @penalize_time)
              @current_speed = 3
              @penalize_counter = 0
              @penalized = false
            end
          end
        end
      else
        if(Graphics.frame_count/Graphics.frame_rate == 1)      #exec per second
          if(!@penalized)
            @current_stamina += @stamina_replenish_rate
            if(@current_stamina > @max_stamina)      #has stamina hit max yet?
              @current_stamina = @max_stamina
            end
          else
            @penalize_counter++
            if(@penalize_counter >= @penalize_time)
              @current_speed = 3
              @penalize_counter = 0
              @penalized = false
            end
          end
        end
      end
    #If player is not holding the dash button
    else
      if Input.press?(Input::UP || Input::DOWN || Input::LEFT || Input::RIGHT)
        if(Graphics.frame_count/Graphics.frame_rate == 1)      #exec per second
          if(!@penalized)
            @current_stamina += @stamina_replenish_rate/4
            if(@current_stamina > @max_stamina)      #has stamina hit max yet?
              @current_stamina = @max_stamina
            end
          else
            @penalize_counter++
            if(@penalize_counter >= @penalize_time)
              @current_speed = 3
              @penalize_counter = 0
              @penalized = false
            end
          end
        end
      else
        if(Graphics.frame_count/Graphics.frame_rate == 1)      #exec per second
          if(!@penalized)
            @current_stamina += @stamina_replenish_rate
            if(@current_stamina > @max_stamina)      #has stamina hit max yet?
              @current_stamina = @max_stamina
            end
          else
            @penalize_counter++
            if(@penalize_counter >= @penalize_time)
              @current_speed = 3
              @penalize_counter = 0
              @penalized = false
            end
          end
        end
      end
    end
  end
 
  #-----------------------------------------------------------------------------
  def update_stamina_bar()
    if(!@penalized)
      #Bar color is yellow
    else
      #Bar color is red
    end
    #draw bar using current stamina and max stamina, no numbers or words
  end
 
  #-----------------------------------------------------------------------------
  def level_up()
    @dash_level++
    @max_stamina += @max_stamina / 4
    @stamina_replenish_rate += @stamina_replenish_rate / 4
  end
end
[/rgss]

edit: added level up method and fixed a few minor conditions. Well I just finished burning prototype so I'm off to play that since I can't bump this for 3 days anyways.
 
Y'know what, I read your request like a week ago and really liked it for some reason... besides that, I needed to update my run system and my Test Bed entirely anyway so here, tell me if this'll work for you because I designed it with your request in mind...

This is the method that you'll need for the bar to draw... I didn't post the whole MACL, just the one method used incase you don't have MACL installed.

Code:
class Bitmap

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

  # * Name      : Draw Gradient Bar

  #   Info      : Draws a Gradient Bar

  #   Author    : SephirothSpawn

  #   Call Info : Four to Nine Arguments

  #               Integer x and y Defines Position

  #               Integer min and max Defines Dimensions of Bar

  #               Start Bar Color and End Color - Colors for Gradient Bar

  #               Background Bar Color

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

  def draw_seph_gradient_bar(x, y, cur, max, width = 152, height = 8,

      s_color = Color.red, e_color = Color.yellow, b_color = Color.black)

    # Draw Border

    self.fill_rect(x, y, width, height, b_color)

    # Draws Bar

    for i in 1...((cur / max.to_f) * (width - 1))

      c = Color.color_between(s_color, e_color, (i / width.to_f))

      self.fill_rect(x + i, y + 1, 1, height - 2, c)

    end

  end

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

# ** Game_Player::Dash

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

 

class Game_Player::Dash

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

  # * 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      = 5                     # Steps player can take while dashing

    @stamina_rate = 0.1                   # Frames that stamina is replenished

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

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

  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

    if idle?

      update_idle

      return

    elsif exhausted?

      update_exhausted

      return

    elsif walking?

      update_walking

      return

    elsif dashing?

      update_dashing

      return

    end

  end

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

  # * Idle?

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

  def idle?

    !$game_player.moving?

  end

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

  # * Exhausted?

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

  def exhausted?

    @exhausted

  end

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

  # * Walking?

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

  def walking?

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

  end

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

  # * Dashing?

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

  def dashing?

    $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 :dash

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

  # * Alias Listings

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

  alias_method :dashsystem_gmplayer_initialize,       :initialize

  alias_method :dashsystem_gmplayer_updateplayermove, :update_player_movement

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

  # * Object Initialization

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

  def initialize

    dashsystem_gmplayer_initialize

    @dash = Game_Player::Dash.new

  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

    if update?

      refresh

    end

  end

end

 

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

# ** Scene_Map

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

 

class Scene_Map < SDK::Scene_Base

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

  # * Alias Lisitngs

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

  alias_method :dashsystem_snmap_mainwindow, :main_window

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

  # * Main Window

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

  def main_window

    dashsystem_snmap_mainwindow

    @window_dashstamina = Window_DashStamina.new

  end

end

 

IDK how different SDK 1.5 is from 2.0+ but I'm assuming it'll work just fine. If you encounter any compatability issues, please paste the entire SDK 1.5 @ here and PM me so I can take a look at the differences and make it work.

There is a small glitch where sometimes the display will flicker between Idle and whatever when you're obviously moving, I tried to find a remedy for that but no avail. This obviously won't crash your game because it is more of a little visual quirk. If you find it unnecessary, then comment out or delete the self.contents.draw_text lines in Window_DashStamina.

Alternatively, you can tweak the number on this line and see if that helps if you find it annoying...

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

Blame Ruby or silly Enterbrain for its slowness on detecting things like that...

Few more things I'm probably going to do with this... for instance my old 'Player.Run' script (which is different from this) disabled "running" (or "dashing" if we will) on certain maps or if a certain switch was on. Just small things like that...

If you're ever in question of an update, you can PM me and I'll send it to ya. Any future version of this should work just like the current version I just posted now, but with extra features.

Enjoy! :thumb:

PS: This was a pretty fun request.
 
You should remember to reply to your requests, that way I don't feel like I did it for nothing! Please look in Submitted Scripts section for "Player : Dash" because I've updated the script there. Player won't be considered "running" while against a wall, no more allowing the player to run during forced moveroutes anymore either :P

There's no "Level-up" ability but that should be easy enough to do through events (or CommonEvents)... just use a call script, and these settings will be saved too when you save your game.

Code:
$game_player.dash.slow_speed += (number)

$game_player.dash.walk_speed += (number)

$game_player.dash.dash_speed += (number)

$game_player.dash.stamina += (number)

$game_player.dash.stamina_rate += (number)

...I think you get the idea...[/code]
 

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