silphius/public/assets/hoe/start.js

129 lines
2.6 KiB
JavaScript
Raw Normal View History

2024-06-26 09:17:35 -05:00
const {Position, Wielder} = wielder
2024-06-25 10:44:37 -05:00
const projected = Wielder.project(Position.tile, item.tool.projection)
2024-06-26 09:17:35 -05:00
if (projected.length > 0) {
2024-06-25 10:44:37 -05:00
2024-06-26 09:17:35 -05:00
const {Controlled, Emitter, Sound, Sprite} = wielder
const {TileLayers} = ecs.get(1)
const layer = TileLayers.layer(0)
2024-06-25 10:44:37 -05:00
2024-06-26 09:17:35 -05:00
Controlled.locked = 1
const [, direction] = Sprite.animation.split(':')
const dirtParticles = {
behaviors: [
{
type: 'moveAcceleration',
config: {
accel: {
x: 0,
y: 200,
},
minStart: 0,
maxStart: 0,
rotate: false,
2024-06-26 04:18:54 -05:00
}
2024-06-26 09:17:35 -05:00
},
{
type: 'moveSpeed',
config: {
speed: {
list: [
{
time: 0,
value: 60
},
{
time: 1,
value: 10
}
]
}
}
},
{
type: 'rotation',
config: {
accel: 0,
minSpeed: 0,
maxSpeed: 0,
minStart: 225,
maxStart: 320
}
},
{
type: 'scale',
config: {
scale: {
list: [
{
value: 0.25,
time: 0,
},
{
value: 0.125,
time: 1,
},
]
}
2024-06-26 04:18:54 -05:00
}
2024-06-26 09:17:35 -05:00
},
{
type: 'textureSingle',
config: {
texture: 'tileset/7',
}
},
],
lifetime: {
min: 0.25,
max: 0.25,
2024-06-26 04:18:54 -05:00
},
2024-06-26 09:17:35 -05:00
frequency: 0.01,
emitterLifetime: 0.25,
pos: {
x: 0,
y: 0
2024-06-26 04:18:54 -05:00
},
2024-06-26 09:17:35 -05:00
};
2024-06-26 04:18:54 -05:00
2024-06-26 09:17:35 -05:00
for (let i = 0; i < 2; ++i) {
Sound.play('/assets/hoe/dig.wav');
for (let i = 0; i < projected.length; ++i) {
Emitter.emit({
...dirtParticles,
behaviors: [
...dirtParticles.behaviors,
{
type: 'spawnShape',
config: {
type: 'rect',
data: {
x: projected[i].x * layer.tileSize.x,
y: projected[i].y * layer.tileSize.y,
w: layer.tileSize.x,
h: layer.tileSize.y,
}
2024-06-26 04:18:54 -05:00
}
}
2024-06-26 09:17:35 -05:00
]
})
}
Sprite.animation = ['moving', direction].join(':');
await wait(300)
Sprite.animation = ['idle', direction].join(':');
await wait(100)
2024-06-26 04:18:54 -05:00
}
2024-06-25 10:44:37 -05:00
2024-06-26 09:17:35 -05:00
for (let i = 0; i < projected.length; ++i) {
if ([1, 2, 3, 4].includes(layer.tile(projected[i]))) {
layer.stamp(projected[i], [[6]])
}
else if ([6].includes(layer.tile(projected[i]))) {
layer.stamp(projected[i], [[7]])
}
2024-06-25 10:44:37 -05:00
}
2024-06-26 09:17:35 -05:00
Controlled.locked = 0;
}