mirror of
https://github.com/genxium/DelayNoMore
synced 2025-10-09 16:46:38 +00:00
Updated CLI unit tests.
This commit is contained in:
@@ -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>
|
||||
|
@@ -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);
|
||||
}
|
@@ -1,9 +0,0 @@
|
||||
{
|
||||
"ver": "1.0.5",
|
||||
"uuid": "fce86138-76fc-44d5-8eac-2731b3b0cefd",
|
||||
"isPlugin": false,
|
||||
"loadPluginInWeb": true,
|
||||
"loadPluginInNative": true,
|
||||
"loadPluginInEditor": false,
|
||||
"subMetas": {}
|
||||
}
|
39
frontend/collision_test_nodejs.js
Normal file
39
frontend/collision_test_nodejs.js
Normal file
@@ -0,0 +1,39 @@
|
||||
const collisions = require('./assets/scripts/modules/Collisions');
|
||||
|
||||
const collisionSys = new collisions.Collisions();
|
||||
|
||||
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(1269.665, 1353.335, [[0, 0], [64, 0], [64, 64], [0, 64]]);
|
||||
|
||||
const barrierCollider1 = collisionSys.createPolygon(1277.7159000000001, 1570.5575, [[642.5696, 319.159], [0, 319.15680000000003], [5.7286, 0], [643.7451, 0.9014999999999986]]);
|
||||
const barrierCollider2 = collisionSys.createPolygon(1289.039, 1318.0805, [[628.626, 54.254500000000064], [0, 56.03250000000003], [0.42449999999999477, 1.1229999999999905], [625.9715000000001, 0]]);
|
||||
const barrierCollider3 = collisionSys.createPolygon(1207, 1310, [[69, 581], [0, 579], [8, 3], [79, 0]]);
|
||||
|
||||
playerCollider.x += -2.98;
|
||||
playerCollider.y += -50.0;
|
||||
collisionSys.update();
|
||||
|
||||
const effPushback = [0.0, 0.0];
|
||||
|
||||
const result = collisionSys.createResult();
|
||||
|
||||
const potentials = playerCollider.potentials();
|
||||
|
||||
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(`Overlapped: a=${polygonStr(result.a)}, b=${polygonStr(result.b)}, pushbackX=${pushbackX}, pushbackY=${pushbackY}`);
|
||||
effPushback[0] += pushbackX;
|
||||
effPushback[1] += pushbackY;
|
||||
}
|
||||
|
||||
console.log(`effPushback=${effPushback}`);
|
Reference in New Issue
Block a user