silphius/public/assets/tomato-plant/interact.js
2024-07-26 02:20:12 -05:00

118 lines
2.3 KiB
JavaScript

const {Interactive, Position, Plant, Sprite} = subject;
Interactive.interacting = false;
Plant.stage = 4;
Sprite.animation = ['stage', Plant.stage].join('/')
for (let i = 0; i < 10; ++i) {
const tomato = ecs.get(await ecs.create({
Collider: {
bodies: [
{
points: [
{x: -4, y: -4},
{x: 3, y: -4},
{x: 3, y: 3},
{x: -4, y: 3},
],
},
],
collisionStartScript: `
if (other.Inventory) {
other.Inventory.give({
qty: 1,
source: '/assets/tomato/tomato.json',
})
ecs.destroy(entity.id)
}
`,
},
Forces: {},
Magnetic: {},
Position: {x: Position.x, y: Position.y},
Sprite: {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 0.333,
scaleY: 0.333,
source: '/assets/tomato/tomato-sprite.json',
},
Ticking: {},
VisibleAabb: {},
}));
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(
Promise.Ticker.all([
d.promise,
lfo(
d.deltas.y,
{
delta: {
count: 1,
frequency: 0.5,
magnitude: 64,
median: 0,
offset: -0.5,
},
},
).promise,
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,
},
},
).promise,
delta(
tomato.Position,
{
x: {
duration: 0.5,
delta: (12 * x) + Math.random() * 8,
},
},
).promise,
delta(
tomato.Position,
{
y: {
duration: 0.5,
delta: (12 * y) + Math.random() * 8,
},
},
).promise,
]),
);
}