refactor: simple

This commit is contained in:
cha0s 2024-10-19 11:55:27 -05:00
parent 29471d8b5d
commit 26b3f5049c

View File

@ -1,31 +1,20 @@
import * as Math from '@/util/math.js';
import Ticker from '@/util/ticker.js';
const SHOTS = 5;
const SHOTS = 10;
function createShots(ecs, where, wielder) {
const offset = Math.random() * Math.TAU;
export default function*({ecs, where, wielder}) {
const {Player, Position} = wielder;
const json = ecs.readJson('/resources/magic-swords/shot.entity.json');
const shots = [];
for (let i = 0; i < SHOTS; ++i) {
shots.push({
...json,
Arbitrary: {
blob: JSON.stringify({where}),
},
Direction: {direction: offset + Math.TAU * (i / SHOTS)},
const offset = Math.random() * Math.TAU;
let count = SHOTS;
while (count--) {
ecs.create({
...ecs.readJson('/resources/magic-swords/shot.entity.json'),
Arbitrary: {blob: JSON.stringify({where})},
Direction: {direction: offset + Math.TAU * (count / SHOTS)},
Owned: {owner: Player ? Player.id : 0},
Position: {x: Position.x, y: Position.y},
});
}
return shots;
}
export default function*({ecs, where, wielder}) {
const shots = createShots(ecs, where, wielder);
do {
ecs.create(shots.shift());
yield Ticker.wait(0.03);
} while (shots.length > 0);
}
}