1
0
Fork 0
Browse Source

refactor: call updateRotation from file

Signed-off-by: André Jaenisch <andre.jaenisch@posteo.de>
combat-scorched-earth-from-outer-space
André Jaenisch 10 months ago
parent
commit
33c53b32af
Signed by: ryuno-ki
GPG Key ID: 5A668E771F1ED854
  1. 30
      src/js/app.js
  2. 4
      test/js/position.test.js

30
src/js/app.js

@ -1,9 +1,8 @@
import { testCollision } from './collisions.js'
import { FPS } from './constants.js'
import { drawShape } from './draw.js'
import { updatePosition } from './position.js'
import { computeNormals } from './shape.js'
import { add, rotate, scale, Vec2 } from './vector.js'
import { updateRotation } from './rotation.js'
import { add, scale, Vec2 } from './vector.js'
import { makeAstronaut, makeBoundary, makeIceCream } from './world.js'
/** @typedef {import('./shape').Shape} Shape */
@ -183,31 +182,6 @@ function update (context, shape, g) {
updateRotation(shape)
}
/**
* Update the rotation of the shape.
*
* @param {Shape} shape
*/
function updateRotation (shape) {
shape.v = shape.v + shape.a * 1 / FPS
rotateShape(shape, shape.v * 1 / FPS)
}
/**
* Rotate a shape around its centre.
*
* @param {Shape} shape
* @param {number} angle
*/
function rotateShape (shape, angle) {
shape.G = shape.G + angle
shape.X.forEach(function (vertex, index) {
shape.X[index] = rotate(vertex, shape.C, angle)
computeNormals(shape)
})
}
/**
* Navigate to another scene.
*

4
test/js/position.test.js

@ -19,7 +19,9 @@ describe('Position', function () {
// Assert
expect(shape.C).not.to.equal(c)
expect(shape.V).not.to.equal(v)
shape.X.forEach((vertex, i) => expect(vertex).not.to.equal(x[i]))
shape.X.forEach(function (vertex, i) {
expect(vertex).not.to.equal(x[i])
})
})
})
})

Loading…
Cancel
Save