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 : Jump

Player : Jump
Version: 3.5
By: Kain Nobel

Introduction

This is a script which allows one-button jumping! This script is smart in the fact that it'll jump to the farthest jumpable space available from a horizontal, vertical or diagonal aspect. A user-specified SE will be played automatically from jumping to landing, and the system works in conjunction with my "Player : Dash" system to allow an extended jump while running.

Features

  • One-button jumping!
  • Script detects farthest jumpable tile in range and jumps to it
  • Ability to disable jumping over certain tiles via counter tags
  • Ability to jump between impassible objects onto a passible tile
  • SE plays for when any character jumps and lands
  • Works for 4 and 8 directional movement
  • Script won't "accidentally" jump you into your panorama (lol)
  • Plugin for "Player.Dash" allows player to jump farther while running
  • Compatible with my Vehicles XP (not yet released)

Script

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

# ~** Character Move Test **~

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

# Written By  : Kain Nobel

# Version     : 2.0

# Last Update : 09.02.2008

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

# Description

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

#

#   This is a special set of methods, that will tell you which direction a

#   character or event is moving, and supports both 4 and 8 directional movement

#   checking.

#

#   When checking something like $game_map.events[1].moving_down?, you have the

#   optional argument 'diag'. If you set this argument as 'true' and a player is

#   moving_lower_left, then it'll return false, else it'll return true for both.

#

#   Also, for Game_Player, we've got additional methods for checking if player

#   is 'attempting' to move a certain direction. This is for scripts that want

#   to know, "Is he just 'attempting' to move left, or is he 'really' moving

#   left?" So, it doesn't check for Input, rather it'll check for Movement AND

#   Input.

#

# Methods List

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

# Game_Character

#   moving_down?

#   moving_left?

#   moving_right?

#   moving_up?

#   moving_upper_left?

#   moving_upper_right?

#   moving_lower_left?

#   moving_lower_right?

#   move_direction

#   moving_diagonal?

#

# Game_Player (< Game_Character)

#   attempt_down?

#   attempt_left?

#   attempt_right?

#   attempt_up?

#   attempt_upper_left?

#   attempt_upper_right?

#   attempt_lower_left?

#   attempt_lower_right?

#   attempt_moving?

#   attempt_direction?

#   attempt_diagonal?

#

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

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

# * SDK Log

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

if Object.const_defined?(:SDK)

  SDK.log('MACL::RGSS.Character.MoveTest', 'Kain Nobel', 2.0, '09.21.2008')

end

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

# * MACL Loading

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

if Object.const_defined?(:MACL)

  MACL::Loaded << 'RGSS.Character.MoveTest'

end

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

# ** Game_Character

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

#   The parent superclass of Game_Player and Game_Event has been modified to

# return detailed information on which direction a character is moving.

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

class Game_Character

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

  # * Moving Down?

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

  def moving_down?(diag = false)

    return false if !diag && (moving_lower_left? || moving_lower_right?)

    (self.real_y < self.y * 128)

  end

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

  # * Moving Left?

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

  def moving_left?(diag = false)

    return false if !diag && (moving_upper_left? || moving_lower_left?)

    (self.real_x > self.x * 128)

  end

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

  # * Moving Right?

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

  def moving_right?(diag = false)

    return false if !diag && (moving_upper_right? || moving_lower_right?)

    (self.real_x < self.x * 128)

  end

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

  # * Moving Left?

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

  def moving_up?(diag = false)

    return false if !diag && (moving_upper_left? || moving_upper_right?)

    (self.real_y > self.y * 128)

  end

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

  # * Moving Lower Left?

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

  def moving_lower_left?

    (self.real_y < self.y * 128) && (self.real_x > self.x * 128)

  end

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

  # * Moving Lower Right?

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

  def moving_lower_right?

    (self.real_y < self.y * 128) && (self.real_x < self.x * 128)

  end

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

  # * Moving Lower Left?

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

  def moving_upper_left?

    (self.real_y > self.y * 128) && (self.real_x > self.x * 128)

  end

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

  # * Moving Lower Right?

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

  def moving_upper_right?

    (self.real_y > self.y * 128) && (self.real_x < self.x * 128)

  end

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

  # * Move Direction?

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

  def move_direction

    return 2 if moving_down?  && !(moving_lower_left?   || moving_lower_right?)

    return 4 if moving_left?  && !(moving_lower_left?   || moving_upper_left?)

    return 6 if moving_right? && !(moving_lower_right?  || moving_upper_right?)

    return 8 if moving_up?    && !(moving_upper_left?   || moving_upper_right?)

    return 1 if moving_lower_left?

    return 3 if moving_lower_right?

    return 7 if moving_upper_left?

    return 9 if moving_upper_right?

    return 0

  end

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

  # * Moving Diagonal?

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

  def moving_diagonal?

    return true if moving_upper_left? or moving_upper_right?

    return true if moving_lower_left? or moving_lower_right?

    return false

  end

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

  # * Attempt Print Test

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

  def moving_print_test(diag = false)

    print("Down : "+moving_down?(diag).to_s+

    "\nLeft : "+moving_left?(diag).to_s+

    "\nRight : "+moving_right?(diag).to_s+

    "\nUp : "+moving_up?(diag).to_s+

    "\nUpRight : "+moving_upper_right?.to_s+

    "\nUpLeft : "+moving_upper_left?.to_s+

    "\nDownRight : "+moving_lower_right?.to_s+

    "\nDownLeft : "+moving_lower_left?.to_s+

    "\nDirection : "+move_direction.to_s)

  end

