module.exports = class Movement { constructor() { } move(player, input) { switch(input.action) { case "move": this.handleMoveDirection(player, input); break; } core.sendUpdateToAll(player); return true; } handleMoveDirection(player, input) { switch(input.direction) { case "up": this.handleUp(player, input); break; case "down": this.handleDown(player, input); break; case "left": this.handleLeft(player, input); break; case "right": this.handleRight(player, input); break; } } handleUp(player, input) { if(input.hasOwnProperty("start")) { player.velocity.y = -1; } else { player.velocity.y = 0; } } handleDown(player, input) { if(input.hasOwnProperty("start")) { player.velocity.y = 1; } else { player.velocity.y = 0; } } handleLeft(player, input) { if(input.hasOwnProperty("start")) { player.velocity.x = -1; } else { player.velocity.x = 0; } } handleRight(player, input) { if(input.hasOwnProperty("start")) { player.sector.x = 1; } else { player.velocity.x = 0; } } target(player, input) { player.moveToTarget = true; player.targetDestination = input.position; var angle = Math.atan2(input.position.y - player.position.y, input.position.x - player.position.x); player.targetAngle = angle; if(input.position.x > player.position.x) { player.velocity.x = player.maxSpeed * Math.cos(angle); } if(input.position.x < player.position.x) { player.velocity.x = player.maxSpeed * Math.cos(angle); } if(input.position.y > player.position.y) { player.velocity.y = player.maxSpeed * Math.sin(angle); } if(input.position.y < player.position.y) { player.velocity.y = player.maxSpeed * Math.sin(angle); } core.sendUpdateToAll(player); return true; } getErrorMessage() { return "Error in Movement Command"; } };