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.

[Resolved] Change Controls to WASD

Status
Not open for further replies.
Ok..

I´ve made a shooter Engine. But i realised, when i move with the Arrow-Keys and Fire with the Mouse... It´s not possibble to hit the WASD, SHIF, Space keys quick..

Now i wanted to move the Player via W,A,S,D.

So the Arrow-Keys make the work of the WASD.

is there a way to do that????
 
This should be in the RGSS support forum

I think your Input lines should be different like this:
Code:
if Input.trigger?(Input::right)
Or whatever... to:

Code:
if Input.trigger?(Input::W)

Or whatever. That's how I think it would work.
 
No it won't work like that. RMXP has it's own set of buttons and "W" isn't one of the inputs.

You'll have to use a keyboard module, and then find out the input for it and call script it from there in a conditional branch, but most of the keyboard modules have constants(I think that's what they are, might be strings) that are too long, you'll have to use find/replace in the script editor and make them something shorter.

Sorry if you don't understand that's as easy as I can put it.
~Kolo The Panda
 
I tryed to replaye the following codes:
case Input.dir4
when 2
move_down
when 4
move_left
when 6
move_right
when 8
move_up
end
end

by using Cybersams Keyboard Skript... So i asked if "R" is pressed ( R = W )... but the player didn´t moved...
 
This is for Cybersam's Keyboard Module...

Code:
if Input.triggered?(87)
  move_up
elsif Input.triggered?(83)
  move_down
elsif Input.triggered?(65)
  move_left
elsif Input.triggered?(68)
  move_right
end
 
Yes...öhm... But my Cybersam Keyboard Script has other Key-Askings...

Here´s my version:

#======================================
# â–  Keyboard Script
#---------------------------------------------------------------------------
#  By: Cybersam
# Date: 25/05/05
# Version 4
#======================================