end

 

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

# ** Game_Player

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

#   The child class of Game_Character, returns user's directional input to tell

# you if they're 'attemtping' to move a certain direction.

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

class Game_Player < Game_Character

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

  # * Attempt Down?

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

  def attempt_down?(diag = false)

    unless Input.press?(Input::LEFT) || Input.press?(Input::RIGHT)

      return Input.press?(Input::DOWN)

    end ; return false

  end

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

  # * Attempt Left?

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

  def attempt_left?(diag = false)

    unless Input.press?(Input::UP) || Input.press?(Input::DOWN)

      return Input.press?(Input::LEFT)

    end ; return false

  end

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

  # * Attempt Right?

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

  def attempt_right?(diag = false)

    unless Input.press?(Input::UP) || Input.press?(Input::DOWN)

      return Input.press?(Input::RIGHT)

    end ; return false

  end

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

  # * Attempt Up?

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

  def attempt_up?(diag = false)

    unless Input.press?(Input::LEFT) || Input.press?(Input::RIGHT)

      return Input.press?(Input::UP)

    end ; return false

  end

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

  # * Attempt Upper Left?

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

  def attempt_upper_left?

    m = Input.press?(Input::UP) && Input.press?(Input::LEFT)

    if Input.const_defined?(:UPPER_LEFT) && !m

      m = Input.press?(Input::UPPER_LEFT) 

    end

    m

  end

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

  # * Attempt Upper Right?

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

  def attempt_upper_right?

    m = Input.press?(Input::UP) && Input.press?(Input::RIGHT)

    if Input.const_defined?(:UPPER_RIGHT) && !m

      m =Input.press?(Input::UPPER_RIGHT)

    end

    m

  end

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

  # * Attempt Lower Left?

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

  def attempt_lower_left?

    m = Input.press?(Input::DOWN) && Input.press?(Input::LEFT)

    if Input.const_defined?(:LOWER_LEFT) && !m

      m = Input.press?(Input::LOWER_LEFT)

    end

    m

  end

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

  # * Attempt Lower Right?

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

  def attempt_lower_right?

    m = Input.press?(Input::DOWN) && Input.press?(Input::RIGHT)

    if Input.const_defined?(:LOWER_RIGHT) && !m

      m = Input.press?(Input::LOWER_RIGHT)

    end

    m

  end

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

  # * Attempt Moving?

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

  def attempt_moving?(diag = false)

    return true if attempt_down?(diag)

    return true if attempt_left?(diag)

    return true if attempt_right?(diag)

    return true if attempt_up?(diag)

    attempt_diagonal?

  end

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

  # *  Attempt Direction

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

  def attempt_direction?

    if    attempt_down?         ; return 2

    elsif attempt_left?         ; return 4

    elsif attempt_right?        ; return 6

    elsif attempt_up?           ; return 8

    elsif attempt_lower_left?   ; return 1

    elsif attempt_lower_right?  ; return 3

    elsif attempt_upper_left?   ; return 7

    elsif attempt_upper_right?  ; return 9

    else                        ; return 0

    end

  end

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

  # * Attempt Diagonal?

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

  def attempt_diagonal?

    return true if attempt_upper_left?

    return true if attempt_upper_right?

    return true if attempt_lower_left?

    return true if attempt_lower_right?

    return false

  end

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

  # * Attempt Print Test

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

  def attempt_print_test(diag = false)

    print("Down : "+attempt_down?(diag).to_s+

    "\nLeft : "+attempt_left?(diag).to_s+

    "\nRight : "+attempt_right?(diag).to_s+

    "\nUp : "+attempt_up?(diag).to_s+

    "\nUpRight : "+attempt_upper_right?.to_s+

    "\nUpLeft : "+attempt_upper_left?.to_s+

    "\nDownRight : "+attempt_lower_right?.to_s+

    "\nDownLeft : "+attempt_lower_left?.to_s)

  end

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

# ** Player.Jump

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

 

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

# * SDK Log

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

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

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

# * SDK Enabled Test : BEGIN

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

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

 

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

# ** Jump

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

 

module Jump

################################################################################

# ~**                CUSTOMIZABLE CONSTANTS - BEGIN                        **~ #

################################################################################

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

  # * IDs of Maps which you aren't allowed to jump

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

  Xclude_Maps   = []

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

  # * Distance (in tiles) that you regularly jump

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

  Distance      = 2

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

  # * Are you able to jump over objects with Counter tags on them?

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

  Counter_Pass  = false

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

  # * Jump Bonus gained from running (If using Run Script)

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

  Dash_Modifier  = 5

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

  # * Audiofile to be played when you jump

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

  SE_Jump       = RPG::AudioFile.new("015-Jump01", 80, 90)

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

  # * Audofile to be played when you land

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

  SE_Land       = RPG::AudioFile.new("016-Jump02", 80, 90)

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

  # * Input/Key to be used to trigger the player to jump

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

  Button        = Keys::SHIFT

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

  # * Does jumping repeat when you hold the Button?

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

  Repeat        = false

################################################################################

# ~**                 CUSTOMIZABLE CONSTANTS - END                         **~ #

################################################################################

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

  # * Module Function

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

  module_function

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

  # * Jump.se_jump

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

  def se_jump

    $game_system.se_play(SE_Jump)

  end

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

  # * Jump.se_land

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

  def se_land

    $game_system.se_play(SE_Land)

  end

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

  # * Jump.xclude_map?

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

  def xclude_map?

    xclude = Xclude_Maps.is_a?(Array) ? Xclude_Maps : []

    xclude.include?($game_map.map_id)

  end

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

  # * Jump.dash_modifier

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

  def dash_modifier

    (Dash_Modifier.is_a?(Numeric) ? Dash_Modifier : 0)

  end

end

 

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

# ** Game_Map

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

 

class Game_Map

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

  # * Tile Blank?

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

  def no_tile?(x, y)

    [2, 1, 0].each {|i| return true if data[x, y, i].nil?}

    (data[x, y, 2].zero? && data[x, y, 1].zero? && data[x, y, 0].zero?)

  end

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

  # * Disable Dash?

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

  def disable_jump?

    Jump::XcludeMaps.include?(@map_id)

  end

end

 

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

# ** Game_Character

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

 

class Game_Character

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

  # * Alias Listings

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

  alias_method :character_jump,         :jump

  alias_method :character_update_jump,  :update_jump

  alias_method :no_tile_passable?,      :passable?

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

  # * Jump

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

  def jump(x_plus, y_plus)

    Jump.se_jump

    character_jump(x_plus, y_plus)

  end

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

  # * Update Jump

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

  def update_jump

    character_update_jump

    if @jump_count.zero?

      Jump.se_land

    end

  end

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

  # * Passable?

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

  def passable?(x, y, d)

    new_x = x + (d == 6 ? 1 : d == 4 ? -1 : 0)

    new_y = y + (d == 2 ? 1 : d == 8 ? -1 : 0)

    return $game_map.no_tile?(new_x, new_y) ? false : no_tile_passable?(x, y, d)

  end

end

 

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

# ** Game_Player

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

 

