silphius/resources/watering-can/start.js

63 lines
1.4 KiB
JavaScript
Raw Normal View History

2024-06-28 16:38:49 -05:00
const {Direction, Position, Wielder} = wielder
2024-07-24 09:28:35 -05:00
const projected = Wielder.activeItem()?.project(Position.tile, Direction.quantize(4))
2024-06-28 16:38:49 -05:00
if (projected?.length > 0) {
const {Controlled, Emitter, Sound, Sprite} = wielder
const {TileLayers, Water} = ecs.get(1)
const layer = TileLayers.layer(0)
Controlled.locked = 1
const [, direction] = Sprite.animation.split(':')
Sprite.animation = ['idle', direction].join(':');
2024-09-17 01:25:39 -05:00
Sound.play('/resources/watering-can/water.wav');
2024-07-30 09:56:53 -05:00
for (const {x, y} of projected) {
Emitter.emit({
entity: {
2024-08-01 15:44:54 -05:00
Forces: {forceY: 100},
2024-07-30 09:56:53 -05:00
Position: {
x: x * layer.tileSize.x + (layer.tileSize.x / 2),
2024-08-01 15:44:54 -05:00
y: y * layer.tileSize.y - (layer.tileSize.y / 4),
2024-07-30 09:56:53 -05:00
},
Sprite: {
2024-08-01 15:44:54 -05:00
scaleX: 0.05,
scaleY: 0.15,
2024-07-30 09:56:53 -05:00
tint: 0x0022aa,
},
2024-08-01 15:44:54 -05:00
Ttl: {ttl: 0.1},
2024-08-03 16:02:09 -05:00
},
fields: [
{
path: ['Sprite', 'lightness'],
value: [0.111, 0.666],
},
],
frequency: 0.01,
shape: {
type: 'circle',
payload: {radius: 4},
},
ttl: 0.5,
2024-07-30 09:56:53 -05:00
});
2024-06-28 16:38:49 -05:00
}
2024-07-30 09:56:53 -05:00
await wait(0.5);
2024-06-28 16:38:49 -05:00
2024-07-12 17:41:55 -05:00
for (const {x, y} of projected) {
const tileIndex = layer.area.x * y + x
2024-06-28 16:38:49 -05:00
let w;
if (Water.water[tileIndex]) {
w = Water.water[tileIndex]
}
else {
w = 0
}
Water.water[tileIndex] = Math.min(255, 64 + w);
}
2024-08-01 14:31:08 -05:00
ecs.system('Water').schedule();
2024-06-28 16:38:49 -05:00
Controlled.locked = 0;
}