feat: changeToRandomDirection

This commit is contained in:
cha0s 2021-02-06 21:03:11 -06:00
parent 5ccdadee6a
commit a702c0e108

View File

@ -1,4 +1,4 @@
import {Vector} from '@avocado/math';
import {randomNumber, Vector} from '@avocado/math';
import {StateProperty, Trait} from '@avocado/traits';
import {compose} from '@latus/core';
@ -33,6 +33,11 @@ export default () => class Directional extends decorate(Trait) {
static describe() {
return {
changeToRandomDirection: {
type: 'void',
label: 'Change',
args: [],
},
direction: {
type: 'number',
label: 'Direction',
@ -71,6 +76,20 @@ export default () => class Directional extends decorate(Trait) {
return listeners;
}
methods() {
return {
changeToRandomDirection: () => {
let newDirection = super.direction;
while (newDirection === super.direction) {
newDirection = Math.floor(randomNumber(0, this.params.directionCount));
}
super.direction = newDirection;
},
};
}
packets() {
const {direction} = this.stateDifferences();
if (direction) {