feat: spurt + ttl
This commit is contained in:
parent
623aabf525
commit
eaec1d0022
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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(':');
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue
Block a user