module Kboard
#--------------------------------------------------------------------------
$RMouse_BUTTON_L = 0x01 # left mouse button
$RMouse_BUTTON_R = 0x02 # right mouse button
$RMouse_BUTTON_M = 0x04 # middle mouse button
$RMouse_BUTTON_4 = 0x05 # 4th mouse button
$RMouse_BUTTON_5 = 0x06 # 5th mouse button
#--------------------------------------------------------------------------
$R_Key_BACK = 0x08 # BACKSPACE key
$R_Key_TAB = 0x09 # TAB key
$R_Key_RETURN = 0x0D # ENTER key
$R_Key_SHIFT = 0x10 # SHIFT key
$R_Key_CTLR = 0x11 # CTLR key
$R_Key_ALT = 0x12 # ALT key
$R_Key_PAUSE = 0x13 # PAUSE key
$R_Key_CAPITAL = 0x14 # CAPS LOCK key
$R_Key_ESCAPE = 0x1B # ESC key
$R_Key_SPACE = 0x20 # SPACEBAR
$R_Key_PRIOR = 0x21 # PAGE UP key
$R_Key_NEXT = 0x22 # PAGE DOWN key
$R_Key_END = 0x23 # END key
$R_Key_HOME = 0x24 # HOME key
$R_Key_LEFT = 0x25 # LEFT ARROW key
$R_Key_UP = 0x26 # UP ARROW key
$R_Key_RIGHT = 0x27 # RIGHT ARROW key
$R_Key_DOWN = 0x28 # DOWN ARROW key
$R_Key_SELECT = 0x29 # SELECT key
$R_Key_PRINT = 0x2A # PRINT key
$R_Key_SNAPSHOT = 0x2C # PRINT SCREEN key
$R_Key_INSERT = 0x2D # INS key
$R_Key_DELETE = 0x2E # DEL key
#--------------------------------------------------------------------------
$R_Key_0 = 0x30 # 0 key
$R_Key_1 = 0x31 # 1 key
$R_Key_2 = 0x32 # 2 key
$R_Key_3 = 0x33 # 3 key
$R_Key_4 = 0x34 # 4 key
$R_Key_5 = 0x35 # 5 key
$R_Key_6 = 0x36 # 6 key
$R_Key_7 = 0x37 # 7 key
$R_Key_8 = 0x38 # 8 key
$R_Key_9 = 0x39 # 9 key
#--------------------------------------------------------------------------
$R_Key_A = 0x41 # A key
$R_Key_B = 0x42 # B key
$R_Key_C = 0x43 # C key
$R_Key_D = 0x44 # D key
$R_Key_E = 0x45 # E key
$R_Key_F = 0x46 # F key
$R_Key_G = 0x47 # G key
$R_Key_H = 0x48 # H key
$R_Key_I = 0x49 # I key
$R_Key_J = 0x4A # J key
$R_Key_K = 0x4B # K key
$R_Key_L = 0x4C # L key
$R_Key_M = 0x4D # M key
$R_Key_N = 0x4E # N key
$R_Key_O = 0x4F # O key
$R_Key_P = 0x50 # P key
$R_Key_Q = 0x51 # Q key
$R_Key_R = 0x52 # R key
$R_Key_S = 0x53 # S key
$R_Key_T = 0x54 # T key
$R_Key_U = 0x55 # U key
$R_Key_V = 0x56 # V key
$R_Key_W = 0x57 # W key
$R_Key_X = 0x58 # X key
$R_Key_Y = 0x59 # Y key
$R_Key_Z = 0x5A # Z key
#--------------------------------------------------------------------------
$R_Key_LWIN = 0x5B # Left Windows key (Microsoft Natural keyboard)
$R_Key_RWIN = 0x5C # Right Windows key (Natural keyboard)
$R_Key_APPS = 0x5D # Applications key (Natural keyboard)
#--------------------------------------------------------------------------
$R_Key_NUMPAD0 = 0x60 # Numeric keypad 0 key
$R_Key_NUMPAD1 = 0x61 # Numeric keypad 1 key
$R_Key_NUMPAD2 = 0x62 # Numeric keypad 2 key
$R_Key_NUMPAD3 = 0x63 # Numeric keypad 3 key
$R_Key_NUMPAD4 = 0x64 # Numeric keypad 4 key
$R_Key_NUMPAD5 = 0x65 # Numeric keypad 5 key
$R_Key_NUMPAD6 = 0x66 # Numeric keypad 6 key
$R_Key_NUMPAD7 = 0x67 # Numeric keypad 7 key
$R_Key_NUMPAD8 = 0x68 # Numeric keypad 8 key
$R_Key_NUMPAD9 = 0x69 # Numeric keypad 9 key
$R_Key_MULTIPLY = 0x6A # Multiply key (*)
$R_Key_ADD = 0x6B # Add key (+)
$R_Key_SEPARATOR = 0x6C # Separator key
$R_Key_SUBTRACT = 0x6D # Subtract key (-)
$R_Key_DECIMAL = 0x6E # Decimal key
$R_Key_DIVIDE = 0x6F # Divide key (/)
#--------------------------------------------------------------------------
$R_Key_F1 = 0x70 # F1 key
$R_Key_F2 = 0x71 # F2 key
$R_Key_F3 = 0x72 # F3 key
$R_Key_F4 = 0x73 # F4 key
$R_Key_F5 = 0x74 # F5 key
$R_Key_F6 = 0x75 # F6 key
$R_Key_F7 = 0x76 # F7 key
$R_Key_F8 = 0x77 # F8 key
$R_Key_F9 = 0x78 # F9 key
$R_Key_F10 = 0x79 # F10 key
$R_Key_F11 = 0x7A # F11 key
$R_Key_F12 = 0x7B # F12 key
#--------------------------------------------------------------------------
$R_Key_NUMLOCK = 0x90 # NUM LOCK key
$R_Key_SCROLL = 0x91 # SCROLL LOCK key
#--------------------------------------------------------------------------
$R_Key_LSHIFT = 0xA0 # Left SHIFT key
$R_Key_RSHIFT = 0xA1 # Right SHIFT key
$R_Key_LCONTROL = 0xA2 # Left CONTROL key
$R_Key_RCONTROL = 0xA3 # Right CONTROL key
$R_Key_L_ALT = 0xA4 # Left ALT key
$R_Key_R_ALT = 0xA5 # Right ALT key
#--------------------------------------------------------------------------
$R_Key_SEP = 0xBC # , key
$R_Key_DASH = 0xBD # - key
$R_Key_DOTT = 0xBE # . key
#--------------------------------------------------------------------------
GetKeyState = Win32API.new("user32","GetAsyncKeyState",['i'],'i')
GetKeyboardState = Win32API.new("user32","GetKeyState",['i'],'i')
GetSetKeyState = Win32API.new("user32","SetKeyboardState",['i'],'i')
#--------------------------------------------------------------------------
module_function
#--------------------------------------------------------------------------
def keyb(rkey)
if GetKeyState.call(rkey) != 0
return 1
end
return 0
end
#--------------------------------------------------------------------------
def keyboard(rkey)
GetKeyState.call(rkey) & 0x01 == 1 #
end
#--------------------------------------------------------------------------
def key(rkey, key = 0)
GetKeyboardState.call(rkey) & 0x01 == key #
end
end
 
Won´t work allready...

Here´s my game_Player
#==============================================================================
# ** Game_Player
#------------------------------------------------------------------------------
# This class handles the player. Its functions include event starting
# determinants and map scrolling. Refer to "$game_player" for the one
# instance of this class.
#==============================================================================

