feat: projection verification

This commit is contained in:
cha0s 2024-06-26 09:17:35 -05:00
parent 559d77c92c
commit b4c38d1ee0
2 changed files with 126 additions and 118 deletions

View File

@ -10,6 +10,7 @@ export default function(Component) {
return Inventory.item(Wielder.activeSlot + 1); return Inventory.item(Wielder.activeSlot + 1);
}; };
Instance.prototype.project = function(position, projection) { Instance.prototype.project = function(position, projection) {
const {TileLayers: {layers: [layer]}} = Component.ecs.get(1);
const {Direction: {direction}} = Component.ecs.get(this.entity); const {Direction: {direction}} = Component.ecs.get(this.entity);
let startX = position.x; let startX = position.x;
let startY = position.y; let startY = position.y;
@ -52,10 +53,12 @@ export default function(Component) {
axe = [row, -column]; axe = [row, -column];
break; break;
} }
projected.push({ const x = startX + parseInt(axe[0]);
x: startX + parseInt(axe[0]), const y = startY + parseInt(axe[1]);
y: startY + parseInt(axe[1]), if (x < 0 || y < 0 || x >= layer.area.x || y >= layer.area.y) {
}) continue;
}
projected.push({x, y});
} }
} }
} }

View File

@ -1,123 +1,128 @@
const {Controlled, Emitter, Position, Sound, Sprite, Wielder} = wielder const {Position, Wielder} = wielder
const {TileLayers} = ecs.get(1)
const layer = TileLayers.layer(0)
const projected = Wielder.project(Position.tile, item.tool.projection) const projected = Wielder.project(Position.tile, item.tool.projection)
if (projected.length > 0) {
Controlled.locked = 1; const {Controlled, Emitter, Sound, Sprite} = wielder
const [, direction] = Sprite.animation.split(':'); const {TileLayers} = ecs.get(1)
const layer = TileLayers.layer(0)
const dirtParticles = { Controlled.locked = 1
behaviors: [ const [, direction] = Sprite.animation.split(':')
{
type: 'moveAcceleration', const dirtParticles = {
config: { behaviors: [
accel: { {
x: 0, type: 'moveAcceleration',
y: 200, config: {
}, accel: {
minStart: 0, x: 0,
maxStart: 0, y: 200,
rotate: false, },
} minStart: 0,
}, maxStart: 0,
{ rotate: false,
type: 'moveSpeed',
config: {
speed: {
list: [
{
time: 0,
value: 60
},
{
time: 1,
value: 10
}
]
} }
} },
}, {
{ type: 'moveSpeed',
type: 'rotation', config: {
config: { speed: {
accel: 0, list: [
minSpeed: 0, {
maxSpeed: 0, time: 0,
minStart: 225, value: 60
maxStart: 320 },
} {
}, time: 1,
{ value: 10
type: 'scale', }
config: { ]
scale: {
list: [
{
value: 0.25,
time: 0,
},
{
value: 0.125,
time: 1,
},
]
}
}
},
{
type: 'textureSingle',
config: {
texture: 'tileset/7',
}
},
],
lifetime: {
min: 0.25,
max: 0.25,
},
frequency: 0.01,
emitterLifetime: 0.25,
pos: {
x: 0,
y: 0
},
};
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,
}
} }
} }
] },
}) {
} type: 'rotation',
Sprite.animation = ['moving', direction].join(':'); config: {
await wait(300) accel: 0,
Sprite.animation = ['idle', direction].join(':'); minSpeed: 0,
await wait(100) maxSpeed: 0,
} minStart: 225,
maxStart: 320
}
},
{
type: 'scale',
config: {
scale: {
list: [
{
value: 0.25,
time: 0,
},
{
value: 0.125,
time: 1,
},
]
}
}
},
{
type: 'textureSingle',
config: {
texture: 'tileset/7',
}
},
],
lifetime: {
min: 0.25,
max: 0.25,
},
frequency: 0.01,
emitterLifetime: 0.25,
pos: {
x: 0,
y: 0
},
};
for (let i = 0; i < projected.length; ++i) { for (let i = 0; i < 2; ++i) {
if ([1, 2, 3, 4].includes(layer.tile(projected[i]))) { Sound.play('/assets/hoe/dig.wav');
layer.stamp(projected[i], [[6]]) 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,
}
}
}
]
})
}
Sprite.animation = ['moving', direction].join(':');
await wait(300)
Sprite.animation = ['idle', direction].join(':');
await wait(100)
} }
else if ([6].includes(layer.tile(projected[i]))) {
layer.stamp(projected[i], [[7]])
}
}
Controlled.locked = 0; 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]])
}
}
Controlled.locked = 0;
}