squishjs 0.7.60 → 0.7.61

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 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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "squishjs",
3
- "version": "0.7.60",
3
+ "version": "0.7.61",
4
4
  "description": "squish & unsquish stuff",
5
5
  "scripts": {
6
6
  "test": "node testRunner.js"
package/src/physics.js ADDED
@@ -0,0 +1,24 @@
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
+ withinEdges = false;
14
+ } else {
15
+ path.push([newX, newY]);
16
+ }
17
+ }
18
+
19
+ return path;
20
+ }
21
+ };
22
+
23
+ module.exports = Physics;
24
+