import Component from '@/ecs/component.js'; export default class Controlled extends Component { instanceFromSchema() { return class ControlledInstance extends super.instanceFromSchema() { directionMove(direction) { const x = Math.cos(direction); if (x > 0) { this.moveLeft = 0; this.moveRight = x; } else { this.moveLeft = -x; this.moveRight = 0; } const y = Math.sin(direction); if (y > 0) { this.moveUp = 0; this.moveDown = y; } else { this.moveUp = -y; this.moveDown = 0; } } stop() { this.moveRight = 0; this.moveDown = 0; this.moveLeft = 0; this.moveUp = 0; } toJSON() { return {}; } } } static properties = { moveUp: {type: 'float32'}, moveRight: {type: 'float32'}, moveDown: {type: 'float32'}, moveLeft: {type: 'float32'}, }; }