silphius/resources/tomato-plant/interact.js

118 lines
2.3 KiB
JavaScript
Raw Normal View History

2024-07-04 09:10:49 -05:00
const {Interactive, Position, Plant, Sprite} = subject;
2024-07-01 18:12:53 -05:00
Interactive.interacting = false;
Plant.stage = 4;
Sprite.animation = ['stage', Plant.stage].join('/')
2024-07-02 10:28:48 -05:00
2024-07-04 09:10:49 -05:00
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},
],
},
],
2024-07-28 18:51:38 -05:00
collisionStartScript: [
'if (other.Inventory) {',
' other.Inventory.give({',
' qty: 1,',
2024-09-17 01:25:39 -05:00
" source: '/resources/tomato/tomato.json',",
2024-07-28 18:51:38 -05:00
' })',
' ecs.destroy(entity.id)',
'}',
].join('\n'),
2024-07-04 09:10:49 -05:00
},
Forces: {},
Magnetic: {},
Position: {x: Position.x, y: Position.y},
Sprite: {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 0.333,
scaleY: 0.333,
2024-09-17 01:25:39 -05:00
source: '/resources/tomato/tomato-sprite.json',
2024-07-04 09:10:49 -05:00
},
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,
},
},
)
2024-07-22 01:31:52 -05:00
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,
},
2024-07-04 09:10:49 -05:00
},
2024-07-22 01:31:52 -05:00
).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,
},
2024-07-04 09:10:49 -05:00
},
2024-07-22 01:31:52 -05:00
).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,
]),
2024-07-04 09:10:49 -05:00
);
}