96 lines
2.2 KiB
JavaScript
96 lines
2.2 KiB
JavaScript
import delta from '@/lib/delta.js';
|
|
import lfo from '@/lib/lfo.js';
|
|
import * as Math from '@/lib/math.js';
|
|
import Ticker from '@/lib/ticker.js';
|
|
|
|
export default function*({ecs, subject}) {
|
|
const {Interactive, Position, Plant, Sprite} = subject;
|
|
Interactive.interacting = false;
|
|
|
|
const specs = [];
|
|
const json = ecs.readJson('/resources/tomato/tomato.entity.json');
|
|
for (let i = 0; i < 10; ++i) {
|
|
specs.push({
|
|
...json,
|
|
Position: {x: Position.x, y: Position.y},
|
|
});
|
|
}
|
|
const tomatoes = Array.from(ecs.createMany(specs)).map((entityId) => ecs.get(entityId));
|
|
|
|
// const tickers = [];
|
|
for (const tomato of tomatoes) {
|
|
const {x, y} = Math.normalizeVector({
|
|
x: (Math.random() * 2) - 1,
|
|
y: (Math.random() * 2) - 1,
|
|
});
|
|
const d = delta(
|
|
tomato.Position,
|
|
{
|
|
y: {
|
|
duration: 0.5,
|
|
delta: 0,
|
|
},
|
|
},
|
|
)
|
|
tomato.Ticking.add(
|
|
Ticker.all([
|
|
d.ticker,
|
|
lfo(
|
|
d.deltas.y,
|
|
{
|
|
delta: {
|
|
count: 1,
|
|
frequency: 0.5,
|
|
magnitude: 64,
|
|
median: 0,
|
|
offset: -0.5,
|
|
},
|
|
},
|
|
).ticker,
|
|
lfo(
|
|
tomato.Sprite,
|
|
{
|
|
scaleX: {
|
|
count: 1,
|
|
frequency: 0.5,
|
|
magnitude: 0.333,
|
|
median: 0.333,
|
|
elapsed: 0.25,
|
|
offset: -0.5,
|
|
},
|
|
scaleY: {
|
|
count: 1,
|
|
frequency: 0.5,
|
|
magnitude: 0.333,
|
|
median: 0.333,
|
|
elapsed: 0.25,
|
|
offset: -0.5,
|
|
},
|
|
},
|
|
).ticker,
|
|
delta(
|
|
tomato.Position,
|
|
{
|
|
x: {
|
|
duration: 0.5,
|
|
delta: (12 * x) + Math.random() * 8,
|
|
},
|
|
},
|
|
).ticker,
|
|
delta(
|
|
tomato.Position,
|
|
{
|
|
y: {
|
|
duration: 0.5,
|
|
delta: (12 * y) + Math.random() * 8,
|
|
},
|
|
},
|
|
).ticker,
|
|
]),
|
|
);
|
|
}
|
|
|
|
Plant.stage = 4;
|
|
Sprite.animation = ['stage', Plant.stage].join('/')
|
|
|
|
} |