feat moveFor, for testing
This commit is contained in:
parent
7c72956ef8
commit
06c054f9f6
|
@ -1,4 +1,4 @@
|
||||||
import {compose} from '@avocado/core';
|
import {compose, TickingPromise} from '@avocado/core';
|
||||||
import {Vector} from '@avocado/math';
|
import {Vector} from '@avocado/math';
|
||||||
|
|
||||||
import {StateProperty, Trait} from '../trait';
|
import {StateProperty, Trait} from '../trait';
|
||||||
|
@ -24,6 +24,20 @@ class MobileBase extends Trait {
|
||||||
methods() {
|
methods() {
|
||||||
return {
|
return {
|
||||||
|
|
||||||
|
moveFor: (duration) => {
|
||||||
|
const direction = Math.floor(Math.random() * 4);
|
||||||
|
let resolve;
|
||||||
|
const promise = new TickingPromise(_resolve => resolve = _resolve);
|
||||||
|
promise.ticker = (elapsed) => {
|
||||||
|
duration -= elapsed;
|
||||||
|
if (duration <= 0) {
|
||||||
|
return resolve();
|
||||||
|
}
|
||||||
|
this.entity.requestMovement(Vector.fromDirection(direction));
|
||||||
|
}
|
||||||
|
return promise;
|
||||||
|
},
|
||||||
|
|
||||||
applyMovement: (movement) => {
|
applyMovement: (movement) => {
|
||||||
this.entity.x += movement[0];
|
this.entity.x += movement[0];
|
||||||
this.entity.y += movement[1];
|
this.entity.y += movement[1];
|
||||||
|
|
Loading…
Reference in New Issue
Block a user