initial commit, kind of working.
This commit is contained in:
@@ -0,0 +1,155 @@
|
||||
package org.flixel.system.input
|
||||
{
|
||||
public class Input
|
||||
{
|
||||
|
||||
internal var _lookup:Object;
|
||||
|
||||
internal var _map:Array;
|
||||
|
||||
internal const _total:uint = 256;
|
||||
|
||||
public function Input()
|
||||
{
|
||||
super();
|
||||
this._lookup = new Object();
|
||||
this._map = new Array(this._total);
|
||||
}
|
||||
|
||||
public function update() : void
|
||||
{
|
||||
var _loc2_:Object = null;
|
||||
var _loc1_:uint = 0;
|
||||
while(_loc1_ < this._total)
|
||||
{
|
||||
_loc2_ = this._map[_loc1_++];
|
||||
if(_loc2_ != null)
|
||||
{
|
||||
if(_loc2_.last == -1 && _loc2_.current == -1)
|
||||
{
|
||||
_loc2_.current = 0;
|
||||
}
|
||||
else if(_loc2_.last == 2 && _loc2_.current == 2)
|
||||
{
|
||||
_loc2_.current = 1;
|
||||
}
|
||||
_loc2_.last = _loc2_.current;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function reset() : void
|
||||
{
|
||||
var _loc2_:Object = null;
|
||||
var _loc1_:uint = 0;
|
||||
while(_loc1_ < this._total)
|
||||
{
|
||||
_loc2_ = this._map[_loc1_++];
|
||||
if(_loc2_ != null)
|
||||
{
|
||||
this[_loc2_.name] = false;
|
||||
_loc2_.current = 0;
|
||||
_loc2_.last = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function pressed(param1:String) : Boolean
|
||||
{
|
||||
return this[param1];
|
||||
}
|
||||
|
||||
public function justPressed(param1:String) : Boolean
|
||||
{
|
||||
return this._map[this._lookup[param1]].current == 2;
|
||||
}
|
||||
|
||||
public function unJustPressed(param1:String) : void
|
||||
{
|
||||
this._map[this._lookup[param1]].current = 1;
|
||||
}
|
||||
|
||||
public function justReleased(param1:String) : Boolean
|
||||
{
|
||||
return this._map[this._lookup[param1]].current == -1;
|
||||
}
|
||||
|
||||
public function record() : Array
|
||||
{
|
||||
var _loc3_:Object = null;
|
||||
var _loc1_:Array = null;
|
||||
var _loc2_:uint = 0;
|
||||
while(_loc2_ < this._total)
|
||||
{
|
||||
_loc3_ = this._map[_loc2_++];
|
||||
if(!(_loc3_ == null || _loc3_.current == 0))
|
||||
{
|
||||
if(_loc1_ == null)
|
||||
{
|
||||
_loc1_ = new Array();
|
||||
}
|
||||
_loc1_.push({
|
||||
"code":_loc2_ - 1,
|
||||
"value":_loc3_.current
|
||||
});
|
||||
}
|
||||
}
|
||||
return _loc1_;
|
||||
}
|
||||
|
||||
public function playback(param1:Array) : void
|
||||
{
|
||||
var _loc4_:Object = null;
|
||||
var _loc5_:Object = null;
|
||||
var _loc2_:uint = 0;
|
||||
var _loc3_:uint = param1.length;
|
||||
while(_loc2_ < _loc3_)
|
||||
{
|
||||
_loc4_ = param1[_loc2_++];
|
||||
_loc5_ = this._map[_loc4_.code];
|
||||
_loc5_.current = _loc4_.value;
|
||||
if(_loc4_.value > 0)
|
||||
{
|
||||
this[_loc5_.name] = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function getKeyCode(param1:String) : int
|
||||
{
|
||||
return this._lookup[param1];
|
||||
}
|
||||
|
||||
public function any() : Boolean
|
||||
{
|
||||
var _loc2_:Object = null;
|
||||
var _loc1_:uint = 0;
|
||||
while(_loc1_ < this._total)
|
||||
{
|
||||
_loc2_ = this._map[_loc1_++];
|
||||
if(_loc2_ != null && _loc2_.current > 0)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
protected function addKey(param1:String, param2:uint) : void
|
||||
{
|
||||
this._lookup[param1] = param2;
|
||||
this._map[param2] = {
|
||||
"name":param1,
|
||||
"current":0,
|
||||
"last":0
|
||||
};
|
||||
}
|
||||
|
||||
public function destroy() : void
|
||||
{
|
||||
this._lookup = null;
|
||||
this._map = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,298 @@
|
||||
package org.flixel.system.input
|
||||
{
|
||||
import flash.events.KeyboardEvent;
|
||||
|
||||
public class Keyboard extends Input
|
||||
{
|
||||
|
||||
public var ESCAPE:Boolean;
|
||||
|
||||
public var F1:Boolean;
|
||||
|
||||
public var F2:Boolean;
|
||||
|
||||
public var F3:Boolean;
|
||||
|
||||
public var F4:Boolean;
|
||||
|
||||
public var F5:Boolean;
|
||||
|
||||
public var F6:Boolean;
|
||||
|
||||
public var F7:Boolean;
|
||||
|
||||
public var F8:Boolean;
|
||||
|
||||
public var F9:Boolean;
|
||||
|
||||
public var F10:Boolean;
|
||||
|
||||
public var F11:Boolean;
|
||||
|
||||
public var F12:Boolean;
|
||||
|
||||
public var ONE:Boolean;
|
||||
|
||||
public var TWO:Boolean;
|
||||
|
||||
public var THREE:Boolean;
|
||||
|
||||
public var FOUR:Boolean;
|
||||
|
||||
public var FIVE:Boolean;
|
||||
|
||||
public var SIX:Boolean;
|
||||
|
||||
public var SEVEN:Boolean;
|
||||
|
||||
public var EIGHT:Boolean;
|
||||
|
||||
public var NINE:Boolean;
|
||||
|
||||
public var ZERO:Boolean;
|
||||
|
||||
public var NUMPADONE:Boolean;
|
||||
|
||||
public var NUMPADTWO:Boolean;
|
||||
|
||||
public var NUMPADTHREE:Boolean;
|
||||
|
||||
public var NUMPADFOUR:Boolean;
|
||||
|
||||
public var NUMPADFIVE:Boolean;
|
||||
|
||||
public var NUMPADSIX:Boolean;
|
||||
|
||||
public var NUMPADSEVEN:Boolean;
|
||||
|
||||
public var NUMPADEIGHT:Boolean;
|
||||
|
||||
public var NUMPADNINE:Boolean;
|
||||
|
||||
public var NUMPADZERO:Boolean;
|
||||
|
||||
public var PAGEUP:Boolean;
|
||||
|
||||
public var PAGEDOWN:Boolean;
|
||||
|
||||
public var HOME:Boolean;
|
||||
|
||||
public var END:Boolean;
|
||||
|
||||
public var INSERT:Boolean;
|
||||
|
||||
public var MINUS:Boolean;
|
||||
|
||||
public var NUMPADMINUS:Boolean;
|
||||
|
||||
public var PLUS:Boolean;
|
||||
|
||||
public var NUMPADPLUS:Boolean;
|
||||
|
||||
public var DELETE:Boolean;
|
||||
|
||||
public var BACKSPACE:Boolean;
|
||||
|
||||
public var TAB:Boolean;
|
||||
|
||||
public var Q:Boolean;
|
||||
|
||||
public var W:Boolean;
|
||||
|
||||
public var E:Boolean;
|
||||
|
||||
public var R:Boolean;
|
||||
|
||||
public var T:Boolean;
|
||||
|
||||
public var Y:Boolean;
|
||||
|
||||
public var U:Boolean;
|
||||
|
||||
public var I:Boolean;
|
||||
|
||||
public var O:Boolean;
|
||||
|
||||
public var P:Boolean;
|
||||
|
||||
public var LBRACKET:Boolean;
|
||||
|
||||
public var RBRACKET:Boolean;
|
||||
|
||||
public var BACKSLASH:Boolean;
|
||||
|
||||
public var CAPSLOCK:Boolean;
|
||||
|
||||
public var A:Boolean;
|
||||
|
||||
public var S:Boolean;
|
||||
|
||||
public var D:Boolean;
|
||||
|
||||
public var F:Boolean;
|
||||
|
||||
public var G:Boolean;
|
||||
|
||||
public var H:Boolean;
|
||||
|
||||
public var J:Boolean;
|
||||
|
||||
public var K:Boolean;
|
||||
|
||||
public var L:Boolean;
|
||||
|
||||
public var SEMICOLON:Boolean;
|
||||
|
||||
public var QUOTE:Boolean;
|
||||
|
||||
public var ENTER:Boolean;
|
||||
|
||||
public var SHIFT:Boolean;
|
||||
|
||||
public var Z:Boolean;
|
||||
|
||||
public var X:Boolean;
|
||||
|
||||
public var C:Boolean;
|
||||
|
||||
public var V:Boolean;
|
||||
|
||||
public var B:Boolean;
|
||||
|
||||
public var N:Boolean;
|
||||
|
||||
public var M:Boolean;
|
||||
|
||||
public var COMMA:Boolean;
|
||||
|
||||
public var PERIOD:Boolean;
|
||||
|
||||
public var NUMPADPERIOD:Boolean;
|
||||
|
||||
public var SLASH:Boolean;
|
||||
|
||||
public var NUMPADSLASH:Boolean;
|
||||
|
||||
public var CONTROL:Boolean;
|
||||
|
||||
public var ALT:Boolean;
|
||||
|
||||
public var SPACE:Boolean;
|
||||
|
||||
public var UP:Boolean;
|
||||
|
||||
public var DOWN:Boolean;
|
||||
|
||||
public var LEFT:Boolean;
|
||||
|
||||
public var RIGHT:Boolean;
|
||||
|
||||
public function Keyboard()
|
||||
{
|
||||
var _loc1_:uint = 0;
|
||||
super();
|
||||
_loc1_ = 65;
|
||||
while(_loc1_ <= 90)
|
||||
{
|
||||
addKey(String.fromCharCode(_loc1_),_loc1_++);
|
||||
}
|
||||
_loc1_ = 48;
|
||||
addKey("ZERO",_loc1_++);
|
||||
addKey("ONE",_loc1_++);
|
||||
addKey("TWO",_loc1_++);
|
||||
addKey("THREE",_loc1_++);
|
||||
addKey("FOUR",_loc1_++);
|
||||
addKey("FIVE",_loc1_++);
|
||||
addKey("SIX",_loc1_++);
|
||||
addKey("SEVEN",_loc1_++);
|
||||
addKey("EIGHT",_loc1_++);
|
||||
addKey("NINE",_loc1_++);
|
||||
_loc1_ = 96;
|
||||
addKey("NUMPADZERO",_loc1_++);
|
||||
addKey("NUMPADONE",_loc1_++);
|
||||
addKey("NUMPADTWO",_loc1_++);
|
||||
addKey("NUMPADTHREE",_loc1_++);
|
||||
addKey("NUMPADFOUR",_loc1_++);
|
||||
addKey("NUMPADFIVE",_loc1_++);
|
||||
addKey("NUMPADSIX",_loc1_++);
|
||||
addKey("NUMPADSEVEN",_loc1_++);
|
||||
addKey("NUMPADEIGHT",_loc1_++);
|
||||
addKey("NUMPADNINE",_loc1_++);
|
||||
addKey("PAGEUP",33);
|
||||
addKey("PAGEDOWN",34);
|
||||
addKey("HOME",36);
|
||||
addKey("END",35);
|
||||
addKey("INSERT",45);
|
||||
_loc1_ = 1;
|
||||
while(_loc1_ <= 12)
|
||||
{
|
||||
addKey("F" + _loc1_,111 + _loc1_++);
|
||||
}
|
||||
addKey("ESCAPE",27);
|
||||
addKey("MINUS",189);
|
||||
addKey("NUMPADMINUS",109);
|
||||
addKey("PLUS",187);
|
||||
addKey("NUMPADPLUS",107);
|
||||
addKey("DELETE",46);
|
||||
addKey("BACKSPACE",8);
|
||||
addKey("LBRACKET",219);
|
||||
addKey("RBRACKET",221);
|
||||
addKey("BACKSLASH",220);
|
||||
addKey("CAPSLOCK",20);
|
||||
addKey("SEMICOLON",186);
|
||||
addKey("QUOTE",222);
|
||||
addKey("ENTER",13);
|
||||
addKey("SHIFT",16);
|
||||
addKey("COMMA",188);
|
||||
addKey("PERIOD",190);
|
||||
addKey("NUMPADPERIOD",110);
|
||||
addKey("SLASH",191);
|
||||
addKey("NUMPADSLASH",191);
|
||||
addKey("CONTROL",17);
|
||||
addKey("ALT",18);
|
||||
addKey("SPACE",32);
|
||||
addKey("UP",38);
|
||||
addKey("DOWN",40);
|
||||
addKey("LEFT",37);
|
||||
addKey("RIGHT",39);
|
||||
addKey("TAB",9);
|
||||
}
|
||||
|
||||
public function handleKeyDown(param1:KeyboardEvent) : void
|
||||
{
|
||||
var _loc2_:Object = _map[param1.keyCode];
|
||||
if(_loc2_ == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if(_loc2_.current > 0)
|
||||
{
|
||||
_loc2_.current = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
_loc2_.current = 2;
|
||||
}
|
||||
this[_loc2_.name] = true;
|
||||
}
|
||||
|
||||
public function handleKeyUp(param1:KeyboardEvent) : void
|
||||
{
|
||||
var _loc2_:Object = _map[param1.keyCode];
|
||||
if(_loc2_ == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if(_loc2_.current > 0)
|
||||
{
|
||||
_loc2_.current = -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
_loc2_.current = 0;
|
||||
}
|
||||
this[_loc2_.name] = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,243 @@
|
||||
package org.flixel.system.input
|
||||
{
|
||||
import flash.display.Bitmap;
|
||||
import flash.display.Sprite;
|
||||
import flash.events.MouseEvent;
|
||||
import org.flixel.FlxCamera;
|
||||
import org.flixel.FlxG;
|
||||
import org.flixel.FlxPoint;
|
||||
import org.flixel.system.replay.MouseRecord;
|
||||
|
||||
public class Mouse extends FlxPoint
|
||||
{
|
||||
|
||||
protected var ImgDefaultCursor:Class = Mouse_ImgDefaultCursor;
|
||||
|
||||
public var wheel:int;
|
||||
|
||||
public var screenX:int;
|
||||
|
||||
public var screenY:int;
|
||||
|
||||
protected var _current:int;
|
||||
|
||||
protected var _last:int;
|
||||
|
||||
protected var _cursorContainer:Sprite;
|
||||
|
||||
protected var _cursor:Bitmap;
|
||||
|
||||
protected var _lastX:int;
|
||||
|
||||
protected var _lastY:int;
|
||||
|
||||
protected var _lastWheel:int;
|
||||
|
||||
protected var _point:FlxPoint;
|
||||
|
||||
protected var _screenPosition:FlxPoint;
|
||||
|
||||
public function Mouse(param1:Sprite)
|
||||
{
|
||||
super();
|
||||
this._cursorContainer = param1;
|
||||
this._lastX = this.screenX = 0;
|
||||
this._lastY = this.screenY = 0;
|
||||
this._lastWheel = this.wheel = 0;
|
||||
this._current = 0;
|
||||
this._last = 0;
|
||||
this._cursor = null;
|
||||
this._point = new FlxPoint();
|
||||
this._screenPosition = new FlxPoint();
|
||||
}
|
||||
|
||||
public function destroy() : void
|
||||
{
|
||||
this._cursorContainer = null;
|
||||
this._cursor = null;
|
||||
this._point = null;
|
||||
this._screenPosition = null;
|
||||
}
|
||||
|
||||
public function show(param1:Class = null, param2:Number = 1, param3:int = 0, param4:int = 0) : void
|
||||
{
|
||||
this._cursorContainer.visible = true;
|
||||
if(param1 != null)
|
||||
{
|
||||
this.load(param1,param2,param3,param4);
|
||||
}
|
||||
else if(this._cursor == null)
|
||||
{
|
||||
this.load();
|
||||
}
|
||||
}
|
||||
|
||||
public function hide() : void
|
||||
{
|
||||
this._cursorContainer.visible = false;
|
||||
}
|
||||
|
||||
public function get visible() : Boolean
|
||||
{
|
||||
return this._cursorContainer.visible;
|
||||
}
|
||||
|
||||
public function load(param1:Class = null, param2:Number = 1, param3:int = 0, param4:int = 0) : void
|
||||
{
|
||||
if(this._cursor != null)
|
||||
{
|
||||
this._cursorContainer.removeChild(this._cursor);
|
||||
}
|
||||
if(param1 == null)
|
||||
{
|
||||
param1 = this.ImgDefaultCursor;
|
||||
}
|
||||
this._cursor = new param1();
|
||||
this._cursor.x = param3;
|
||||
this._cursor.y = param4;
|
||||
this._cursor.scaleX = param2;
|
||||
this._cursor.scaleY = param2;
|
||||
this._cursorContainer.addChild(this._cursor);
|
||||
}
|
||||
|
||||
public function unload() : void
|
||||
{
|
||||
if(this._cursor != null)
|
||||
{
|
||||
if(this._cursorContainer.visible)
|
||||
{
|
||||
this.load();
|
||||
}
|
||||
else
|
||||
{
|
||||
this._cursorContainer.removeChild(this._cursor);
|
||||
this._cursor = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function update(param1:int, param2:int) : void
|
||||
{
|
||||
this._screenPosition.make(param1,param2);
|
||||
this.getScreenPosition(null,this._point);
|
||||
this.screenX = this._point.x;
|
||||
this.screenY = this._point.y;
|
||||
this.updateCursor();
|
||||
if(this._last == -1 && this._current == -1)
|
||||
{
|
||||
this._current = 0;
|
||||
}
|
||||
else if(this._last == 2 && this._current == 2)
|
||||
{
|
||||
this._current = 1;
|
||||
}
|
||||
this._last = this._current;
|
||||
}
|
||||
|
||||
protected function updateCursor() : void
|
||||
{
|
||||
this.getWorldPosition(null,this);
|
||||
this._cursorContainer.x = this._screenPosition.x;
|
||||
this._cursorContainer.y = this._screenPosition.y;
|
||||
}
|
||||
|
||||
public function getWorldPosition(param1:FlxCamera = null, param2:FlxPoint = null) : FlxPoint
|
||||
{
|
||||
if(param1 == null)
|
||||
{
|
||||
param1 = FlxG.camera;
|
||||
}
|
||||
if(param2 == null)
|
||||
{
|
||||
param2 = new FlxPoint();
|
||||
}
|
||||
this.getScreenPosition(param1,this._point);
|
||||
return param2.make(this._point.x + param1.scroll.x,this._point.y + param1.scroll.y);
|
||||
}
|
||||
|
||||
public function getScreenPosition(param1:FlxCamera = null, param2:FlxPoint = null) : FlxPoint
|
||||
{
|
||||
if(param1 == null)
|
||||
{
|
||||
param1 = FlxG.camera;
|
||||
}
|
||||
if(param2 == null)
|
||||
{
|
||||
param2 = new FlxPoint();
|
||||
}
|
||||
return param2.make(this._screenPosition.x / param1.zoom,this._screenPosition.y / param1.zoom);
|
||||
}
|
||||
|
||||
public function reset() : void
|
||||
{
|
||||
this._current = 0;
|
||||
this._last = 0;
|
||||
}
|
||||
|
||||
public function pressed() : Boolean
|
||||
{
|
||||
return this._current > 0;
|
||||
}
|
||||
|
||||
public function justPressed() : Boolean
|
||||
{
|
||||
return this._current == 2;
|
||||
}
|
||||
|
||||
public function justReleased() : Boolean
|
||||
{
|
||||
return this._current == -1;
|
||||
}
|
||||
|
||||
public function handleMouseDown(param1:MouseEvent) : void
|
||||
{
|
||||
if(this._current > 0)
|
||||
{
|
||||
this._current = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
this._current = 2;
|
||||
}
|
||||
}
|
||||
|
||||
public function handleMouseUp(param1:MouseEvent) : void
|
||||
{
|
||||
if(this._current > 0)
|
||||
{
|
||||
this._current = -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
this._current = 0;
|
||||
}
|
||||
}
|
||||
|
||||
public function handleMouseWheel(param1:MouseEvent) : void
|
||||
{
|
||||
this.wheel = param1.delta;
|
||||
}
|
||||
|
||||
public function record() : MouseRecord
|
||||
{
|
||||
if(this._lastX == this.screenX && this._lastY == this.screenY && this._current == 0 && this._lastWheel == this.wheel)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
this._lastX = this.screenX;
|
||||
this._lastY = this.screenY;
|
||||
this._lastWheel = this.wheel;
|
||||
return new MouseRecord(this.screenX,this.screenY,this._current,this.wheel);
|
||||
}
|
||||
|
||||
public function playback(param1:MouseRecord) : void
|
||||
{
|
||||
this.screenX = param1.x;
|
||||
this.screenY = param1.y;
|
||||
this._current = param1.button;
|
||||
this.wheel = param1.wheel;
|
||||
this.updateCursor();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
package org.flixel.system.input
|
||||
{
|
||||
import mx.core.BitmapAsset;
|
||||
|
||||
[Embed(source="/_assets/181_org.flixel.system.input.Mouse_ImgDefaultCursor.png")]
|
||||
public class Mouse_ImgDefaultCursor extends BitmapAsset
|
||||
{
|
||||
|
||||
public function Mouse_ImgDefaultCursor()
|
||||
{
|
||||
super();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user