class Game_Player < Game_Character
#--------------------------------------------------------------------------
# * Invariables
#--------------------------------------------------------------------------
CENTER_X = (320 - 16) * 4 # Center screen x-coordinate * 4
CENTER_Y = (240 - 16) * 4 # Center screen y-coordinate * 4
#--------------------------------------------------------------------------
# * Passable Determinants
# x : x-coordinate
# y : y-coordinate
# d : direction (0,2,4,6,8)
# * 0 = Determines if all directions are impassable (for jumping)
#--------------------------------------------------------------------------
def passable?(x, y, d)
# Get new coordinates
new_x = x + (d == 6 ? 1 : d == 4 ? -1 : 0)
new_y = y + (d == 2 ? 1 : d == 8 ? -1 : 0)
# If coordinates are outside of map
unless $game_map.valid?(new_x, new_y)
# Impassable
return false
end
# If debug mode is ON and ctrl key was pressed
if $DEBUG and Input.press?(Input::CTRL)
# Passable
return true
end
super
end
#--------------------------------------------------------------------------
# * Set Map Display Position to Center of Screen
#--------------------------------------------------------------------------
def center(x, y)
max_x = ($game_map.width - 20) * 128
max_y = ($game_map.height - 15) * 128
$game_map.display_x = [0, [x * 128 - CENTER_X, max_x].min].max
$game_map.display_y = [0, [y * 128 - CENTER_Y, max_y].min].max
end
#--------------------------------------------------------------------------
# * Move to Designated Position
# x : x-coordinate
# y : y-coordinate
#--------------------------------------------------------------------------
def moveto(x, y)
super
# Centering
center(x, y)
# Make encounter count
make_encounter_count
end
#--------------------------------------------------------------------------
# * Increaase Steps
#--------------------------------------------------------------------------
def increase_steps
super
# If move route is not forcing
unless @move_route_forcing
# Increase steps
$game_party.increase_steps
# Number of steps are an even number
if $game_party.steps % 2 == 0
# Slip damage check
$game_party.check_map_slip_damage
end
end
end
#--------------------------------------------------------------------------
# * Get Encounter Count
#--------------------------------------------------------------------------
def encounter_count
return @encounter_count
end
#--------------------------------------------------------------------------
# * Make Encounter Count
#--------------------------------------------------------------------------
def make_encounter_count
# Image of two dice rolling
if $game_map.map_id != 0
n = $game_map.encounter_step
@encounter_count = rand(n) + rand(n) + 1
end
end
#--------------------------------------------------------------------------
# * Refresh
#--------------------------------------------------------------------------
def refresh
# If party members = 0
if $game_party.actors.size == 0
# Clear character file name and hue
@character_name = ""
@character_hue = 0
# End method
return
end
# Get lead actor
actor = $game_party.actors[0]
# Set character file name and hue
@character_name = actor.character_name
@character_hue = actor.character_hue
# Initialize opacity level and blending method
@opacity = 255
@blend_type = 0
end
#--------------------------------------------------------------------------
# * Same Position Starting Determinant
#--------------------------------------------------------------------------
def check_event_trigger_here(triggers)
result = false
# If event is running
if $game_system.map_interpreter.running?
return result
end
# All event loops
for event in $game_map.events.values
# If event coordinates and triggers are consistent
if event.x == @x and event.y == @y and triggers.include?(event.trigger)
# If starting determinant is same position event (other than jumping)
if not event.jumping? and event.over_trigger?
event.start
result = true
end
end
end
return result
end
#--------------------------------------------------------------------------
# * Front Envent Starting Determinant
#--------------------------------------------------------------------------
def check_event_trigger_there(triggers)
result = false
# If event is running
if $game_system.map_interpreter.running?
return result
end
# Calculate front event coordinates
new_x = @x + (@direction == 6 ? 1 : @direction == 4 ? -1 : 0)
new_y = @y + (@direction == 2 ? 1 : @direction == 8 ? -1 : 0)
# All event loops
for event in $game_map.events.values
# If event coordinates and triggers are consistent
if event.x == new_x and event.y == new_y and
triggers.include?(event.trigger)
# If starting determinant is front event (other than jumping)
if not event.jumping? and not event.over_trigger?
event.start
result = true
end
end
end
# If fitting event is not found
if result == false
# If front tile is a counter
if $game_map.counter?(new_x, new_y)
# Calculate 1 tile inside coordinates
new_x += (@direction == 6 ? 1 : @direction == 4 ? -1 : 0)
new_y += (@direction == 2 ? 1 : @direction == 8 ? -1 : 0)
# All event loops
for event in $game_map.events.values
# If event coordinates and triggers are consistent
if event.x == new_x and event.y == new_y and
triggers.include?(event.trigger)
# If starting determinant is front event (other than jumping)
if not event.jumping? and not event.over_trigger?
event.start
result = true
end
end
end
end
end
return result
end
#--------------------------------------------------------------------------
# * Touch Event Starting Determinant
#--------------------------------------------------------------------------
def check_event_trigger_touch(x, y)
result = false
# If event is running
if $game_system.map_interpreter.running?
return result
end
# All event loops
for event in $game_map.events.values
# If event coordinates and triggers are consistent
if event.x == x and event.y == y and [1,2].include?(event.trigger)
# If starting determinant is front event (other than jumping)
if not event.jumping? and not event.over_trigger?
event.start
result = true
end
end
end
return result
end
#--------------------------------------------------------------------------
# * Frame Update
#--------------------------------------------------------------------------
def update
# Remember whether or not moving in local variables
last_moving = moving?
# If moving, event running, move route forcing, and message window
# display are all not occurring
unless moving? or $game_system.map_interpreter.running? or
@move_route_forcing or $game_temp.message_window_showing
# Move player in the direction the directional button is being pressed
case Input.dir4
if Input.triggered?(87)
move_up
elsif Input.triggered?(83)
move_down
elsif Input.triggered?(65)
move_left
elsif Input.triggered?(68)
move_right
end
end
# Remember coordinates in local variables
last_real_x = @real_x
last_real_y = @real_y
super
# If character moves down and is positioned lower than the center
# of the screen
if @real_y > last_real_y and @real_y - $game_map.display_y > CENTER_Y
# Scroll map down
$game_map.scroll_down(@real_y - last_real_y)
end
# If character moves left and is positioned more let on-screen than
# center
if @real_x < last_real_x and @real_x - $game_map.display_x < CENTER_X
# Scroll map left
$game_map.scroll_left(last_real_x - @real_x)
end
# If character moves right and is positioned more right on-screen than
# center
if @real_x > last_real_x and @real_x - $game_map.display_x > CENTER_X
# Scroll map right
$game_map.scroll_right(@real_x - last_real_x)
end
# If character moves up and is positioned higher than the center
# of the screen
if @real_y < last_real_y and @real_y - $game_map.display_y < CENTER_Y
# Scroll map up
$game_map.scroll_up(last_real_y - @real_y)
end
# If not moving
unless moving?
# If player was moving last time
if last_moving
# Event determinant is via touch of same position event
result = check_event_trigger_here([1,2])
# If event which started does not exist
if result == false
# Disregard if debug mode is ON and ctrl key was pressed
unless $DEBUG and Input.press?(Input::CTRL)
# Encounter countdown
if @encounter_count > 0
@encounter_count -= 1
end
end
end
end
# If C button was pressed
if Input.trigger?(Input::C)
# Same position and front event determinant
check_event_trigger_here([0])
check_event_trigger_there([0,1,2])
end
end
end
end
 
