squishjs 0.7.56 → 0.7.62
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +3 -1
- package/package.json +1 -1
- package/src/Asset.js +1 -2
- package/src/physics.js +42 -0
package/index.js
CHANGED
|
@@ -12,6 +12,7 @@ const subtypes = require('./src/subtypes');
|
|
|
12
12
|
const Squisher = require('./src/Squisher');
|
|
13
13
|
const Asset = require('./src/Asset');
|
|
14
14
|
const GeometryUtils = require('./src/util/geometry');
|
|
15
|
+
const Physics = require('./src/physics');
|
|
15
16
|
|
|
16
17
|
module.exports = {
|
|
17
18
|
squish,
|
|
@@ -28,5 +29,6 @@ module.exports = {
|
|
|
28
29
|
ViewUtils: viewUtils,
|
|
29
30
|
TerrainGenerator: terrainGenerator,
|
|
30
31
|
GeometryUtils,
|
|
31
|
-
Asset
|
|
32
|
+
Asset,
|
|
33
|
+
Physics
|
|
32
34
|
};
|
package/package.json
CHANGED
package/src/Asset.js
CHANGED
package/src/physics.js
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
const Physics = {
|
|
2
|
+
getPath: (startX, startY, xVel, yVel, endX = 100, endY = 100) => {
|
|
3
|
+
const path = [];
|
|
4
|
+
let withinEdges = true;
|
|
5
|
+
while (withinEdges) {
|
|
6
|
+
const curX = path.length === 0 ? startX : path[path.length - 1][0];
|
|
7
|
+
const curY = path.length === 0 ? startY : path[path.length - 1][1];
|
|
8
|
+
|
|
9
|
+
const newX = curX + xVel;
|
|
10
|
+
const newY = curY + yVel;
|
|
11
|
+
|
|
12
|
+
if (newX < 0 || newX > endX || newY < 0 || newY > endY) {
|
|
13
|
+
let _newX = newX;
|
|
14
|
+
let _newY = newY;
|
|
15
|
+
if (newX < 0) {
|
|
16
|
+
_newX = 0;
|
|
17
|
+
} else if (newX > endX) {
|
|
18
|
+
_newX = endX;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
if (newY < 0) {
|
|
22
|
+
_newY = 0;
|
|
23
|
+
} else if (newY > endY) {
|
|
24
|
+
_newY = endY;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
if (!(path[path.length - 1][0] === _newX || path[path.length - 1][1] === _newY)) {
|
|
28
|
+
path.push([_newX, _newY]);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
withinEdges = false;
|
|
32
|
+
} else {
|
|
33
|
+
path.push([newX, newY]);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
return path;
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
module.exports = Physics;
|
|
42
|
+
|