implemented mouse looking

This commit is contained in:
logsol 2013-12-12 18:42:27 +01:00
parent 88d70f2549
commit 5f7917c5cc
9 changed files with 117 additions and 19 deletions

View file

@ -0,0 +1,38 @@
define([
"Game/Client/Control/Input/XyInput",
"Game/Client/View/DomController",
"Game/Config/Settings"
],
function (Parent, DomController, Settings) {
function MouseInput() {
Parent.call(this);
this.init();
}
MouseInput.prototype = Object.create(Parent.prototype);
MouseInput.prototype.init = function() {
var canvas = null;
var self = this;
canvas = DomController.getCanvas();
canvas.onmousemove = function(e){
// -1 +1 +1 +1 xy scaling should
// -1 -1 +1 -1 be like this
var x = (((e.clientX - this.offsetLeft) / Settings.STAGE_WIDTH) * 2) - 1;
var y = (((Settings.STAGE_HEIGHT - (e.clientY - this.offsetTop)) / Settings.STAGE_HEIGHT) * 2) -1;
self.onXyChange(x, y);
}
};
return MouseInput;
});

View file

@ -0,0 +1,22 @@
define([
"Game/Core/NotificationCenter"
],
function (NotificationCenter) {
function XyInput() {
this.x = null;
this.y = null
}
XyInput.prototype.onXyChange = function(x, y) {
this.x = x;
this.y = y;
NotificationCenter.trigger('onXyChange', x, y);
}
return XyInput;
});

View file

@ -1,16 +1,20 @@
define([
"Game/Core/Control/PlayerController",
"Game/Client/Control/KeyboardInput",
"Game/Client/Control/Input/MouseInput",
"Game/Core/NotificationCenter"
],
function (Parent, KeyboardInput, NotificationCenter) {
function (Parent, KeyboardInput, MouseInput, NotificationCenter) {
function PlayerController (me) {
Parent.call(this, me);
this.keyboardInput = new KeyboardInput(this);
this.xyInput = new MouseInput(this);
NotificationCenter.on("onXyChange", this.setXY, this);
var keys = {
w:87,
@ -21,7 +25,7 @@ function (Parent, KeyboardInput, NotificationCenter) {
up: 38,
left: 37,
down: 40,
right: 39
right: 39
}
this.init(keys);
@ -61,10 +65,17 @@ function (Parent, KeyboardInput, NotificationCenter) {
NotificationCenter.trigger('sendGameCommand', 'jump');
}
PlayerController.prototype.setXY = function(x, y) {
Parent.prototype.lookAt.call(this, x, y);
NotificationCenter.trigger('sendGameCommand', 'lookAt', x, y); // implement that x and y are received
};
PlayerController.prototype.update = function () {
this.keyboardInput.update();
Parent.prototype.update.call(this);
}
return PlayerController;
});