feat: changeToRandomDirection
This commit is contained in:
parent
5ccdadee6a
commit
a702c0e108
|
@ -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) {
|
||||
|
|
Loading…
Reference in New Issue
Block a user