function HumanController() { this.keyboard = null; this.player = null; this.mousePosition = {x: 0, y: 0}; this.init = function(player) { this.keyboard = new KeyboardInput(); this.keyboard.attach(); this.player = player; }; this.reset = function() { }; this.makeDecisions = function(player) { if(system.keyboard.isDown(Keys.Up) || system.keyboard.isDown(Keys.W)) { this.player.walkUp(); } if(system.keyboard.isDown(Keys.Down) || system.keyboard.isDown(Keys.S)) { this.player.walkDown(); } if(system.keyboard.isDown(Keys.Left)|| system.keyboard.isDown(Keys.A)) { this.player.walkLeft(); } if(system.keyboard.isDown(Keys.Right)|| system.keyboard.isDown(Keys.D)) { this.player.walkRight(); } if(system.keyboard.isPressed(Keys.Space)) { this.player.jump(); } }; this.mouseMove = function(camera, x, y) { this.mousePosition.x = x - camera.position.x; this.mousePosition.y = y - camera.position.y; this.player.targetAngle = system.angleTo(this.player.position, this.mousePosition); } this.mouseDown = function(camera, button, x, y) { this.mousePosition.x = x - camera.position.x; this.mousePosition.y = y - camera.position.y; this.player.targetAngle = system.angleTo(this.player.position, this.mousePosition); if(button == 2) { this.player.walkTowards(this.mousePosition); } } this.mouseUp = function(camera, button, x, y) { }; this.touchStart = function(camera, x, y) { this.mousePosition.x = x - camera.position.x; this.mousePosition.y = y - camera.position.y; this.player.targetAngle = system.angleTo(this.player.position, this.mousePosition); this.player.walkTowards(this.mousePosition); }; this.touchMove = function(camera, x, y) { this.mousePosition.x = x - camera.position.x; this.mousePosition.y = y - camera.position.y; this.player.targetAngle = system.angleTo(this.player.position, this.mousePosition); }; this.touchEnd = function(camera, x, y) { }; this.contextMenu = function() { }; this.debugDraw = function(context) { /* context.save(); context.translate(this.player.position.x, this.player.position.y); context.font = "16px sans-serif"; context.textAlign = "center"; context.textBaseline = "middle"; context.fillStyle = "#DDDDDD"; context.strokeStyle = "#333333"; context.lineWidth = 2; var message = parseInt(this.player.position.x) + ", " + parseInt(this.player.position.y); var textMetrics = context.measureText(message); var textWidth = textMetrics.width; context.fillText(message, 0, 0); context.restore(); */ /*context.strokeStyle = "crimson"; context.save(); context.translate(this.mousePosition.x, this.mousePosition.y); context.beginPath(); context.arc(0, 0, 10, 0, 2 * Math.PI); context.stroke(); context.restore(); */ }; };