Refine archive world spawn and interaction handling
All checks were successful
Build Org Website / build (push) Successful in 38s

This commit is contained in:
gitea-actions
2026-07-30 10:22:23 +01:00
parent 2f125f32ae
commit dc1ca5c00e
11 changed files with 112 additions and 33 deletions

View File

@@ -84,7 +84,7 @@
});
this.createAnimations();
this.npcSprites = [];
this.npcCollisions = this.physics.add.staticGroup();
const state = controller.getState();
const safe = Systems.nearestSafeSpawn(this.areaId,
state.position.area === this.areaId ? state.position.x : area.spawn.x,
@@ -100,6 +100,7 @@
this.interactables = [];
this.markers = [];
this.createWorldObjects();
this.physics.add.collider(this.player, this.npcCollisions);
this.createEnemies();
this.createInput();
@@ -164,11 +165,12 @@
if (!controller.reducedMotion()) this.tweens.add({ targets: marker, alpha: 0.45, scale: 1.14, yoyo: true, repeat: -1, duration: 1100 });
});
this.area.npcs.forEach(([id, x, y]) => {
const npc = this.add.sprite(x, y, "cast", Data.NPCS[id].frame).setScale(0.23).setDepth(y + 60);
const npc = this.npcCollisions.create(x, y, "cast", Data.NPCS[id].frame)
.setScale(0.23).setDepth(y + 60);
npc.refreshBody();
npc.body.setSize(82, 44).setOffset(115, 214);
npc.setData("interaction", { type: "npc", id, x, y });
this.npcSprites.push(npc);
this.interactables.push(npc.getData("interaction"));
if (!controller.reducedMotion()) this.tweens.add({ targets: npc, y: y - 2, duration: 1200 + Data.NPCS[id].frame * 30, yoyo: true, repeat: -1 });
});
this.addChest("town-garden", 205, 565, "memory_fragment", 2);
this.addChest("town-wall", 1235, 840, "ink_vial", 2);
@@ -215,6 +217,7 @@
createEnemies() {
this.enemies = this.physics.add.group();
this.physics.add.collider(this.enemies, this.collisions);
this.physics.add.collider(this.enemies, this.npcCollisions);
this.physics.add.collider(this.enemies, this.enemies);
this.area.enemies.forEach((entry) => {
const spawn = Array.isArray(entry)
@@ -289,7 +292,6 @@
if (!moving) this.stepDistance = 0;
}
this.player.setDepth(this.player.y + 60);
this.npcSprites.forEach((npc) => npc.setFlipX(this.player.x < npc.x));
this.updateEnemies(time, delta);
this.updateNearest();
this.handleKeys(time);
@@ -311,13 +313,7 @@
}
updateNearest() {
let nearest = null;
let best = Infinity;
this.interactables.forEach((item) => {
const distance = Phaser.Math.Distance.Between(this.player.x, this.player.y, item.x, item.y);
if (distance < best) { best = distance; nearest = item; }
});
this.nearest = best < 92 ? nearest : null;
this.nearest = Systems.nearestInteraction(this.interactables, this.player.x, this.player.y);
controller.setPrompt(this.nearest ? promptFor(this.nearest) : "");
}