silphius/public/assets/watering-can/start.js
2024-07-30 09:56:53 -05:00

55 lines
1.3 KiB
JavaScript

const {Direction, Position, Wielder} = wielder
const projected = Wielder.activeItem()?.project(Position.tile, Direction.quantize(4))
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(':');
Sound.play('/assets/watering-can/water.wav');
for (const {x, y} of projected) {
Emitter.emit({
count: 25,
frequency: 0.01,
shape: {
type: 'filledRect',
payload: {width: 16, height: 16},
},
entity: {
Forces: {forceY: 100},
Position: {
x: x * layer.tileSize.x + (layer.tileSize.x / 2),
y: y * layer.tileSize.y - layer.tileSize.y,
},
Sprite: {
scaleX: 0.2,
scaleY: 0.2,
tint: 0x0022aa,
},
Ttl: {ttl: 0.25},
}
});
}
await wait(0.5);
for (const {x, y} of projected) {
const tileIndex = layer.area.x * y + x
let w;
if (Water.water[tileIndex]) {
w = Water.water[tileIndex]
}
else {
w = 0
}
Water.water[tileIndex] = Math.min(255, 64 + w);
}
Controlled.locked = 0;
}