12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
- 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";
- }
- };
|