Skip to content

Instantly share code, notes, and snippets.

@HimeWorks
Created May 9, 2016 17:11
Show Gist options
  • Save HimeWorks/cfffc25ff03373a4bc707776a91f81cb to your computer and use it in GitHub Desktop.
Save HimeWorks/cfffc25ff03373a4bc707776a91f81cb to your computer and use it in GitHub Desktop.
WASD + 8-dir movement
# 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