feat: spurt + ttl
This commit is contained in:
parent
623aabf525
commit
eaec1d0022
|
@ -56,9 +56,12 @@ export default class Emitter {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
let {count = 1} = particle;
|
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);
|
const specifications = Array(count);
|
||||||
for (let i = 0; i < count; ++i) {
|
for (let i = 0; i < count * spurt; ++i) {
|
||||||
specifications[i] = entity;
|
specifications[i] = entity;
|
||||||
}
|
}
|
||||||
const stream = K.stream(async (emitter) => {
|
const stream = K.stream(async (emitter) => {
|
||||||
|
@ -72,9 +75,14 @@ export default class Emitter {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const it = entityIds.values();
|
const it = entityIds.values();
|
||||||
const entityId = it.next().value;
|
const batch = new Set();
|
||||||
this.ecs.attach(new Set([entityId]));
|
for (let i = 0; i < spurt; ++i) {
|
||||||
emitter.emit(this.configure(entityId, particle));
|
batch.add(it.next().value);
|
||||||
|
}
|
||||||
|
this.ecs.attach(batch);
|
||||||
|
for (const entityId of batch) {
|
||||||
|
emitter.emit(this.configure(entityId, particle));
|
||||||
|
}
|
||||||
count -= 1;
|
count -= 1;
|
||||||
if (0 === count) {
|
if (0 === count) {
|
||||||
emitter.end();
|
emitter.end();
|
||||||
|
@ -84,9 +92,14 @@ export default class Emitter {
|
||||||
const scheduled = (elapsed) => {
|
const scheduled = (elapsed) => {
|
||||||
accumulated += elapsed;
|
accumulated += elapsed;
|
||||||
while (accumulated > frequency && count > 0) {
|
while (accumulated > frequency && count > 0) {
|
||||||
const entityId = it.next().value;
|
const batch = new Set();
|
||||||
this.ecs.attach(new Set([entityId]));
|
for (let i = 0; i < spurt; ++i) {
|
||||||
emitter.emit(this.configure(entityId, particle));
|
batch.add(it.next().value);
|
||||||
|
}
|
||||||
|
this.ecs.attach(batch);
|
||||||
|
for (const entityId of batch) {
|
||||||
|
emitter.emit(this.configure(entityId, particle));
|
||||||
|
}
|
||||||
accumulated -= frequency;
|
accumulated -= frequency;
|
||||||
count -= 1;
|
count -= 1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,7 +13,22 @@ if (projected?.length > 0) {
|
||||||
Sound.play('/assets/hoe/dig.wav');
|
Sound.play('/assets/hoe/dig.wav');
|
||||||
for (const {x, y} of projected) {
|
for (const {x, y} of projected) {
|
||||||
Emitter.emit({
|
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: [
|
fields: [
|
||||||
{
|
{
|
||||||
path: ['Sprite', 'lightness'],
|
path: ['Sprite', 'lightness'],
|
||||||
|
@ -28,29 +43,13 @@ if (projected?.length > 0) {
|
||||||
value: [0.05, 0.1],
|
value: [0.05, 0.1],
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
frequency: 0.006,
|
frequency: 0.05,
|
||||||
shape: {
|
shape: {
|
||||||
type: 'filledRect',
|
type: 'filledRect',
|
||||||
payload: {width: 12, height: 12},
|
payload: {width: 12, height: 12},
|
||||||
},
|
},
|
||||||
entity: {
|
spurt: 5,
|
||||||
Behaving: {
|
ttl: 0.4,
|
||||||
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},
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
Sprite.animation = ['moving', direction].join(':');
|
Sprite.animation = ['moving', direction].join(':');
|
||||||
|
|
|
@ -14,22 +14,6 @@ if (projected?.length > 0) {
|
||||||
|
|
||||||
for (const {x, y} of projected) {
|
for (const {x, y} of projected) {
|
||||||
Emitter.emit({
|
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: {
|
entity: {
|
||||||
Forces: {forceY: 100},
|
Forces: {forceY: 100},
|
||||||
Position: {
|
Position: {
|
||||||
|
@ -37,13 +21,24 @@ if (projected?.length > 0) {
|
||||||
y: y * layer.tileSize.y - (layer.tileSize.y / 4),
|
y: y * layer.tileSize.y - (layer.tileSize.y / 4),
|
||||||
},
|
},
|
||||||
Sprite: {
|
Sprite: {
|
||||||
alpha: 0,
|
|
||||||
scaleX: 0.05,
|
scaleX: 0.05,
|
||||||
scaleY: 0.15,
|
scaleY: 0.15,
|
||||||
tint: 0x0022aa,
|
tint: 0x0022aa,
|
||||||
},
|
},
|
||||||
Ttl: {ttl: 0.1},
|
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);
|
await wait(0.5);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user