refactor: action

This commit is contained in:
cha0s 2024-08-01 15:44:54 -05:00
parent b467874608
commit c4f2c4e7d4
4 changed files with 38 additions and 23 deletions

View File

@ -5,6 +5,12 @@ export default class Ttl extends Component {
const {ecs} = this;
return class TtlInstance extends super.instanceFromSchema() {
$$elapsed = 0;
get elapsed() {
return this.$$elapsed;
}
set elapsed(elapsed) {
this.$$elapsed = elapsed;
}
$$reset() {
this.$$elapsed = 0;
}

View File

@ -13,7 +13,7 @@ if (projected?.length > 0) {
Sound.play('/assets/hoe/dig.wav');
for (const {x, y} of projected) {
Emitter.emit({
count: 75,
count: 30,
fields: [
{
path: ['Sprite', 'lightness'],
@ -21,34 +21,35 @@ if (projected?.length > 0) {
},
{
path: ['Sprite', 'alpha'],
value: [0.3, 1],
value: [0.5, 1],
},
{
path: ['Sprite', 'scaleX'],
value: [0.05, 0.3],
},
{
path: ['Sprite', 'scaleY'],
value: [0.05, 0.3],
path: ['Sprite', 'scale'],
value: [0.05, 0.1],
},
],
frequency: 0.004,
frequency: 0.006,
shape: {
type: 'filledRect',
payload: {width: 16, height: 16},
payload: {width: 12, height: 12},
},
entity: {
Forces: {forceY: -40},
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.2,
scaleY: 0.2,
scaleX: 0.05,
scaleY: 0.05,
tint: 0x552200,
},
Ttl: {ttl: 0.125},
Ttl: {ttl: 0.35},
}
});
}

View File

@ -38,6 +38,7 @@ for (let i = 0; i < N; ++i) {
source: '/assets/magic-swords/magic-sword-shot.json',
},
Ticking: {},
Ttl: {ttl: 1.5},
VisibleAabb: {},
}));
}
@ -57,6 +58,7 @@ while (shots.length > 0) {
spawner += elapsed;
if (creating.length > 0 && spawner >= EVERY) {
const shot = creating.shift();
shot.Ttl.elapsed = 0;
shot.Sprite.alpha = 1;
accumulated[shot.id] = 0;
shots.push(shot)
@ -77,6 +79,7 @@ while (shots.length > 0) {
shot.Direction.direction = (Math.TAU + toward) % Math.TAU;
if (Math.distance(where, shot.Position) < 4) {
delete accumulated[shot.id];
shot.Ttl.elapsed = 0;
shot.Sprite.alpha = 0;
ecs.destroy(shot.id);
destroying.push(shot);

View File

@ -14,30 +14,35 @@ if (projected?.length > 0) {
for (const {x, y} of projected) {
Emitter.emit({
count: 100,
count: 30,
fields: [
{
path: ['Sprite', 'alpha'],
value: [1, 1],
},
{
path: ['Sprite', 'lightness'],
value: [0.111, 0.666],
},
],
frequency: 0.005,
frequency: 0.01875,
shape: {
type: 'filledRect',
payload: {width: 16, height: 16},
type: 'circle',
payload: {radius: 4},
},
entity: {
Forces: {forceY: 400},
Forces: {forceY: 100},
Position: {
x: x * layer.tileSize.x + (layer.tileSize.x / 2),
y: y * layer.tileSize.y - layer.tileSize.y,
y: y * layer.tileSize.y - (layer.tileSize.y / 4),
},
Sprite: {
scaleX: 0.1,
scaleY: 0.3,
alpha: 0,
scaleX: 0.05,
scaleY: 0.15,
tint: 0x0022aa,
},
Ttl: {ttl: 0.0625},
Ttl: {ttl: 0.1},
}
});
}