const { game, updateObject, t } = ctx;
mapEvents = {
async init(e) {
// const objects = ctx.query.near(e.tile.position, 3);
// console.log("ooo", objects);
// objects.forEach(obj => {
// obj.position.z += 1;
// })
ctx.add({
position: {x: 10, y: 10, z: 20},
})
while (true) {
for await (pos of ctx.utils.drag(ctx)) {
ctx.raise({...pos});
// ctx.map.tile(pos.x, pos.y).setRoad(true);
}
ctx.endMapUpdate();
}
},
async pointerdown1(e) {
let down = true;
let last = e;
e.tile.setRoad(true);
ctx.once('pointerup').then(() => {
down = false;
});
while (down) {
const p1 = last.tile.position;
const p2 = e.tile.position;
for (const pos of ctx.utils.line(p1.x, p1.y, p2.x, p2.y)) {
ctx.map.tile(pos.x, pos.y).setRoad(true);
}
last = e;
e = await ctx.once('pointermove');
}
},
}
events = {
async click(e) {
e.target.material = {color: 0xff0000};
// e.target.position.x += 1;
// return;
const middle = ctx.query.byName('middle');
// middle.position.x = Math.random();
if (e.target) {
await ctx.animate(e.target, {
to: {position: {x: 0, y: 3, z: 0}},
duration: 300,
});
await ctx.animate(e.target, {
to: {position: {x: 10, y: 3, z: 0}},
duration: 300,
});
} else {
// TODO create new object
}
},
mousemove(e) {
return;
if (e.target) {
updateObject(e.target, obj => {
obj.position.y += 0.1;
});
}
}
}