diff --git a/public/assets/tomato-plant/interact.js b/public/assets/tomato-plant/interact.js index d835947..9e1cf7a 100644 --- a/public/assets/tomato-plant/interact.js +++ b/public/assets/tomato-plant/interact.js @@ -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, + ); + +} + diff --git a/public/assets/tomato/collision-start.js b/public/assets/tomato/collision-start.js new file mode 100644 index 0000000..8d3b95c --- /dev/null +++ b/public/assets/tomato/collision-start.js @@ -0,0 +1,7 @@ +if (other.Inventory) { + other.Inventory.give({ + qty: 1, + source: '/assets/tomato/tomato.json', + }) + ecs.destroy(entity.id) +} diff --git a/public/assets/tomato/tomato-sprite.json b/public/assets/tomato/tomato-sprite.json new file mode 100644 index 0000000..8ff7c22 --- /dev/null +++ b/public/assets/tomato/tomato-sprite.json @@ -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}}} \ No newline at end of file