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.

Simple request: Running?

uupa99

Member

Im kind of a noob so sorry if this is very simple or something. I have searched aorund the forum a bit and haven't found anything. Specificaly, what I want is to have a normal speed, 3, which will be walking. No buttons pressed to active that. however, I would like it so when you hit or hold, lets say Z, the speed goes to maybe 4 and that would be like running.

Also, what would be nice, but I don't really NEED it, is also when you hit the button for running, the spirte changes to something else like lets say the same person only looking like he is running.

Can someone tell me how to do this please?
 
Seph was going to put this in his test bed, but I don't see it????

I'm sure this was done before, but I don't seem to be able to find either one, so....

Code:
#
#  Super Simple Dash - V1
#
#  Hold the "Z" key to make the player run
#
#  paste in a new script above main
#
#  Brewmeister - 12Jan09
#

class Game_Player

  alias brew_dash_update update

  def update
    if Input.press?(Input::A)
      @move_speed=5
    else
      @move_speed=4
    end
    brew_dash_update
  end
end

Hmm, didn't realize it was quite this simple until I tried it.

Be Well

[edit] oops, forgot the sprite change. I'll work on that then update.
 
Ok, here's V2, with the character set change...

Code:
#
#  Super Simple Dash - V2
#
#  Hold the "Z" key to make the player run
#
#  paste in a new script above main
#
#  Brewmeister - 12Jan09
#
#  ADDED: Change character set when running.
#  create a running character set. Add "_dash" to the filename.
#  e.g.  001-Fighter01.png  &   001-Fighter01_dash.png
#  checks for file, so it will work without one.

class Game_Player

  attr_accessor   :character_name           # character file name
  attr_accessor   :current_speed

  alias brew_dash_init initialize
  alias brew_dash_update update

  def initialize
    @current_speed = 4
    brew_dash_init
  end
  
  def update
    if Input.press?(Input::A)
      @move_speed=5    #set the fast speed here
      if @move_speed != @current_speed
        #check to see if dash file exists
        begin
          # Check that the graphics for the new character name actually exists
          RPG::Cache.character(@character_name + "_dash.png", 0)
          # Change it now that we know it exists
          @character_name += "_dash"
        rescue
          # The dash graphics does not exist.
        end
        @current_speed = @move_speed
      end
    else
      @move_speed=4    #set the normal speed here
      if @move_speed != @current_speed
        #remove _dash from the graphic name if it exists
        @character_name = @character_name.sub(/_dash/) {}
        @current_speed = @move_speed
      end
    end
    brew_dash_update
  end
end

Ref: furryman_battle_commands
 

Zeriab

Sponsor

Hey brew

Code:
if FileTest.exist?("Graphics/Characters/" + @character_name + "_dash.png")
That is a dangerous construct since it will fail both if the project is compressed and if the file exists in the RTP. It's mostly the former issue which is of concern.
Instead I would suggest trying to cache the character since that can retrieve the graphics from the encrypted archive.
Code:
    begin
      # Check that the graphics for the new character name actually exists
      RPG::Cache.character(("Graphics/Characters/" + @character_name + "_dash.png"),0)
      # Change it now that we know it exists
      @character_name += "_dash"
    rescue
      # The dash graphics does not exist.
    end

*hugs*
- Zeriab
 
Brew, I wouldn't suggest changing the @character_name, but the attr_reader method, character_name.

Code:
class Game_Character
  alias_method :brew_dashing_gmchr_cn, :character_name
  def character_name
    s = brew_dashing_gmchr_cn.to_s
    s += '_dash' if dashing?
    return s
  end
  def dashing?
    return @dashing
  end
end

Now where you would modify the @charcter_name, just set @dashing = true/false.

I've learned modifying instance variables can cause incompatibility errors, where modify reader methods is less dangerous. :)
 
Cool. I scratched my head about leaving the @character_name alone, if for nothing else to make sure it never got set to <charname>_dash_dash
Just wasn't sure of the most efficient way to do it.
Thanks

Code:
#
#  Super Simple Dash - V3
#
#  Hold the "Z" key to make the player run
#
#  paste in a new script above main
#
#  Brewmeister - 12Jan09
#  Zeriab - change Filetest to Cache.character to see if file exists.
#  Seph - modify the attr_reader method character name instead of
#         directly changing the instance variable. (safer)
#
#  ADDED: Change character set when running.
#  create a running character set. Add "_dash" to the filename.
#  e.g.  001-Fighter01.png  &   001-Fighter01_dash.png
#  checks for file, so it will work without one.

class Game_Character
  alias_method :brew_dashing_gmchr_cn, :character_name
  def character_name
    s = brew_dashing_gmchr_cn.to_s
    s += '_dash' if dashing?
    return s
  end
  def dashing?
    return @dashing
  end
end

class Game_Player

  attr_accessor   :current_speed

  alias brew_dash_init initialize
  alias brew_dash_update update

  def initialize
    @current_speed = 4
    brew_dash_init
  end
  
  def update
    if Input.press?(Input::A)
      @move_speed = 5    #set the fast speed here
      if @move_speed != @current_speed
        #check to see if dash file exists
        begin
          # Check that the graphics for the new character name actually exists
          RPG::Cache.character(@character_name + "_dash", 0)
          # Change it now that we know it exists
          @dashing = true
        rescue
          # The dash graphics does not exist.
        end
        @current_speed = @move_speed
      end
    else
      @move_speed = 4    #set the normal speed here
      if @move_speed != @current_speed
        #remove _dash from the graphic name if it exists
        @dashing = false
        @current_speed = @move_speed
      end
    end
    brew_dash_update
  end
end
 
Oh, I have a question for something a bit more elaborate. My game switches back and forth between sprites, depending on what area you are going through, sideview or overhead.

rockfinishedsprite2copyzg7.png
rockdungeonspritekd7.png
Can I make it so the script is like, disabled or something when a transition is made between maps so he can't run at certain points? It would greatly reduce the amount of sprite work I'd have to do.
 

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