23 lines
724 B
JavaScript
23 lines
724 B
JavaScript
import * as Math from '@/util/math.js';
|
|
import Ticker from '@/util/ticker.js';
|
|
|
|
const SPREAD = 0.5;
|
|
|
|
export default function*({ecs, entity}) {
|
|
const {Arbitrary, Controlled, Direction, id, Position, Speed, Sprite} = entity;
|
|
let accumulated = 0;
|
|
Controlled.directionMove(Direction.direction);
|
|
while (accumulated <= SPREAD) {
|
|
accumulated += yield Ticker.wait();
|
|
Speed.speed = 100 * (1 - (accumulated / SPREAD));
|
|
}
|
|
const {where: {x, y}} = Arbitrary.bag;
|
|
const toward = Math.atan2(y - Position.y, x - Position.x);
|
|
Direction.direction = (Math.TAU + toward) % Math.TAU;
|
|
Controlled.directionMove(Direction.direction);
|
|
Speed.speed = 400;
|
|
yield Ticker.wait(0.5);
|
|
Sprite.alpha = 0;
|
|
ecs.destroy(id);
|
|
}
|