class Game_Player < Game_Character

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

  # * Alias Listings

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

  alias_method :jump_player_update,         :update

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

  # * Update

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

  def update

    jump_player_update

    unless disable_jump?

      if update_jump_input?

        update_jump_input

      end

    end

  end

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

  # * Jump Disabled?

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

  def disable_jump?

    (Jump.xclude_map? || jumping? || !jump_valid?)

  end

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

  # * Update Jump Input?

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

  def update_jump_input?

    return false unless $game_player.update_plyrmvttest?

    (Jump::Repeat ? Input.press?(Jump::Button) : Input.trigger?(Jump::Button))

  end

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

  # * Update Jump Input

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

  def update_jump_input

    case @direction

    when 2 # Jump Down  / Down-Left || Down-Right

      if    attempt_lower_left?   ; jump(-(jump_dist-1), (jump_dist-1))

      elsif attempt_lower_right?  ; jump((jump_dist-1), (jump_dist-1))

      else                        ; jump(0, jump_dist)

      end

    when 4 # Jump Left  / Up-Left   / Down-Left

      if    attempt_upper_left?   ; jump(-(jump_dist-1), -(jump_dist-1))

      elsif attempt_lower_left?   ; jump(-(jump_dist-1), (jump_dist-1))

      else                        ; jump(-jump_dist, 0)

      end

    when 6 # Jump Right / Up-Right  / Down-Right

      if    attempt_upper_right?  ; jump((jump_dist-1), -(jump_dist-1))

      elsif attempt_lower_right?  ; jump((jump_dist-1), (jump_dist-1))

      else                        ; jump(jump_dist, 0)

      end

    when 8 # Jump Up    / Up-Left   / Up-Right

      if    attempt_upper_left?   ; jump(-(jump_dist-1), -(jump_dist-1))

      elsif attempt_upper_right?  ; jump((jump_dist-1), -(jump_dist-1))

      else                        ; jump(0, -jump_dist)

      end

    end

  end

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

  # * Jump Valid ?

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

  def jump_valid?

    return $DEBUG if Input.press?(Input::CTRL)

    case move_direction

    when 1

      return false if self.y > $game_map.height - Jump::Distance

      return false if self.x < Jump::Distance

    when 3

      return false if self.y > $game_map.height - Jump::Distance

      return false if self.x > $game_map.width  - Jump::Distance

    when 7

      return false if self.y < Jump::Distance

      return false if self.x > $game_map.width  - Jump::Distance 

    when 9

      return false if self.y < Jump::Distance

      return false if self.x < Jump::Distance

    end

    case @direction

    when 2 ; return false if self.y > $game_map.height - Jump::Distance

    when 4 ; return false if self.x < Jump::Distance

    when 6 ; return false if self.x > $game_map.width  - Jump::Distance

    when 8 ; return false if self.y < Jump::Distance

    end

    unless Jump::Counter_Pass == true

      0.upto(Jump::Distance) do |i|

        case move_direction

        when 1 ; return false if $game_map.counter?(self.x-i, self.y+i)

        when 3 ; return false if $game_map.counter?(self.x+i, self.y+i)

        when 7 ; return false if $game_map.counter?(self.x-i, self.y-i)

        when 9 ; return false if $game_map.counter?(self.x+i, self.y-i)

        end

        case @direction

        when 2 ; return false if $game_map.counter?(self.x, self.y+i)

        when 4 ; return false if $game_map.counter?(self.x-i, self.y)

        when 6 ; return false if $game_map.counter?(self.x+i, self.y)

        when 8 ; return false if $game_map.counter?(self.x, self.y-i)

        end

      end

    end

    return true

  end

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

  # * Jump Dist

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

  def jump_dist

    spaces = Array.new

    for i in 0..Jump::Distance + 1

      if defined?(Game_Player::Dash)

        i += Jump::Dash_Modifier if $game_player.dash.dashing?

      end

      i -= 1 if attempt_diagonal? || moving_diagonal?

      case move_direction

      when 1 ; spaces.push(i) if passable?(self.x-i, self.y+i, 0)

      when 3 ; spaces.push(i) if passable?(self.x+i, self.y+i, 0)

      when 7 ; spaces.push(i) if passable?(self.x-i, self.y-i, 0)

      when 9 ; spaces.push(i) if passable?(self.x+i, self.y-i, 0)

      end

      case @direction

      when 2 ; spaces.push(i) if passable?(self.x,   self.y+i, 0)

      when 4 ; spaces.push(i) if passable?(self.x-i, self.y,   0)

      when 6 ; spaces.push(i) if passable?(self.x+i, self.y,   0)

      when 8 ; spaces.push(i) if passable?(self.x,   self.y-i, 0)

      end

    end

    (spaces.empty? ? 0 : spaces.last)

  end

end

 

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

# * SDK Enabled Test : END

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

end

Instructions

Place below SDK and above Main. This script requires the "RGSS.Character.Move Test" library, future versions might not require this but for now it does.

Compatibility

Should be compatible with most stuff. This script will make tiles which are blank on all 3 layers impassible; this isn't a bug, I did this so you can't jump into your panorama and "walk through the sky".

Author's Notes

Honestly, this script hasn't been updated much in a LONG time, but it is better than the version in my Test Bed (v1.5), but not up to my present-day coding standards. One thing I've yet to put in there is setting certain events to be un-jumpable, I'll do this in my next revision, I promise! This script is subject to a major overhaul in cleaning up code and adding features.

Reason this script requires the MoveTest script is because it checks if player is moving or standing still while jumping and adjusts distance accordingly. It is possible I might remove the requirement in the next version, maybe? We'll see...

Terms and Conditions

Free to use in commercial and non-commercial games, CREDIT IS A MUST OR I HUNT YOU DOWN >.<
 
Fixed bug where you could jump during messages and moveroutes 'n the such... appologies if anybody came across this error, I failed to notice it XD
 

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