Updated CLI unit tests.

This commit is contained in:
genxium
2022-11-12 11:20:16 +08:00
parent 98daeff408
commit 41967b11f7
5 changed files with 71 additions and 68 deletions

View File

@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<map version="1.2" tiledversion="1.2.3" orientation="isometric" renderorder="right-down" width="50" height="50" tilewidth="64" tileheight="64" infinite="0" nextlayerid="11" nextobjectid="214">
<map version="1.2" tiledversion="1.2.3" orientation="isometric" renderorder="right-down" width="50" height="50" tilewidth="64" tileheight="64" infinite="0" nextlayerid="11" nextobjectid="215">
<tileset firstgid="1" source="Tile_W64_H64_S01.tsx"/>
<tileset firstgid="17" source="Tile_W300_H300_S01.tsx"/>
<layer id="1" name="GroundFloor" width="50" height="50" locked="1">
@@ -8,7 +8,7 @@
</data>
</layer>
<objectgroup id="2" name="PlayerStartingPos">
<object id="135" x="1442.33" y="2063">
<object id="135" x="1516.33" y="2113">
<point/>
</object>
<object id="137" x="2270" y="1640">
@@ -36,5 +36,11 @@
</properties>
<polyline points="1101.33,-342 470.926,284.848 526.26,339.333 1152.93,-285.091"/>
</object>
<object id="214" x="988" y="1632">
<properties>
<property name="boundary_type" value="barrier"/>
</properties>
<polyline points="-3,1 -70,72 514,640 588,572"/>
</object>
</objectgroup>
</map>

View File

@@ -1,39 +0,0 @@
const collisions = require('./modules/Collisions');
const collisionSys = new collisions.Collisions();
/*
Backend result reference
2022-10-22T12:11:25.156+0800 INFO collider_visualizer/worldColliderDisplay.go:77 Collided: player.X=1257.665, player.Y=1415.335, oldDx=-2.98, oldDy=-50, playerShape=&{[[0 0] [64 0] [64 64] [0 64]] 1254.685 1365.335 true}, toCheckBarrier=&{[[628.626 54.254500000000064] [0 56.03250000000003] [0.42449999999999477 1.1229999999999905] [625.9715000000001 0]] 1289.039 1318.0805 true}, pushbackX=-0.15848054013127655, pushbackY=-56.03205175509715, result=&{56.03227587710039 -0.0028283794946841584 -0.9999960001267175 false false [0.9988052279193613 -0.04886836073527201]}
*/
function polygonStr(body) {
let coords = [];
let cnt = body._coords.length;
for (let ix = 0, iy = 1; ix < cnt; ix += 2, iy += 2) {
coords.push([body._coords[ix], body._coords[iy]]);
}
return JSON.stringify(coords);
}
const playerCollider = collisionSys.createPolygon(1257.665, 1415.335, [[0, 0], [64, 0], [64, 64], [0, 64]]);
const barrierCollider = collisionSys.createPolygon(1289.039, 1318.0805, [[628.626, 54.254500000000064], [0, 56.03250000000003], [0.42449999999999477, 1.1229999999999905], [625.9715000000001, 0]]);
const oldDx = -2.98;
const oldDy = -50.0;
playerCollider.x += oldDx;
playerCollider.y += oldDy;
collisionSys.update();
const result = collisionSys.createResult();
const potentials = playerCollider.potentials();
let overlapCheckId = 0;
for (const barrier of potentials) {
if (!playerCollider.collides(barrier, result)) continue;
const pushbackX = result.overlap * result.overlap_x;
const pushbackY = result.overlap * result.overlap_y;
console.log("For overlapCheckId=" + overlapCheckId + ", the overlap: a=", polygonStr(result.a), ", b=", polygonStr(result.b), ", pushbackX=", pushbackX, ", pushbackY=", pushbackY);
}

View File

@@ -1,9 +0,0 @@
{
"ver": "1.0.5",
"uuid": "fce86138-76fc-44d5-8eac-2731b3b0cefd",
"isPlugin": false,
"loadPluginInWeb": true,
"loadPluginInNative": true,
"loadPluginInEditor": false,
"subMetas": {}
}