Preparing for new release

This commit is contained in:
Richard Davey
2013-04-18 14:16:18 +01:00
parent 72a4809dd8
commit 6bb4c5e3fc
165 changed files with 37278 additions and 29038 deletions
+295 -290
View File
@@ -1,6 +1,4 @@
/// <reference path="../../Game.ts" />
/// <reference path="../../geom/Point.ts" />
/// <reference path="../../geom/Circle.ts" />
/**
* Input - Finger
@@ -13,311 +11,318 @@
* @todo Lots
*/
class Finger {
/**
* Phaser
*/
/**
* Constructor
* @param {Kiwi.Game} game.
* @return {Kiwi.Input.Finger} This object.
*/
constructor(game: Game) {
module Phaser {
this._game = game;
this.active = false;
export class Finger {
}
/**
* Constructor
* @param {Phaser.Game} game.
* @return {Phaser.Finger} This object.
*/
constructor(game: Game) {
/**
*
* @property _game
* @type Kiwi.Game
* @private
**/
private _game: Game;
this._game = game;
this.active = false;
/**
* An identification number for each touch point. When a touch point becomes active, it must be assigned an identifier that is distinct from any other active touch point. While the touch point remains active, all events that refer to it must assign it the same identifier.
* @property identifier
* @type Number
*/
public identifier: number;
/**
*
* @property active
* @type Boolean
*/
public active: bool;
/**
*
* @property point
* @type Point
**/
public point: Point = null;
/**
*
* @property circle
* @type Circle
**/
public circle: Circle = null;
/**
*
* @property withinGame
* @type Boolean
*/
public withinGame: bool = false;
/**
* The horizontal coordinate of point relative to the viewport in pixels, excluding any scroll offset
* @property clientX
* @type Number
*/
public clientX: number = -1;
//
/**
* The vertical coordinate of point relative to the viewport in pixels, excluding any scroll offset
* @property clientY
* @type Number
*/
public clientY: number = -1;
//
/**
* The horizontal coordinate of point relative to the viewport in pixels, including any scroll offset
* @property pageX
* @type Number
*/
public pageX: number = -1;
/**
* The vertical coordinate of point relative to the viewport in pixels, including any scroll offset
* @property pageY
* @type Number
*/
public pageY: number = -1;
/**
* The horizontal coordinate of point relative to the screen in pixels
* @property screenX
* @type Number
*/
public screenX: number = -1;
/**
* The vertical coordinate of point relative to the screen in pixels
* @property screenY
* @type Number
*/
public screenY: number = -1;
/**
* The horizontal coordinate of point relative to the game element
* @property x
* @type Number
*/
public x: number = -1;
/**
* The vertical coordinate of point relative to the game element
* @property y
* @type Number
*/
public y: number = -1;
/**
* The Element on which the touch point started when it was first placed on the surface, even if the touch point has since moved outside the interactive area of that element.
* @property target
* @type Any
*/
public target;
/**
*
* @property isDown
* @type Boolean
**/
public isDown: bool = false;
/**
*
* @property isUp
* @type Boolean
**/
public isUp: bool = false;
/**
*
* @property timeDown
* @type Number
**/
public timeDown: number = 0;
/**
*
* @property duration
* @type Number
**/
public duration: number = 0;
/**
*
* @property timeUp
* @type Number
**/
public timeUp: number = 0;
/**
*
* @property justPressedRate
* @type Number
**/
public justPressedRate: number = 200;
/**
*
* @property justReleasedRate
* @type Number
**/
public justReleasedRate: number = 200;
/**
*
* @method start
* @param {Any} event
*/
public start(event) {
this.identifier = event.identifier;
this.target = event.target;
// populate geom objects
if (this.point === null)
{
this.point = new Point();
}
if (this.circle === null)
{
this.circle = new Circle(0, 0, 44);
/**
*
* @property _game
* @type Phaser.Game
* @private
**/
private _game: Game;
/**
* An identification number for each touch point. When a touch point becomes active, it must be assigned an identifier that is distinct from any other active touch point. While the touch point remains active, all events that refer to it must assign it the same identifier.
* @property identifier
* @type Number
*/
public identifier: number;
/**
*
* @property active
* @type Boolean
*/
public active: bool;
/**
*
* @property point
* @type Point
**/
public point: Point = null;
/**
*
* @property circle
* @type Circle
**/
public circle: Circle = null;
/**
*
* @property withinGame
* @type Boolean
*/
public withinGame: bool = false;
/**
* The horizontal coordinate of point relative to the viewport in pixels, excluding any scroll offset
* @property clientX
* @type Number
*/
public clientX: number = -1;
//
/**
* The vertical coordinate of point relative to the viewport in pixels, excluding any scroll offset
* @property clientY
* @type Number
*/
public clientY: number = -1;
//
/**
* The horizontal coordinate of point relative to the viewport in pixels, including any scroll offset
* @property pageX
* @type Number
*/
public pageX: number = -1;
/**
* The vertical coordinate of point relative to the viewport in pixels, including any scroll offset
* @property pageY
* @type Number
*/
public pageY: number = -1;
/**
* The horizontal coordinate of point relative to the screen in pixels
* @property screenX
* @type Number
*/
public screenX: number = -1;
/**
* The vertical coordinate of point relative to the screen in pixels
* @property screenY
* @type Number
*/
public screenY: number = -1;
/**
* The horizontal coordinate of point relative to the game element
* @property x
* @type Number
*/
public x: number = -1;
/**
* The vertical coordinate of point relative to the game element
* @property y
* @type Number
*/
public y: number = -1;
/**
* The Element on which the touch point started when it was first placed on the surface, even if the touch point has since moved outside the interactive area of that element.
* @property target
* @type Any
*/
public target;
/**
*
* @property isDown
* @type Boolean
**/
public isDown: bool = false;
/**
*
* @property isUp
* @type Boolean
**/
public isUp: bool = false;
/**
*
* @property timeDown
* @type Number
**/
public timeDown: number = 0;
/**
*
* @property duration
* @type Number
**/
public duration: number = 0;
/**
*
* @property timeUp
* @type Number
**/
public timeUp: number = 0;
/**
*
* @property justPressedRate
* @type Number
**/
public justPressedRate: number = 200;
/**
*
* @property justReleasedRate
* @type Number
**/
public justReleasedRate: number = 200;
/**
*
* @method start
* @param {Any} event
*/
public start(event) {
this.identifier = event.identifier;
this.target = event.target;
// populate geom objects
if (this.point === null)
{
this.point = new Point();
}
if (this.circle === null)
{
this.circle = new Circle(0, 0, 44);
}
this.move(event);
this.active = true;
this.withinGame = true;
this.isDown = true;
this.isUp = false;
this.timeDown = this._game.time.now;
}
this.move(event);
/**
*
* @method move
* @param {Any} event
*/
public move(event) {
this.active = true;
this.withinGame = true;
this.isDown = true;
this.isUp = false;
this.timeDown = this._game.time.now;
this.clientX = event.clientX;
this.clientY = event.clientY;
this.pageX = event.pageX;
this.pageY = event.pageY;
this.screenX = event.screenX;
this.screenY = event.screenY;
}
this.x = this.pageX - this._game.stage.offset.x;
this.y = this.pageY - this._game.stage.offset.y;
/**
*
* @method move
* @param {Any} event
*/
public move(event) {
this.point.setTo(this.x, this.y);
this.circle.setTo(this.x, this.y, 44);
this.clientX = event.clientX;
this.clientY = event.clientY;
this.pageX = event.pageX;
this.pageY = event.pageY;
this.screenX = event.screenX;
this.screenY = event.screenY;
// Droppings history (used for gestures and motion tracking)
this.x = this.pageX - this._game.stage.offset.x;
this.y = this.pageY - this._game.stage.offset.y;
this.duration = this._game.time.now - this.timeDown;
this.point.setTo(this.x, this.y);
this.circle.setTo(this.x, this.y, 44);
// Droppings history (used for gestures and motion tracking)
this.duration = this._game.time.now - this.timeDown;
}
/**
*
* @method leave
* @param {Any} event
*/
public leave(event) {
this.withinGame = false;
this.move(event);
}
/**
*
* @method stop
* @param {Any} event
*/
public stop(event) {
this.active = false;
this.withinGame = false;
this.isDown = false;
this.isUp = true;
this.timeUp = this._game.time.now;
this.duration = this.timeUp - this.timeDown;
}
/**
*
* @method justPressed
* @param {Number} [duration].
* @return {Boolean}
*/
public justPressed(duration?: number = this.justPressedRate): bool {
if (this.isDown === true && (this.timeDown + duration) > this._game.time.now)
{
return true;
}
else
{
return false;
/**
*
* @method leave
* @param {Any} event
*/
public leave(event) {
this.withinGame = false;
this.move(event);
}
/**
*
* @method stop
* @param {Any} event
*/
public stop(event) {
this.active = false;
this.withinGame = false;
this.isDown = false;
this.isUp = true;
this.timeUp = this._game.time.now;
this.duration = this.timeUp - this.timeDown;
}
/**
*
* @method justPressed
* @param {Number} [duration].
* @return {Boolean}
*/
public justPressed(duration?: number = this.justPressedRate): bool {
if (this.isDown === true && (this.timeDown + duration) > this._game.time.now)
{
return true;
}
else
{
return false;
}
}
/**
*
* @method justReleased
* @param {Number} [duration].
* @return {Boolean}
*/
public justReleased(duration?: number = this.justReleasedRate): bool {
if (this.isUp === true && (this.timeUp + duration) > this._game.time.now)
{
return true;
}
else
{
return false;
}
}
/**
* Returns a string representation of this object.
* @method toString
* @return {string} a string representation of the instance.
**/
public toString(): string {
return "[{Finger (identifer=" + this.identifier + " active=" + this.active + " duration=" + this.duration + " withinGame=" + this.withinGame + " x=" + this.x + " y=" + this.y + " clientX=" + this.clientX + " clientY=" + this.clientY + " screenX=" + this.screenX + " screenY=" + this.screenY + " pageX=" + this.pageX + " pageY=" + this.pageY + ")}]";
}
}
/**
*
* @method justReleased
* @param {Number} [duration].
* @return {Boolean}
*/
public justReleased(duration?: number = this.justReleasedRate): bool {
if (this.isUp === true && (this.timeUp + duration) > this._game.time.now)
{
return true;
}
else
{
return false;
}
}
/**
* Returns a string representation of this object.
* @method toString
* @return {string} a string representation of the instance.
**/
public toString(): string {
return "[{Finger (identifer=" + this.identifier + " active=" + this.active + " duration=" + this.duration + " withinGame=" + this.withinGame + " x=" + this.x + " y=" + this.y + " clientX=" + this.clientX + " clientY=" + this.clientY + " screenX=" + this.screenX + " screenY=" + this.screenY + " pageX=" + this.pageX + " pageY=" + this.pageY + ")}]";
}
}
}
+73 -68
View File
@@ -1,76 +1,81 @@
/// <reference path="../../Game.ts" />
/// <reference path="Mouse.ts" />
/// <reference path="Keyboard.ts" />
/// <reference path="Touch.ts" />
class Input {
/**
* Phaser
*/
constructor(game: Game) {
module Phaser {
this._game = game;
export class Input {
this.mouse = new Mouse(this._game);
this.keyboard = new Keyboard(this._game);
this.touch = new Touch(this._game);
constructor(game: Game) {
this._game = game;
this.mouse = new Mouse(this._game);
this.keyboard = new Keyboard(this._game);
this.touch = new Touch(this._game);
}
private _game: Game;
public mouse: Mouse;
public keyboard: Keyboard;
public touch: Touch;
public x: number = 0;
public y: number = 0;
public scaleX: number = 1;
public scaleY: number = 1;
public worldX: number = 0;
public worldY: number = 0;
public update() {
this.x = Math.round(this.x);
this.y = Math.round(this.y);
this.worldX = this._game.camera.worldView.x + this.x;
this.worldY = this._game.camera.worldView.y + this.y;
this.mouse.update();
this.touch.update();
}
public reset() {
this.mouse.reset();
this.keyboard.reset();
this.touch.reset();
}
public getWorldX(camera?: Camera = this._game.camera) {
return camera.worldView.x + this.x;
}
public getWorldY(camera?: Camera = this._game.camera) {
return camera.worldView.y + this.y;
}
public renderDebugInfo(x: number, y: number, color?: string = 'rgb(255,255,255)') {
this._game.stage.context.fillStyle = color;
this._game.stage.context.fillText('Input', x, y);
this._game.stage.context.fillText('Screen X: ' + this.x + ' Screen Y: ' + this.y, x, y + 14);
this._game.stage.context.fillText('World X: ' + this.worldX + ' World Y: ' + this.worldY, x, y + 28);
this._game.stage.context.fillText('Scale X: ' + this.scaleX.toFixed(1) + ' Scale Y: ' + this.scaleY.toFixed(1), x, y + 42);
}
}
private _game: Game;
public mouse: Mouse;
public keyboard: Keyboard;
public touch: Touch;
public x: number = 0;
public y: number = 0;
public scaleX: number = 1;
public scaleY: number = 1;
public worldX: number = 0;
public worldY: number = 0;
public update() {
this.x = Math.round(this.x);
this.y = Math.round(this.y);
this.worldX = this._game.camera.worldView.x + this.x;
this.worldY = this._game.camera.worldView.y + this.y;
this.mouse.update();
this.touch.update();
}
public reset() {
this.mouse.reset();
this.keyboard.reset();
this.touch.reset();
}
public getWorldX(camera?: Camera = this._game.camera) {
return camera.worldView.x + this.x;
}
public getWorldY(camera?: Camera = this._game.camera) {
return camera.worldView.y + this.y;
}
public renderDebugInfo(x: number, y: number, color?: string = 'rgb(255,255,255)') {
this._game.stage.context.fillStyle = color;
this._game.stage.context.fillText('Input', x, y);
this._game.stage.context.fillText('Screen X: ' + this.x + ' Screen Y: ' + this.y, x, y + 14);
this._game.stage.context.fillText('World X: ' + this.worldX + ' World Y: ' + this.worldY, x, y + 28);
this._game.stage.context.fillText('Scale X: ' + this.scaleX.toFixed(1) + ' Scale Y: ' + this.scaleY.toFixed(1), x, y + 42);
}
}
}
+234 -207
View File
@@ -1,214 +1,241 @@
/// <reference path="../../Game.ts" />
/// <reference path="Input.ts" />
class Keyboard {
/**
* Phaser
*/
constructor(game: Game) {
module Phaser {
this._game = game;
this.start();
export class Keyboard {
constructor(game: Game) {
this._game = game;
this.start();
}
private _game: Game;
private _keys = {};
private _capture = {};
public start() {
document.body.addEventListener('keydown', (event: KeyboardEvent) => this.onKeyDown(event), false);
document.body.addEventListener('keyup', (event: KeyboardEvent) => this.onKeyUp(event), false);
}
public addKeyCapture(keycode: number) {
this._capture[keycode] = true;
}
public removeKeyCapture(keycode: number) {
delete this._capture[keycode];
}
public clearCaptures() {
this._capture = {};
}
public onKeyDown(event: KeyboardEvent) {
if (this._capture[event.keyCode])
{
event.preventDefault();
}
if (!this._keys[event.keyCode])
{
this._keys[event.keyCode] = { isDown: true, timeDown: this._game.time.now, timeUp: 0 };
}
else
{
this._keys[event.keyCode].isDown = true;
this._keys[event.keyCode].timeDown = this._game.time.now;
}
}
public onKeyUp(event: KeyboardEvent) {
if (this._capture[event.keyCode])
{
event.preventDefault();
}
if (!this._keys[event.keyCode])
{
this._keys[event.keyCode] = { isDown: false, timeDown: 0, timeUp: this._game.time.now };
}
else
{
this._keys[event.keyCode].isDown = false;
this._keys[event.keyCode].timeUp = this._game.time.now;
}
}
public reset() {
for (var key in this._keys)
{
this._keys[key].isDown = false;
}
}
public justPressed(keycode: number, duration?: number = 250): bool {
if (this._keys[keycode] && this._keys[keycode].isDown === true && (this._game.time.now - this._keys[keycode].timeDown < duration))
{
return true;
}
else
{
return false;
}
}
public justReleased(keycode: number, duration?: number = 250): bool {
if (this._keys[keycode] && this._keys[keycode].isDown === false && (this._game.time.now - this._keys[keycode].timeUp < duration))
{
return true;
}
else
{
return false;
}
}
public isDown(keycode: number): bool {
if (this._keys[keycode])
{
return this._keys[keycode].isDown;
}
else
{
return false;
}
}
// Letters
public static A: number = "A".charCodeAt(0);
public static B: number = "B".charCodeAt(0);
public static C: number = "C".charCodeAt(0);
public static D: number = "D".charCodeAt(0);
public static E: number = "E".charCodeAt(0);
public static F: number = "F".charCodeAt(0);
public static G: number = "G".charCodeAt(0);
public static H: number = "H".charCodeAt(0);
public static I: number = "I".charCodeAt(0);
public static J: number = "J".charCodeAt(0);
public static K: number = "K".charCodeAt(0);
public static L: number = "L".charCodeAt(0);
public static M: number = "M".charCodeAt(0);
public static N: number = "N".charCodeAt(0);
public static O: number = "O".charCodeAt(0);
public static P: number = "P".charCodeAt(0);
public static Q: number = "Q".charCodeAt(0);
public static R: number = "R".charCodeAt(0);
public static S: number = "S".charCodeAt(0);
public static T: number = "T".charCodeAt(0);
public static U: number = "U".charCodeAt(0);
public static V: number = "V".charCodeAt(0);
public static W: number = "W".charCodeAt(0);
public static X: number = "X".charCodeAt(0);
public static Y: number = "Y".charCodeAt(0);
public static Z: number = "Z".charCodeAt(0);
// Numbers
public static ZERO: number = "0".charCodeAt(0);
public static ONE: number = "1".charCodeAt(0);
public static TWO: number = "2".charCodeAt(0);
public static THREE: number = "3".charCodeAt(0);
public static FOUR: number = "4".charCodeAt(0);
public static FIVE: number = "5".charCodeAt(0);
public static SIX: number = "6".charCodeAt(0);
public static SEVEN: number = "7".charCodeAt(0);
public static EIGHT: number = "8".charCodeAt(0);
public static NINE: number = "9".charCodeAt(0);
// Numpad
public static NUMPAD_0: number = 96;
public static NUMPAD_1: number = 97;
public static NUMPAD_2: number = 98;
public static NUMPAD_3: number = 99;
public static NUMPAD_4: number = 100;
public static NUMPAD_5: number = 101;
public static NUMPAD_6: number = 102;
public static NUMPAD_7: number = 103;
public static NUMPAD_8: number = 104;
public static NUMPAD_9: number = 105;
public static NUMPAD_MULTIPLY: number = 106;
public static NUMPAD_ADD: number = 107;
public static NUMPAD_ENTER: number = 108;
public static NUMPAD_SUBTRACT: number = 109;
public static NUMPAD_DECIMAL: number = 110;
public static NUMPAD_DIVIDE: number = 111;
// Function Keys
public static F1: number = 112;
public static F2: number = 113;
public static F3: number = 114;
public static F4: number = 115;
public static F5: number = 116;
public static F6: number = 117;
public static F7: number = 118;
public static F8: number = 119;
public static F9: number = 120;
public static F10: number = 121;
public static F11: number = 122;
public static F12: number = 123;
public static F13: number = 124;
public static F14: number = 125;
public static F15: number = 126;
// Symbol Keys
public static COLON: number = 186;
public static EQUALS: number = 187;
public static UNDERSCORE: number = 189;
public static QUESTION_MARK: number = 191;
public static TILDE: number = 192;
public static OPEN_BRACKET: number = 219;
public static BACKWARD_SLASH: number = 220;
public static CLOSED_BRACKET: number = 221;
public static QUOTES: number = 222;
// Other Keys
public static BACKSPACE: number = 8;
public static TAB: number = 9;
public static CLEAR: number = 12;
public static ENTER: number = 13;
public static SHIFT: number = 16;
public static CONTROL: number = 17;
public static ALT: number = 18;
public static CAPS_LOCK: number = 20;
public static ESC: number = 27;
public static SPACEBAR: number = 32;
public static PAGE_UP: number = 33;
public static PAGE_DOWN: number = 34;
public static END: number = 35;
public static HOME: number = 36;
public static LEFT: number = 37;
public static UP: number = 38;
public static RIGHT: number = 39;
public static DOWN: number = 40;
public static INSERT: number = 45;
public static DELETE: number = 46;
public static HELP: number = 47;
public static NUM_LOCK: number = 144;
}
private _game: Game;
private _keys = {};
public start() {
document.body.addEventListener('keydown', (event: KeyboardEvent) => this.onKeyDown(event), false);
document.body.addEventListener('keyup', (event: KeyboardEvent) => this.onKeyUp(event), false);
}
public onKeyDown(event: KeyboardEvent) {
//event.preventDefault();
if (!this._keys[event.keyCode])
{
this._keys[event.keyCode] = { isDown: true, timeDown: this._game.time.now, timeUp: 0 };
}
else
{
this._keys[event.keyCode].isDown = true;
this._keys[event.keyCode].timeDown = this._game.time.now;
}
}
public onKeyUp(event: KeyboardEvent) {
//event.preventDefault();
if (!this._keys[event.keyCode])
{
this._keys[event.keyCode] = { isDown: false, timeDown: 0, timeUp: this._game.time.now };
}
else
{
this._keys[event.keyCode].isDown = false;
this._keys[event.keyCode].timeUp = this._game.time.now;
}
}
public reset() {
for (var key in this._keys)
{
this._keys[key].isDown = false;
}
}
public justPressed(keycode: number, duration?: number = 250): bool {
if (this._keys[keycode] && this._keys[keycode].isDown === true && (this._game.time.now - this._keys[keycode].timeDown < duration))
{
return true;
}
else
{
return false;
}
}
public justReleased(keycode: number, duration?: number = 250): bool {
if (this._keys[keycode] && this._keys[keycode].isDown === false && (this._game.time.now - this._keys[keycode].timeUp < duration))
{
return true;
}
else
{
return false;
}
}
public isDown(keycode: number): bool {
if (this._keys[keycode])
{
return this._keys[keycode].isDown;
}
else
{
return false;
}
}
// Letters
public static A: number = "A".charCodeAt(0);
public static B: number = "B".charCodeAt(0);
public static C: number = "C".charCodeAt(0);
public static D: number = "D".charCodeAt(0);
public static E: number = "E".charCodeAt(0);
public static F: number = "F".charCodeAt(0);
public static G: number = "G".charCodeAt(0);
public static H: number = "H".charCodeAt(0);
public static I: number = "I".charCodeAt(0);
public static J: number = "J".charCodeAt(0);
public static K: number = "K".charCodeAt(0);
public static L: number = "L".charCodeAt(0);
public static M: number = "M".charCodeAt(0);
public static N: number = "N".charCodeAt(0);
public static O: number = "O".charCodeAt(0);
public static P: number = "P".charCodeAt(0);
public static Q: number = "Q".charCodeAt(0);
public static R: number = "R".charCodeAt(0);
public static S: number = "S".charCodeAt(0);
public static T: number = "T".charCodeAt(0);
public static U: number = "U".charCodeAt(0);
public static V: number = "V".charCodeAt(0);
public static W: number = "W".charCodeAt(0);
public static X: number = "X".charCodeAt(0);
public static Y: number = "Y".charCodeAt(0);
public static Z: number = "Z".charCodeAt(0);
// Numbers
public static ZERO: number = "0".charCodeAt(0);
public static ONE: number = "1".charCodeAt(0);
public static TWO: number = "2".charCodeAt(0);
public static THREE: number = "3".charCodeAt(0);
public static FOUR: number = "4".charCodeAt(0);
public static FIVE: number = "5".charCodeAt(0);
public static SIX: number = "6".charCodeAt(0);
public static SEVEN: number = "7".charCodeAt(0);
public static EIGHT: number = "8".charCodeAt(0);
public static NINE: number = "9".charCodeAt(0);
// Numpad
public static NUMPAD_0: number = 96;
public static NUMPAD_1: number = 97;
public static NUMPAD_2: number = 98;
public static NUMPAD_3: number = 99;
public static NUMPAD_4: number = 100;
public static NUMPAD_5: number = 101;
public static NUMPAD_6: number = 102;
public static NUMPAD_7: number = 103;
public static NUMPAD_8: number = 104;
public static NUMPAD_9: number = 105;
public static NUMPAD_MULTIPLY: number = 106;
public static NUMPAD_ADD: number = 107;
public static NUMPAD_ENTER: number = 108;
public static NUMPAD_SUBTRACT: number = 109;
public static NUMPAD_DECIMAL: number = 110;
public static NUMPAD_DIVIDE: number = 111;
// Function Keys
public static F1: number = 112;
public static F2: number = 113;
public static F3: number = 114;
public static F4: number = 115;
public static F5: number = 116;
public static F6: number = 117;
public static F7: number = 118;
public static F8: number = 119;
public static F9: number = 120;
public static F10: number = 121;
public static F11: number = 122;
public static F12: number = 123;
public static F13: number = 124;
public static F14: number = 125;
public static F15: number = 126;
// Symbol Keys
public static COLON: number = 186;
public static EQUALS: number = 187;
public static UNDERSCORE: number = 189;
public static QUESTION_MARK: number = 191;
public static TILDE: number = 192;
public static OPEN_BRACKET: number = 219;
public static BACKWARD_SLASH: number = 220;
public static CLOSED_BRACKET: number = 221;
public static QUOTES: number = 222;
// Other Keys
public static BACKSPACE: number = 8;
public static TAB: number = 9;
public static CLEAR: number = 12;
public static ENTER: number = 13;
public static SHIFT: number = 16;
public static CONTROL: number = 17;
public static ALT: number = 18;
public static CAPS_LOCK: number = 20;
public static ESC: number = 27;
public static SPACEBAR: number = 32;
public static PAGE_UP: number = 33;
public static PAGE_DOWN: number = 34;
public static END: number = 35;
public static HOME: number = 36;
public static LEFT: number = 37;
public static UP: number = 38;
public static RIGHT: number = 39;
public static DOWN: number = 40;
public static INSERT: number = 45;
public static DELETE: number = 46;
public static HELP: number = 47;
public static NUM_LOCK: number = 144;
}
}
+80 -73
View File
@@ -1,101 +1,108 @@
/// <reference path="../../Game.ts" />
/// <reference path="Input.ts" />
class Mouse {
/**
* Phaser
*/
constructor(game: Game) {
module Phaser {
this._game = game;
this.start();
export class Mouse {
}
constructor(game: Game) {
private _game: Game;
this._game = game;
this.start();
private _x: number = 0;
private _y: number = 0;
}
public button: number;
private _game: Game;
public static LEFT_BUTTON: number = 0;
public static MIDDLE_BUTTON: number = 1;
public static RIGHT_BUTTON: number = 2;
private _x: number = 0;
private _y: number = 0;
public isDown: bool = false;
public isUp: bool = true;
public timeDown: number = 0;
public duration: number = 0;
public timeUp: number = 0;
public button: number;
public start() {
public static LEFT_BUTTON: number = 0;
public static MIDDLE_BUTTON: number = 1;
public static RIGHT_BUTTON: number = 2;
this._game.stage.canvas.addEventListener('mousedown', (event: MouseEvent) => this.onMouseDown(event), true);
this._game.stage.canvas.addEventListener('mousemove', (event: MouseEvent) => this.onMouseMove(event), true);
this._game.stage.canvas.addEventListener('mouseup', (event: MouseEvent) => this.onMouseUp(event), true);
public isDown: bool = false;
public isUp: bool = true;
public timeDown: number = 0;
public duration: number = 0;
public timeUp: number = 0;
}
public reset() {
public start() {
this.isDown = false;
this.isUp = true;
this._game.stage.canvas.addEventListener('mousedown', (event: MouseEvent) => this.onMouseDown(event), true);
this._game.stage.canvas.addEventListener('mousemove', (event: MouseEvent) => this.onMouseMove(event), true);
this._game.stage.canvas.addEventListener('mouseup', (event: MouseEvent) => this.onMouseUp(event), true);
}
}
public onMouseDown(event: MouseEvent) {
public reset() {
this.button = event.button;
this.isDown = false;
this.isUp = true;
this._x = event.clientX - this._game.stage.x;
this._y = event.clientY - this._game.stage.y;
}
this._game.input.x = this._x * this._game.input.scaleX;
this._game.input.y = this._y * this._game.input.scaleY;
public onMouseDown(event: MouseEvent) {
this.isDown = true;
this.isUp = false;
this.timeDown = this._game.time.now;
this.button = event.button;
}
this._x = event.clientX - this._game.stage.x;
this._y = event.clientY - this._game.stage.y;
public update() {
this._game.input.x = this._x * this._game.input.scaleX;
this._game.input.y = this._y * this._game.input.scaleY;
//this._game.input.x = this._x * this._game.input.scaleX;
//this._game.input.y = this._y * this._game.input.scaleY;
this.isDown = true;
this.isUp = false;
this.timeDown = this._game.time.now;
}
public update() {
//this._game.input.x = this._x * this._game.input.scaleX;
//this._game.input.y = this._y * this._game.input.scaleY;
if (this.isDown)
{
this.duration = this._game.time.now - this.timeDown;
}
}
public onMouseMove(event: MouseEvent) {
this.button = event.button;
this._x = event.clientX - this._game.stage.x;
this._y = event.clientY - this._game.stage.y;
this._game.input.x = this._x * this._game.input.scaleX;
this._game.input.y = this._y * this._game.input.scaleY;
}
public onMouseUp(event: MouseEvent) {
this.button = event.button;
this.isDown = false;
this.isUp = true;
this.timeUp = this._game.time.now;
this.duration = this.timeUp - this.timeDown;
this._x = event.clientX - this._game.stage.x;
this._y = event.clientY - this._game.stage.y;
this._game.input.x = this._x * this._game.input.scaleX;
this._game.input.y = this._y * this._game.input.scaleY;
if (this.isDown)
{
this.duration = this._game.time.now - this.timeDown;
}
}
public onMouseMove(event: MouseEvent) {
this.button = event.button;
this._x = event.clientX - this._game.stage.x;
this._y = event.clientY - this._game.stage.y;
this._game.input.x = this._x * this._game.input.scaleX;
this._game.input.y = this._y * this._game.input.scaleY;
}
public onMouseUp(event: MouseEvent) {
this.button = event.button;
this.isDown = false;
this.isUp = true;
this.timeUp = this._game.time.now;
this.duration = this.timeUp - this.timeDown;
this._x = event.clientX - this._game.stage.x;
this._y = event.clientY - this._game.stage.y;
this._game.input.x = this._x * this._game.input.scaleX;
this._game.input.y = this._y * this._game.input.scaleY;
}
}
}
+390 -384
View File
@@ -1,5 +1,4 @@
/// <reference path="../../Game.ts" />
/// <reference path="../../Signal.ts" />
/// <reference path="Finger.ts" />
/**
@@ -20,430 +19,437 @@
* Input Zones (mouse and touch) - lock entities within them + axis aligned drags
*/
class Touch {
/**
* Phaser
*/
/**
* Constructor
* @param {Game} game.
* @return {Touch} This object.
*/
constructor(game: Game) {
module Phaser {
this._game = game;
export class Touch {
this.finger1 = new Finger(this._game);
this.finger2 = new Finger(this._game);
this.finger3 = new Finger(this._game);
this.finger4 = new Finger(this._game);
this.finger5 = new Finger(this._game);
this.finger6 = new Finger(this._game);
this.finger7 = new Finger(this._game);
this.finger8 = new Finger(this._game);
this.finger9 = new Finger(this._game);
this.finger10 = new Finger(this._game);
/**
* Constructor
* @param {Game} game.
* @return {Touch} This object.
*/
constructor(game: Game) {
this._fingers = [this.finger1, this.finger2, this.finger3, this.finger4, this.finger5, this.finger6, this.finger7, this.finger8, this.finger9, this.finger10];
this._game = game;
this.touchDown = new Signal();
this.touchUp = new Signal();
this.finger1 = new Finger(this._game);
this.finger2 = new Finger(this._game);
this.finger3 = new Finger(this._game);
this.finger4 = new Finger(this._game);
this.finger5 = new Finger(this._game);
this.finger6 = new Finger(this._game);
this.finger7 = new Finger(this._game);
this.finger8 = new Finger(this._game);
this.finger9 = new Finger(this._game);
this.finger10 = new Finger(this._game);
this.start();
this._fingers = [this.finger1, this.finger2, this.finger3, this.finger4, this.finger5, this.finger6, this.finger7, this.finger8, this.finger9, this.finger10];
}
this.touchDown = new Signal();
this.touchUp = new Signal();
/**
*
* @property _game
* @type Game
* @private
**/
private _game: Game;
this.start();
/**
*
* @property x
* @type Number
**/
public x: number = 0;
}
/**
*
* @property y
* @type Number
**/
public y: number = 0;
/**
*
* @property _game
* @type Game
* @private
**/
private _game: Game;
/**
*
* @property _fingers
* @type Array
* @private
**/
private _fingers: Finger[];
/**
*
* @property x
* @type Number
**/
public x: number = 0;
/**
*
* @property finger1
* @type Finger
**/
public finger1: Finger;
/**
*
* @property y
* @type Number
**/
public y: number = 0;
/**
*
* @property finger2
* @type Finger
**/
public finger2: Finger;
/**
*
* @property _fingers
* @type Array
* @private
**/
private _fingers: Finger[];
/**
*
* @property finger3
* @type Finger
**/
public finger3: Finger;
/**
*
* @property finger1
* @type Finger
**/
public finger1: Finger;
/**
*
* @property finger4
* @type Finger
**/
public finger4: Finger;
/**
*
* @property finger2
* @type Finger
**/
public finger2: Finger;
/**
*
* @property finger5
* @type Finger
**/
public finger5: Finger;
/**
*
* @property finger3
* @type Finger
**/
public finger3: Finger;
/**
*
* @property finger6
* @type Finger
**/
public finger6: Finger;
/**
*
* @property finger4
* @type Finger
**/
public finger4: Finger;
/**
*
* @property finger7
* @type Finger
**/
public finger7: Finger;
/**
*
* @property finger5
* @type Finger
**/
public finger5: Finger;
/**
*
* @property finger8
* @type Finger
**/
public finger8: Finger;
/**
*
* @property finger6
* @type Finger
**/
public finger6: Finger;
/**
*
* @property finger9
* @type Finger
**/
public finger9: Finger;
/**
*
* @property finger7
* @type Finger
**/
public finger7: Finger;
/**
*
* @property finger10
* @type Finger
**/
public finger10: Finger;
/**
*
* @property finger8
* @type Finger
**/
public finger8: Finger;
/**
*
* @property latestFinger
* @type Finger
**/
public latestFinger: Finger;
/**
*
* @property finger9
* @type Finger
**/
public finger9: Finger;
/**
*
* @property isDown
* @type Boolean
**/
public isDown: bool = false;
/**
*
* @property finger10
* @type Finger
**/
public finger10: Finger;
/**
*
* @property isUp
* @type Boolean
**/
public isUp: bool = true;
/**
*
* @property latestFinger
* @type Finger
**/
public latestFinger: Finger;
public touchDown: Signal;
public touchUp: Signal;
/**
*
* @property isDown
* @type Boolean
**/
public isDown: bool = false;
/**
*
* @method start
*/
public start() {
/**
*
* @property isUp
* @type Boolean
**/
public isUp: bool = true;
this._game.stage.canvas.addEventListener('touchstart', (event) => this.onTouchStart(event), false);
this._game.stage.canvas.addEventListener('touchmove', (event) => this.onTouchMove(event), false);
this._game.stage.canvas.addEventListener('touchend', (event) => this.onTouchEnd(event), false);
this._game.stage.canvas.addEventListener('touchenter', (event) => this.onTouchEnter(event), false);
this._game.stage.canvas.addEventListener('touchleave', (event) => this.onTouchLeave(event), false);
this._game.stage.canvas.addEventListener('touchcancel', (event) => this.onTouchCancel(event), false);
public touchDown: Signal;
public touchUp: Signal;
document.addEventListener('touchmove', (event) => this.consumeTouchMove(event), false);
/**
*
* @method start
*/
public start() {
}
this._game.stage.canvas.addEventListener('touchstart', (event) => this.onTouchStart(event), false);
this._game.stage.canvas.addEventListener('touchmove', (event) => this.onTouchMove(event), false);
this._game.stage.canvas.addEventListener('touchend', (event) => this.onTouchEnd(event), false);
this._game.stage.canvas.addEventListener('touchenter', (event) => this.onTouchEnter(event), false);
this._game.stage.canvas.addEventListener('touchleave', (event) => this.onTouchLeave(event), false);
this._game.stage.canvas.addEventListener('touchcancel', (event) => this.onTouchCancel(event), false);
/**
* Prevent iOS bounce-back (doesn't work?)
* @method consumeTouchMove
* @param {Any} event
**/
private consumeTouchMove(event) {
document.addEventListener('touchmove', (event) => this.consumeTouchMove(event), false);
event.preventDefault();
}
}
/**
* Prevent iOS bounce-back (doesn't work?)
* @method consumeTouchMove
* @param {Any} event
**/
private consumeTouchMove(event) {
/**
*
* @method onTouchStart
* @param {Any} event
**/
private onTouchStart(event) {
event.preventDefault();
event.preventDefault();
}
// A list of all the touch points that BECAME active with the current event
// https://developer.mozilla.org/en-US/docs/DOM/TouchList
/**
*
* @method onTouchStart
* @param {Any} event
**/
private onTouchStart(event) {
// event.targetTouches = list of all touches on the TARGET ELEMENT (i.e. game dom element)
// event.touches = list of all touches on the ENTIRE DOCUMENT, not just the target element
// event.changedTouches = the touches that CHANGED in this event, not the total number of them
for (var i = 0; i < event.changedTouches.length; i++)
{
for (var f = 0; f < this._fingers.length; f++)
event.preventDefault();
// A list of all the touch points that BECAME active with the current event
// https://developer.mozilla.org/en-US/docs/DOM/TouchList
// event.targetTouches = list of all touches on the TARGET ELEMENT (i.e. game dom element)
// event.touches = list of all touches on the ENTIRE DOCUMENT, not just the target element
// event.changedTouches = the touches that CHANGED in this event, not the total number of them
for (var i = 0; i < event.changedTouches.length; i++)
{
if (this._fingers[f].active === false)
for (var f = 0; f < this._fingers.length; f++)
{
this._fingers[f].start(event.changedTouches[i]);
this.x = this._fingers[f].x;
this.y = this._fingers[f].y;
this._game.input.x = this.x * this._game.input.scaleX;
this._game.input.y = this.y * this._game.input.scaleY;
this.touchDown.dispatch(this._fingers[f].x, this._fingers[f].y, this._fingers[f].timeDown, this._fingers[f].timeUp, this._fingers[f].duration);
this.isDown = true;
this.isUp = false;
break;
if (this._fingers[f].active === false)
{
this._fingers[f].start(event.changedTouches[i]);
this.x = this._fingers[f].x;
this.y = this._fingers[f].y;
this._game.input.x = this.x * this._game.input.scaleX;
this._game.input.y = this.y * this._game.input.scaleY;
this.touchDown.dispatch(this._fingers[f].x, this._fingers[f].y, this._fingers[f].timeDown, this._fingers[f].timeUp, this._fingers[f].duration);
this.isDown = true;
this.isUp = false;
break;
}
}
}
}
/**
* Doesn't appear to be supported by most browsers yet
* @method onTouchCancel
* @param {Any} event
**/
private onTouchCancel(event) {
event.preventDefault();
// Touch cancel - touches that were disrupted (perhaps by moving into a plugin or browser chrome)
// http://www.w3.org/TR/touch-events/#dfn-touchcancel
// event.changedTouches = the touches that CHANGED in this event, not the total number of them
for (var i = 0; i < event.changedTouches.length; i++)
{
for (var f = 0; f < this._fingers.length; f++)
{
if (this._fingers[f].identifier === event.changedTouches[i].identifier)
{
this._fingers[f].stop(event.changedTouches[i]);
break;
}
}
}
}
/**
* Doesn't appear to be supported by most browsers yet
* @method onTouchEnter
* @param {Any} event
**/
private onTouchEnter(event) {
event.preventDefault();
// For touch enter and leave its a list of the touch points that have entered or left the target
// event.targetTouches = list of all touches on the TARGET ELEMENT (i.e. game dom element)
// event.touches = list of all touches on the ENTIRE DOCUMENT, not just the target element
// event.changedTouches = the touches that CHANGED in this event, not the total number of them
for (var i = 0; i < event.changedTouches.length; i++)
{
for (var f = 0; f < this._fingers.length; f++)
{
if (this._fingers[f].active === false)
{
this._fingers[f].start(event.changedTouches[i]);
break;
}
}
}
}
/**
* Doesn't appear to be supported by most browsers yet
* @method onTouchLeave
* @param {Any} event
**/
private onTouchLeave(event) {
event.preventDefault();
// For touch enter and leave its a list of the touch points that have entered or left the target
// event.changedTouches = the touches that CHANGED in this event, not the total number of them
for (var i = 0; i < event.changedTouches.length; i++)
{
for (var f = 0; f < this._fingers.length; f++)
{
if (this._fingers[f].identifier === event.changedTouches[i].identifier)
{
this._fingers[f].leave(event.changedTouches[i]);
break;
}
}
}
}
/**
*
* @method onTouchMove
* @param {Any} event
**/
private onTouchMove(event) {
event.preventDefault();
// event.targetTouches = list of all touches on the TARGET ELEMENT (i.e. game dom element)
// event.touches = list of all touches on the ENTIRE DOCUMENT, not just the target element
// event.changedTouches = the touches that CHANGED in this event, not the total number of them
for (var i = 0; i < event.changedTouches.length; i++)
{
for (var f = 0; f < this._fingers.length; f++)
{
if (this._fingers[f].identifier === event.changedTouches[i].identifier)
{
this._fingers[f].move(event.changedTouches[i]);
this.x = this._fingers[f].x;
this.y = this._fingers[f].y;
this._game.input.x = this.x * this._game.input.scaleX;
this._game.input.y = this.y * this._game.input.scaleY;
break;
}
}
}
}
/**
*
* @method onTouchEnd
* @param {Any} event
**/
private onTouchEnd(event) {
event.preventDefault();
// For touch end its a list of the touch points that have been removed from the surface
// https://developer.mozilla.org/en-US/docs/DOM/TouchList
// event.changedTouches = the touches that CHANGED in this event, not the total number of them
for (var i = 0; i < event.changedTouches.length; i++)
{
for (var f = 0; f < this._fingers.length; f++)
{
if (this._fingers[f].identifier === event.changedTouches[i].identifier)
{
this._fingers[f].stop(event.changedTouches[i]);
this.x = this._fingers[f].x;
this.y = this._fingers[f].y;
this._game.input.x = this.x * this._game.input.scaleX;
this._game.input.y = this.y * this._game.input.scaleY;
this.touchUp.dispatch(this._fingers[f].x, this._fingers[f].y, this._fingers[f].timeDown, this._fingers[f].timeUp, this._fingers[f].duration);
this.isDown = false;
this.isUp = true;
break;
}
}
}
}
/**
*
* @method calculateDistance
* @param {Finger} finger1
* @param {Finger} finger2
**/
public calculateDistance(finger1: Finger, finger2: Finger) {
}
/**
*
* @method calculateAngle
* @param {Finger} finger1
* @param {Finger} finger2
**/
public calculateAngle(finger1: Finger, finger2: Finger) {
}
/**
*
* @method checkOverlap
* @param {Finger} finger1
* @param {Finger} finger2
**/
public checkOverlap(finger1: Finger, finger2: Finger) {
}
/**
*
* @method update
*/
public update() {
}
/**
*
* @method stop
*/
public stop() {
//this._domElement.addEventListener('touchstart', (event) => this.onTouchStart(event), false);
//this._domElement.addEventListener('touchmove', (event) => this.onTouchMove(event), false);
//this._domElement.addEventListener('touchend', (event) => this.onTouchEnd(event), false);
//this._domElement.addEventListener('touchenter', (event) => this.onTouchEnter(event), false);
//this._domElement.addEventListener('touchleave', (event) => this.onTouchLeave(event), false);
//this._domElement.addEventListener('touchcancel', (event) => this.onTouchCancel(event), false);
}
/**
*
* @method reset
**/
public reset() {
this.isDown = false;
this.isUp = false;
}
}
/**
* Doesn't appear to be supported by most browsers yet
* @method onTouchCancel
* @param {Any} event
**/
private onTouchCancel(event) {
event.preventDefault();
// Touch cancel - touches that were disrupted (perhaps by moving into a plugin or browser chrome)
// http://www.w3.org/TR/touch-events/#dfn-touchcancel
// event.changedTouches = the touches that CHANGED in this event, not the total number of them
for (var i = 0; i < event.changedTouches.length; i++)
{
for (var f = 0; f < this._fingers.length; f++)
{
if (this._fingers[f].identifier === event.changedTouches[i].identifier)
{
this._fingers[f].stop(event.changedTouches[i]);
break;
}
}
}
}
/**
* Doesn't appear to be supported by most browsers yet
* @method onTouchEnter
* @param {Any} event
**/
private onTouchEnter(event) {
event.preventDefault();
// For touch enter and leave its a list of the touch points that have entered or left the target
// event.targetTouches = list of all touches on the TARGET ELEMENT (i.e. game dom element)
// event.touches = list of all touches on the ENTIRE DOCUMENT, not just the target element
// event.changedTouches = the touches that CHANGED in this event, not the total number of them
for (var i = 0; i < event.changedTouches.length; i++)
{
for (var f = 0; f < this._fingers.length; f++)
{
if (this._fingers[f].active === false)
{
this._fingers[f].start(event.changedTouches[i]);
break;
}
}
}
}
/**
* Doesn't appear to be supported by most browsers yet
* @method onTouchLeave
* @param {Any} event
**/
private onTouchLeave(event) {
event.preventDefault();
// For touch enter and leave its a list of the touch points that have entered or left the target
// event.changedTouches = the touches that CHANGED in this event, not the total number of them
for (var i = 0; i < event.changedTouches.length; i++)
{
for (var f = 0; f < this._fingers.length; f++)
{
if (this._fingers[f].identifier === event.changedTouches[i].identifier)
{
this._fingers[f].leave(event.changedTouches[i]);
break;
}
}
}
}
/**
*
* @method onTouchMove
* @param {Any} event
**/
private onTouchMove(event) {
event.preventDefault();
// event.targetTouches = list of all touches on the TARGET ELEMENT (i.e. game dom element)
// event.touches = list of all touches on the ENTIRE DOCUMENT, not just the target element
// event.changedTouches = the touches that CHANGED in this event, not the total number of them
for (var i = 0; i < event.changedTouches.length; i++)
{
for (var f = 0; f < this._fingers.length; f++)
{
if (this._fingers[f].identifier === event.changedTouches[i].identifier)
{
this._fingers[f].move(event.changedTouches[i]);
this.x = this._fingers[f].x;
this.y = this._fingers[f].y;
this._game.input.x = this.x * this._game.input.scaleX;
this._game.input.y = this.y * this._game.input.scaleY;
break;
}
}
}
}
/**
*
* @method onTouchEnd
* @param {Any} event
**/
private onTouchEnd(event) {
event.preventDefault();
// For touch end its a list of the touch points that have been removed from the surface
// https://developer.mozilla.org/en-US/docs/DOM/TouchList
// event.changedTouches = the touches that CHANGED in this event, not the total number of them
for (var i = 0; i < event.changedTouches.length; i++)
{
for (var f = 0; f < this._fingers.length; f++)
{
if (this._fingers[f].identifier === event.changedTouches[i].identifier)
{
this._fingers[f].stop(event.changedTouches[i]);
this.x = this._fingers[f].x;
this.y = this._fingers[f].y;
this._game.input.x = this.x * this._game.input.scaleX;
this._game.input.y = this.y * this._game.input.scaleY;
this.touchUp.dispatch(this._fingers[f].x, this._fingers[f].y, this._fingers[f].timeDown, this._fingers[f].timeUp, this._fingers[f].duration);
this.isDown = false;
this.isUp = true;
break;
}
}
}
}
/**
*
* @method calculateDistance
* @param {Finger} finger1
* @param {Finger} finger2
**/
public calculateDistance(finger1: Finger, finger2: Finger) {
}
/**
*
* @method calculateAngle
* @param {Finger} finger1
* @param {Finger} finger2
**/
public calculateAngle(finger1: Finger, finger2: Finger) {
}
/**
*
* @method checkOverlap
* @param {Finger} finger1
* @param {Finger} finger2
**/
public checkOverlap(finger1: Finger, finger2: Finger) {
}
/**
*
* @method update
*/
public update() {
}
/**
*
* @method stop
*/
public stop() {
//this._domElement.addEventListener('touchstart', (event) => this.onTouchStart(event), false);
//this._domElement.addEventListener('touchmove', (event) => this.onTouchMove(event), false);
//this._domElement.addEventListener('touchend', (event) => this.onTouchEnd(event), false);
//this._domElement.addEventListener('touchenter', (event) => this.onTouchEnter(event), false);
//this._domElement.addEventListener('touchleave', (event) => this.onTouchLeave(event), false);
//this._domElement.addEventListener('touchcancel', (event) => this.onTouchCancel(event), false);
}
/**
*
* @method reset
**/
public reset() {
this.isDown = false;
this.isUp = false;
}
}
}