From eaec1d0022a0d020f142afdf57b6e97f9e8be1ba Mon Sep 17 00:00:00 2001 From: cha0s Date: Sat, 3 Aug 2024 16:02:09 -0500 Subject: [PATCH] feat: spurt + ttl --- app/particles/emitter.js | 29 +++++++++++++++------ public/assets/hoe/start.js | 39 ++++++++++++++--------------- public/assets/watering-can/start.js | 31 ++++++++++------------- 3 files changed, 53 insertions(+), 46 deletions(-) diff --git a/app/particles/emitter.js b/app/particles/emitter.js index 311b86b..c6c1756 100644 --- a/app/particles/emitter.js +++ b/app/particles/emitter.js @@ -56,9 +56,12 @@ export default class Emitter { }, } let {count = 1} = particle; - const {entity, frequency = 0} = particle; + const {entity, frequency = 0, spurt = 1, ttl = 0} = particle; + if (ttl > 0) { + count = Math.floor(ttl / frequency); + } const specifications = Array(count); - for (let i = 0; i < count; ++i) { + for (let i = 0; i < count * spurt; ++i) { specifications[i] = entity; } const stream = K.stream(async (emitter) => { @@ -72,9 +75,14 @@ export default class Emitter { return; } const it = entityIds.values(); - const entityId = it.next().value; - this.ecs.attach(new Set([entityId])); - emitter.emit(this.configure(entityId, particle)); + const batch = new Set(); + for (let i = 0; i < spurt; ++i) { + batch.add(it.next().value); + } + this.ecs.attach(batch); + for (const entityId of batch) { + emitter.emit(this.configure(entityId, particle)); + } count -= 1; if (0 === count) { emitter.end(); @@ -84,9 +92,14 @@ export default class Emitter { const scheduled = (elapsed) => { accumulated += elapsed; while (accumulated > frequency && count > 0) { - const entityId = it.next().value; - this.ecs.attach(new Set([entityId])); - emitter.emit(this.configure(entityId, particle)); + const batch = new Set(); + for (let i = 0; i < spurt; ++i) { + batch.add(it.next().value); + } + this.ecs.attach(batch); + for (const entityId of batch) { + emitter.emit(this.configure(entityId, particle)); + } accumulated -= frequency; count -= 1; } diff --git a/public/assets/hoe/start.js b/public/assets/hoe/start.js index 2ffccbd..258e22d 100644 --- a/public/assets/hoe/start.js +++ b/public/assets/hoe/start.js @@ -13,7 +13,22 @@ if (projected?.length > 0) { Sound.play('/assets/hoe/dig.wav'); for (const {x, y} of projected) { Emitter.emit({ - count: 30, + entity: { + Behaving: { + routines: { + initial: 'await delta(entity.Forces, {forceY: {delta: 640, duration: 0.125}}).promise', + }, + }, + Forces: {forceY: -80}, + Position: { + x: x * layer.tileSize.x + (layer.tileSize.x / 2), + y: y * layer.tileSize.y + (layer.tileSize.y / 2), + }, + Sprite: { + tint: 0x552200, + }, + Ttl: {ttl: 0.35}, + }, fields: [ { path: ['Sprite', 'lightness'], @@ -28,29 +43,13 @@ if (projected?.length > 0) { value: [0.05, 0.1], }, ], - frequency: 0.006, + frequency: 0.05, shape: { type: 'filledRect', payload: {width: 12, height: 12}, }, - entity: { - Behaving: { - routines: { - initial: 'await delta(entity.Forces, {forceY: {delta: 640, duration: 0.125}}).promise', - }, - }, - Forces: {forceY: -80}, - Position: { - x: x * layer.tileSize.x + (layer.tileSize.x / 2), - y: y * layer.tileSize.y + (layer.tileSize.y / 2), - }, - Sprite: { - scaleX: 0.05, - scaleY: 0.05, - tint: 0x552200, - }, - Ttl: {ttl: 0.35}, - } + spurt: 5, + ttl: 0.4, }); } Sprite.animation = ['moving', direction].join(':'); diff --git a/public/assets/watering-can/start.js b/public/assets/watering-can/start.js index 3a125c0..dba019c 100644 --- a/public/assets/watering-can/start.js +++ b/public/assets/watering-can/start.js @@ -14,22 +14,6 @@ if (projected?.length > 0) { for (const {x, y} of projected) { Emitter.emit({ - count: 30, - fields: [ - { - path: ['Sprite', 'alpha'], - value: [1, 1], - }, - { - path: ['Sprite', 'lightness'], - value: [0.111, 0.666], - }, - ], - frequency: 0.01875, - shape: { - type: 'circle', - payload: {radius: 4}, - }, entity: { Forces: {forceY: 100}, Position: { @@ -37,13 +21,24 @@ if (projected?.length > 0) { y: y * layer.tileSize.y - (layer.tileSize.y / 4), }, Sprite: { - alpha: 0, scaleX: 0.05, scaleY: 0.15, tint: 0x0022aa, }, Ttl: {ttl: 0.1}, - } + }, + fields: [ + { + path: ['Sprite', 'lightness'], + value: [0.111, 0.666], + }, + ], + frequency: 0.01, + shape: { + type: 'circle', + payload: {radius: 4}, + }, + ttl: 0.5, }); } await wait(0.5);