mirror of
https://github.com/logsol/chuck.js.git
synced 2026-05-11 10:37:34 +00:00
restructured repository
This commit is contained in:
parent
cc6279eac9
commit
080a2e410c
38 changed files with 87 additions and 26 deletions
|
|
@ -1,68 +0,0 @@
|
|||
Chuck.Control.InputControlUnit = function(ki, me) {
|
||||
this._ki = ki;
|
||||
this._me = me;
|
||||
|
||||
this._shift;
|
||||
this._isJumping;
|
||||
|
||||
this.KEY_LEFT = 65;
|
||||
this.KEY_RIGHT = 68;
|
||||
this.KEY_UP = 87;
|
||||
this.KEY_DOWN = 83;
|
||||
|
||||
this.init();
|
||||
}
|
||||
|
||||
Chuck.Control.InputControlUnit.prototype.init = function() {
|
||||
|
||||
this._ki.setInputControlUnit(this);
|
||||
|
||||
this._ki.registerKey(this.KEY_LEFT, 'moveLeft', 'stop', 'moveLeft');
|
||||
this._ki.registerKey(this.KEY_RIGHT, 'moveRight', 'stop', 'moveRight');
|
||||
this._ki.registerKey(this.KEY_UP, 'jump', 'jumped', 'jumping');
|
||||
this._ki.registerKey(this.KEY_DOWN, 'duck', 'standUp', 'duck');
|
||||
this._ki.registerKey(this.KEY_DOWN, 'activateShift', 'activateShift', 'deactivateShift');
|
||||
}
|
||||
|
||||
Chuck.Control.InputControlUnit.prototype.moveLeft = function() {
|
||||
this._me.move(-1);
|
||||
}
|
||||
|
||||
Chuck.Control.InputControlUnit.prototype.moveRight = function() {
|
||||
this._me.move(1);
|
||||
}
|
||||
|
||||
Chuck.Control.InputControlUnit.prototype.stop = function() {
|
||||
this._me.stop();
|
||||
}
|
||||
|
||||
Chuck.Control.InputControlUnit.prototype.jump = function() {
|
||||
this._isJumping = true;
|
||||
this._me.jump();
|
||||
}
|
||||
|
||||
Chuck.Control.InputControlUnit.prototype.jumped = function() {
|
||||
this._isJumping = false;
|
||||
}
|
||||
|
||||
Chuck.Control.InputControlUnit.prototype.jumping = function() {
|
||||
if (this._isJumping) {
|
||||
this._me.jumping();
|
||||
}
|
||||
}
|
||||
|
||||
Chuck.Control.InputControlUnit.prototype.duck = function() {
|
||||
this._me.duck();
|
||||
}
|
||||
|
||||
Chuck.Control.InputControlUnit.prototype.standUp = function() {
|
||||
this._me.standUp();
|
||||
}
|
||||
|
||||
Chuck.Control.InputControlUnit.prototype.activateShift = function() {
|
||||
this._shift = true;
|
||||
}
|
||||
|
||||
Chuck.Control.InputControlUnit.prototype.deactivateShift = function() {
|
||||
this._shift = false;
|
||||
}
|
||||
|
|
@ -1,56 +0,0 @@
|
|||
Chuck.Control.Key = function() {
|
||||
this._active = false;
|
||||
this._activityUpdateStatus = false;
|
||||
this._activityUpdateNeeded = false;
|
||||
this._keyDown = null;
|
||||
this._keyUp = null;
|
||||
this._keyFrame = null;
|
||||
|
||||
}
|
||||
Chuck.Control.Key.prototype.setActivityUpdateStatus = function(active) {
|
||||
this._activityUpdateStatus = active;
|
||||
}
|
||||
|
||||
Chuck.Control.Key.prototype.getActivityUpdateStatus = function() {
|
||||
return this._activityUpdateStatus;
|
||||
}
|
||||
|
||||
Chuck.Control.Key.prototype.setActivityUpdateNeeded = function(need) {
|
||||
this._activityUpdateNeeded = need;
|
||||
}
|
||||
|
||||
Chuck.Control.Key.prototype.getActivityUpdateNeeded = function() {
|
||||
return this._activityUpdateNeeded;
|
||||
}
|
||||
|
||||
Chuck.Control.Key.prototype.setActive = function(active) {
|
||||
this._active = active;
|
||||
}
|
||||
|
||||
Chuck.Control.Key.prototype.getActive = function() {
|
||||
return this._active;
|
||||
}
|
||||
|
||||
Chuck.Control.Key.prototype.setKeyDownFunction = function(f) {
|
||||
this._keyDown = f;
|
||||
}
|
||||
|
||||
Chuck.Control.Key.prototype.getKeyDownFunction = function() {
|
||||
return this._keyDown;
|
||||
}
|
||||
|
||||
Chuck.Control.Key.prototype.setKeyUpFunction = function(f) {
|
||||
this._keyUp = f;
|
||||
}
|
||||
|
||||
Chuck.Control.Key.prototype.getKeyUpFunction = function() {
|
||||
return this._keyUp;
|
||||
}
|
||||
|
||||
Chuck.Control.Key.prototype.setKeyFrameFunction = function(f) {
|
||||
this._keyFrame = f;
|
||||
}
|
||||
|
||||
Chuck.Control.Key.prototype.getKeyFrameFunction = function() {
|
||||
return this._keyFrame;
|
||||
}
|
||||
|
|
@ -1,72 +0,0 @@
|
|||
Chuck.Control.KeyboardInput = function() {
|
||||
this._registry = {};
|
||||
this._inputControlUnit = null;
|
||||
|
||||
this.init();
|
||||
}
|
||||
|
||||
Chuck.Control.KeyboardInput.prototype.init = function() {
|
||||
$(window).keydown($.proxy(this._onKeyDown, this));
|
||||
$(window).keyup($.proxy(this._onKeyUp, this));
|
||||
}
|
||||
|
||||
Chuck.Control.KeyboardInput.prototype.setInputControlUnit = function(inputControlUnit) {
|
||||
this._inputControlUnit = inputControlUnit;
|
||||
}
|
||||
|
||||
Chuck.Control.KeyboardInput.prototype.registerKey = function(keyCode, onKeyDown, onKeyUp, onKeyFrame) {
|
||||
var key = new Chuck.Control.Key();
|
||||
key.setKeyDownFunction(onKeyDown);
|
||||
key.setKeyUpFunction(onKeyUp);
|
||||
key.setKeyFrameFunction(onKeyFrame);
|
||||
this._registry[keyCode] = key;
|
||||
}
|
||||
|
||||
Chuck.Control.KeyboardInput.prototype._getKeyByKeyCode = function(keyCode) {
|
||||
return this._registry[keyCode];
|
||||
}
|
||||
|
||||
Chuck.Control.KeyboardInput.prototype._onKeyDown = function(e) {
|
||||
var key = this._getKeyByKeyCode(e.keyCode);
|
||||
if (key && key.getActive() == false) {
|
||||
key.setActivityUpdateStatus(true);
|
||||
key.setActivityUpdateNeeded(true);
|
||||
}
|
||||
}
|
||||
|
||||
Chuck.Control.KeyboardInput.prototype._onKeyUp = function(e) {
|
||||
var key = this._getKeyByKeyCode(e.keyCode);
|
||||
if (key != null) {
|
||||
key.setActivityUpdateStatus(false);
|
||||
key.setActivityUpdateNeeded(true);
|
||||
}
|
||||
}
|
||||
|
||||
Chuck.Control.KeyboardInput.prototype.update = function() {
|
||||
var callback = null;
|
||||
var self = this;
|
||||
$.each(this._registry, function(keyCode, key) {
|
||||
if (key.getActivityUpdateNeeded()) {
|
||||
if (key.getActivityUpdateStatus() == true) {
|
||||
callback = key.getKeyDownFunction();
|
||||
key.setActive(true);
|
||||
} else {
|
||||
callback = key.getKeyUpFunction();
|
||||
key.setActive(false);
|
||||
}
|
||||
key.setActivityUpdateNeeded(false);
|
||||
}
|
||||
|
||||
if (callback) {
|
||||
self._inputControlUnit[callback]();
|
||||
} else {
|
||||
if (key.getActive()) {
|
||||
callback = key.getKeyFrameFunction();
|
||||
if (callback) {
|
||||
self._inputControlUnit[callback]();
|
||||
}
|
||||
}
|
||||
}
|
||||
callback = null;
|
||||
});
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue