Skip to content

Instantly share code, notes, and snippets.

@ibilon
Last active December 22, 2015 05:49
Show Gist options
  • Save ibilon/6426881 to your computer and use it in GitHub Desktop.
Save ibilon/6426881 to your computer and use it in GitHub Desktop.
Haxepunk fusion of input and joystick check/pressed.
import com.haxepunk.utils.Input;
import com.haxepunk.utils.Joystick;
class Inputs
{
static function define_input (name:String, keys:Array<Int>)
{
Input.define(name, keys);
}
static function define_joystick (name:String, keys:Array<Int>)
{
_joystick.set(name, keys);
}
static function check (name:String, idJoystick:Int=0) : Bool
{
var input = Input.check(name);
var joystick:Bool = false;
if (_joystick.exists(name))
{
for (i in _joystick.get(name))
joystick = joystick || Input.joystick(idJoystick).check(i);
}
return input || joystick;
}
static function pressed (name:String, idJoystick:Int=0) : Bool
{
var input = Input.pressed(name);
var joystick:Bool = false;
if (_joystick.exists(name))
{
for (i in _joystick.get(name))
joystick = joystick || Input.joystick(idJoystick).pressed(i);
}
return input || joystick;
}
static function released (name:String) : Bool
{
return Input.released(name);
}
private static var _joystick:Map<String,Array<Int>> = new Map<String,Array<Int>>();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment