diff --git a/resources/tomato-plant/interact.js b/resources/tomato-plant/interact.js index 9283211..334aa76 100644 --- a/resources/tomato-plant/interact.js +++ b/resources/tomato-plant/interact.js @@ -1,11 +1,11 @@ const {Interactive, Position, Plant, Sprite} = subject; Interactive.interacting = false; -Plant.stage = 4; -Sprite.animation = ['stage', Plant.stage].join('/') + +const promises = []; for (let i = 0; i < 10; ++i) { - const tomato = ecs.get(await ecs.create({ + promises.push(ecs.create({ Collider: { bodies: [ { @@ -42,6 +42,12 @@ for (let i = 0; i < 10; ++i) { VisibleAabb: {}, })); +} + +const ids = await Promise.all(promises); +for (const id of ids) { + const tomato = ecs.get(id); + const {x, y} = Math.normalizeVector({ x: (Math.random() * 2) - 1, y: (Math.random() * 2) - 1, @@ -113,6 +119,7 @@ for (let i = 0; i < 10; ++i) { ).promise, ]), ); - } +Plant.stage = 4; +Sprite.animation = ['stage', Plant.stage].join('/')