silphius/resources/hoe/start.js

72 lines
1.9 KiB
JavaScript
Raw Permalink Normal View History

2024-11-04 11:28:37 -06:00
import Ticker from '@/lib/ticker.js';
2024-06-25 10:44:37 -05:00
2024-10-17 23:35:34 -05:00
export default function*({ecs, wielder}) {
const {Direction, Position, Wielder} = wielder;
const projected = Wielder.activeItem()?.project(Position.tile, Direction.quantize(4))
if (projected?.length > 0) {
2024-06-25 10:44:37 -05:00
2024-10-17 23:35:34 -05:00
const {Controlled, Emitter, Sound, Sprite} = wielder
const {TileLayers} = ecs.get(1)
const layer = TileLayers.layer(0)
2024-06-26 09:17:35 -05:00
2024-10-17 23:35:34 -05:00
Controlled.locked = 1
const [, direction] = Sprite.animation.split(':')
for (let i = 0; i < 2; ++i) {
Sound.play('/resources/hoe/dig.wav');
for (const {x, y} of projected) {
Emitter.emit({
entity: {
Behaving: {
routines: {
initial: '/resources/hoe/dirt-particle.js',
},
2024-08-03 16:02:09 -05:00
},
2024-10-17 23:35:34 -05:00
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},
2024-08-03 16:02:09 -05:00
},
2024-10-17 23:35:34 -05:00
fields: [
{
path: ['Sprite', 'lightness'],
value: [0.05, 0.25],
},
{
path: ['Sprite', 'alpha'],
value: [0.5, 1],
},
{
path: ['Sprite', 'scale'],
value: [0.05, 0.1],
},
],
frequency: 0.05,
shape: {
type: 'filledRect',
payload: {width: 12, height: 12},
2024-08-01 00:39:54 -05:00
},
2024-10-17 23:35:34 -05:00
spurt: 5,
ttl: 0.4,
});
}
Sprite.animation = ['moving', direction].join(':');
yield Ticker.wait(0.3)
Sprite.animation = ['idle', direction].join(':');
yield Ticker.wait(0.1)
2024-06-26 09:17:35 -05:00
}
2024-06-25 10:44:37 -05:00
2024-10-17 23:35:34 -05:00
for (const position of projected) {
TileLayers.layer(1).stamp(position, [[7]])
}
2024-06-25 10:44:37 -05:00
2024-10-17 23:35:34 -05:00
Controlled.locked = 0;
2024-06-26 09:17:35 -05:00
2024-10-17 23:35:34 -05:00
}
2024-06-26 09:17:35 -05:00
}