silphius/app/ecs/components/controlled.js

44 lines
1004 B
JavaScript
Raw Normal View History

2024-06-26 21:08:09 -05:00
import Component from '@/ecs/component.js';
export default class Controlled extends Component {
2024-06-29 06:38:19 -05:00
instanceFromSchema() {
return class ControlledInstance extends super.instanceFromSchema() {
2024-07-24 09:28:35 -05:00
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;
}
2024-06-29 06:38:19 -05:00
toJSON() {
return {};
}
}
}
2024-06-26 21:08:09 -05:00
static properties = {
moveUp: {type: 'float32'},
moveRight: {type: 'float32'},
moveDown: {type: 'float32'},
moveLeft: {type: 'float32'},
};
}