1
0
Fork 0
Browse Source

feat: add first power-up

Signed-off-by: André Jaenisch <andre.jaenisch@posteo.de>
combat-scorched-earth-from-outer-space
André Jaenisch 10 months ago
parent
commit
7a283b8c42
Signed by: ryuno-ki
GPG Key ID: 5A668E771F1ED854
  1. 30
      src/js/world.js
  2. 20
      test/js/world.test.js
  3. 12
      types/world.d.ts

30
src/js/world.js

@ -59,3 +59,33 @@ export function makeBoundary ({ x, y, height, width }) {
return shape
}
/**
* Creates power-up.
*
* @param {object} config
* @param {number} config.x
* @param {number} config.y
* @returns {Shape}
*/
export function makeIceCream ({ x, y }) {
const width = 20
const height = 20
const center = Vec2(x + width / 2, y + height / 2)
const friction = 20
const restitution = 0
const mass = 400
const bounds = 20
const shape = RigidShape({
center,
mass,
friction,
restitution,
bounds,
width,
height
})
return shape
}

20
test/js/world.test.js

@ -1,7 +1,11 @@
import { expect } from 'chai'
import { Vec2 } from '../../src/js/vector.js'
import { makeAstronaut, makeBoundary } from '../../src/js/world.js'
import {
makeAstronaut,
makeIceCream,
makeBoundary
} from '../../src/js/world.js'
describe('World', function () {
describe('makeAstronaut', function () {
@ -33,4 +37,18 @@ describe('World', function () {
expect(boundary.X[2]).to.deep.equal(Vec2(x + width, y + height))
})
})
describe('makeIceCream', function () {
it('should make an power-up shape', function () {
// Arrange
const x = 50
const y = 100
// Act
const iceCream = makeIceCream({ x, y })
// Assert
expect(iceCream).to.be.an('object')
})
})
})

12
types/world.d.ts vendored

@ -21,4 +21,16 @@ export function makeBoundary({ x, y, height, width }: {
height: number;
width: number;
}): Shape;
/**
* Creates power-up.
*
* @param {object} config
* @param {number} config.x
* @param {number} config.y
* @returns {Shape}
*/
export function makeIceCream({ x, y }: {
x: number;
y: number;
}): Shape;
export type Shape = import('./shape').Shape;

Loading…
Cancel
Save