Code:
if Input.triggered?(Input::R)
  move_up
elsif Input.triggered?(Input::Y)
  move_down
elsif Input.triggered?(Input::X)
  move_left
elsif Input.triggered?(Input::Z)
  move_right
end

Enterbrain made the keys like that for a few reasons. One is probably for Joystick support (minimizing the amount of buttons required makes it easier for cross compatibility between keyboard and joystick) and because it emulates the basic Microsoft Sidewinder game-pad.

Q/W [R/L] = 2 Shoulder Buttons
ASDZXC [XYZABC] = Six Command Buttons
Directions [LEFT, RIGHT, UP, DOWN] = Directional Pad
 
You know, since the default movement uses the Input.dir4 method and returns values, you could just alias the Input.dir4 method and leave it as is.

Code:
module Input
  class << self
    if @seph_dir4_stack.nil?
      alias seph_dir4_input_dir4 dir4
      @seph_dir4_stack = true
    end
    def dir4
      if trigger?(BUTTON_CONSTANT_FOR_DOWN)
        return 2
      elsif trigger?(BUTTON_CONSTANT_FOR_LEFT)
        return 4
      elsif trigger?(BUTTON_CONSTANT_FOR_RIGHT)
        return 6
      elsif trigger?(BUTTON_CONSTANT_FOR_UP)
        return 8
      end
      return seph_dir4_input_dir4
    end
  end
end

Just replace the CAPS with either button numbers (See Cybersam's script) or whatever.
 
There´s still a Problem... if i press "W or A or S or D", the Player moved only one field in the direction....

And, The Arrow Keys... I want to use them for different actions... NOT FOR MOVING. ( But that´s not a real problem... forget it completely fast again ) ^^

Example:
Before:
Arrows = movement
WASD = Actions


After
Arrows = Actions ( in the actions, the player can´t move..so it isn´t realy a Problem )
WASD = Movement


But it works...just one field..but ':|
 
Status
Not open for further replies.

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