Sfoglia il codice sorgente

cleaned up the hider check as it was not working perfectly

tags/v0.11.0
Shaun 2 anni fa
parent
commit
0343543a58
2 ha cambiato i file con 38 aggiunte e 41 eliminazioni
  1. +16
    -0
      src/client/js/misc/physics.js
  2. +22
    -41
      src/client/js/rendering/renderer.js

+ 16
- 0
src/client/js/misc/physics.js Vedi File

@@ -76,6 +76,22 @@ define([
return inside;
},

//Helper function to check if a point is inside an area
// This function is optimized to check if the point is outside the rect first
// and if it is not, we do the more expensive isInPolygon check
isInArea: function (x, y, { x: ax, y: ay, width, height, area }) {
//Outside rect
if (
x < ax ||
x >= ax + width ||
y < ay ||
y >= ay + height
)
return false;

return this.isInPolygon(x, y, area);
},

distanceToPolygon: function (p, verts) {
return distanceToPolygon.calculate(p, verts);
}


+ 22
- 41
src/client/js/rendering/renderer.js Vedi File

@@ -389,64 +389,45 @@ define([
let foundVisibleLayer = null;
let foundHiddenLayer = null;

const fnTileInArea = physics.isInArea.bind(physics, x, y);
const fnPlayerInArea = physics.isInArea.bind(physics, px, py);

hiddenRooms.forEach(h => {
const { discovered, layer, interior } = h;
const { x: hx, y: hy, width, height, area } = h;

//Is the tile outside the hider
if (
x < hx ||
x >= hx + width ||
y < hy ||
y >= hy + height
) {
//If the hider is an interior, the tile should be hidden if the player is inside the hider
if (interior) {
if (physics.isInPolygon(px, py, area))
foundHiddenLayer = layer;
}

return;
}
if (interior) {
if (!physics.isInPolygon(x, y, area))
foundHiddenLayer = layer;
}
const playerInHider = fnPlayerInArea(h);
const tileInHider = fnTileInArea(h);

//Is the tile inside the hider
if (!physics.isInPolygon(x, y, area))
return;
if (playerInHider) {
if (interior && !tileInHider) {
foundHiddenLayer = layer;

if (discovered) {
foundVisibleLayer = layer;
return;
}
} else if (tileInHider && !discovered) {
foundHiddenLayer = layer;

return;
}

//Is the player outside the hider
if (
px < hx ||
px >= hx + width ||
py < hy ||
py >= hy + height
) {
foundHiddenLayer = layer;
} else if (discovered) {
foundVisibleLayer = layer;

return;
}

//Is the player inside the hider
if (!physics.isInPolygon(px, py, area)) {
foundHiddenLayer = layer;

if (!tileInHider)
return;
}

foundVisibleLayer = layer;
});

//We compare hider layers to cater for hiders inside hiders
return (foundHiddenLayer > foundVisibleLayer) || (foundHiddenLayer === 0 && foundVisibleLayer === null);
return (
foundHiddenLayer > foundVisibleLayer ||
(
foundHiddenLayer === 0 &&
foundVisibleLayer === null
)
);
},

updateSprites: function () {


Caricamento…
Annulla
Salva