fun: tomato harvest

This commit is contained in:
cha0s 2024-07-04 09:10:49 -05:00
parent 36be786348
commit 271b944796
3 changed files with 123 additions and 5 deletions

View File

@ -1,9 +1,119 @@
const {Interactive, Plant, Sprite} = subject;
const {Interactive, Position, Plant, Sprite} = subject;
Interactive.interacting = false;
Plant.stage = 4;
Sprite.animation = ['stage', Plant.stage].join('/')
initiator.Inventory.give({
qty: 1,
source: '/assets/tomato/tomato.json',
})
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: '/assets/tomato/collision-start.js',
},
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,
},
},
)
const l = lfo(
d.deltas.y,
{
delta: {
count: 1,
frequency: 0.5,
magnitude: 64,
median: 0,
offset: -0.5,
},
},
)
const ls = 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,
},
},
)
tomato.Ticking.addTickingPromise(
d.promise,
);
tomato.Ticking.addTickingPromise(
l.promise,
);
tomato.Ticking.addTickingPromise(
ls.promise,
);
tomato.Ticking.addTickingPromise(
delta(
tomato.Position,
{
x: {
duration: 0.5,
delta: (12 * x) + Math.random() * 8,
},
},
).promise,
);
tomato.Ticking.addTickingPromise(
delta(
tomato.Position,
{
y: {
duration: 0.5,
delta: (12 * y) + Math.random() * 8,
},
},
).promise,
);
}

View File

@ -0,0 +1,7 @@
if (other.Inventory) {
other.Inventory.give({
qty: 1,
source: '/assets/tomato/tomato.json',
})
ecs.destroy(entity.id)
}

View File

@ -0,0 +1 @@
{"frames":{"":{"frame":{"x":0,"y":0,"w":24,"h":24},"spriteSourceSize":{"x":0,"y":0,"w":24,"h":24},"sourceSize":{"w":24,"h":24}}},"meta":{"format":"RGBA8888","image":"./tomato.png","scale":1,"size":{"w":24,"h":24}}}