Created
May 9, 2016 17:11
-
-
Save HimeWorks/cfffc25ff03373a4bc707776a91f81cb to your computer and use it in GitHub Desktop.
WASD + 8-dir movement
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Title: WASD Movement | |
# Author: Hime | |
# Description: Allows you to use WASD keys for movement, with support for | |
# diagonal movement: http://himeworks.com/2014/11/eight-directional-movement/ | |
#============================================================================== | |
module Input | |
#-------------------------------------------------------------------------- | |
# alias method: self.dir4 | |
#-------------------------------------------------------------------------- | |
class << self | |
alias :th_wasd_movement_dir4 :dir4 | |
end | |
def self.dir4 | |
return 2 if Input.press?(:Y) | |
return 4 if Input.press?(:X) | |
return 6 if Input.press?(:Z) | |
return 8 if Input.press?(:R) | |
th_wasd_movement_dir4 | |
end | |
class << self | |
alias :th_wasd_movement_dir8 :dir8 | |
end | |
def self.dir8 | |
return 1 if Input.press?(:Y) && Input.press?(:X) | |
return 3 if Input.press?(:Y) && Input.press?(:Z) | |
return 7 if Input.press?(:R) && Input.press?(:X) | |
return 9 if Input.press?(:R) && Input.press?(:Z) | |
th_wasd_movement_dir8 | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment