Browse Source
Signed-off-by: André Jaenisch <andre.jaenisch@posteo.de>combat-scorched-earth-from-outer-space
3 changed files with 121 additions and 0 deletions
@ -0,0 +1,61 @@
|
||||
import { RigidShape } from './shape.js' |
||||
import { Vec2 } from './vector.js' |
||||
|
||||
/** @typedef {import('./shape').Shape} Shape */ |
||||
|
||||
/** |
||||
* Creates player avatar. |
||||
* |
||||
* @returns {Shape} |
||||
*/ |
||||
export function makeAstronaut () { |
||||
const center = Vec2(200, 200) |
||||
const friction = 20 |
||||
const restitution = 0 |
||||
const mass = 400 |
||||
const bounds = 1 |
||||
const width = 20 |
||||
const height = 20 |
||||
|
||||
const shape = RigidShape({ |
||||
center, |
||||
mass, |
||||
friction, |
||||
restitution, |
||||
bounds, |
||||
width, |
||||
height |
||||
}) |
||||
|
||||
return shape |
||||
} |
||||
|
||||
/** |
||||
* Creates a boundary at the bottom of the screen. |
||||
* |
||||
* @param {object} config |
||||
* @param {number} config.x |
||||
* @param {number} config.y |
||||
* @param {number} config.height |
||||
* @param {number} config.width |
||||
* @returns {Shape} |
||||
*/ |
||||
export function makeBottomBoundary ({ x, y, height, width }) { |
||||
const center = Vec2(x + width / 2, y + height / 2) |
||||
const friction = 20 |
||||
const restitution = 0 |
||||
const mass = 0 |
||||
const bounds = 1 |
||||
|
||||
const shape = RigidShape({ |
||||
center, |
||||
mass, |
||||
friction, |
||||
restitution, |
||||
bounds, |
||||
width, |
||||
height |
||||
}) |
||||
|
||||
return shape |
||||
} |
@ -0,0 +1,36 @@
|
||||
import { expect } from 'chai' |
||||
|
||||
import { Vec2 } from '../../src/js/vector.js' |
||||
import { makeAstronaut, makeBottomBoundary } from '../../src/js/world.js' |
||||
|
||||
describe('World', function () { |
||||
describe('makeAstronaut', function () { |
||||
it('should make an astronaut shape', function () { |
||||
// Arrange
|
||||
/* nothing to do here */ |
||||
|
||||
// Act
|
||||
const astronaut = makeAstronaut() |
||||
|
||||
// Assert
|
||||
expect(astronaut).to.be.an('object') |
||||
}) |
||||
}) |
||||
|
||||
describe('makeBottomBoundary', function () { |
||||
it('should make an immobil shape', function () { |
||||
// Arrange
|
||||
const x = 0 |
||||
const y = 100 |
||||
const height = 1 |
||||
const width = 200 |
||||
|
||||
// Act
|
||||
const boundary = makeBottomBoundary({ x, y, height, width }) |
||||
|
||||
// Assert
|
||||
expect(boundary.X[0]).to.deep.equal(Vec2(x, y)) |
||||
expect(boundary.X[2]).to.deep.equal(Vec2(x + width, y + height)) |
||||
}) |
||||
}) |
||||
}) |
@ -0,0 +1,24 @@
|
||||
/** @typedef {import('./shape').Shape} Shape */ |
||||
/** |
||||
* Creates player avatar. |
||||
* |
||||
* @returns {Shape} |
||||
*/ |
||||
export function makeAstronaut(): Shape; |
||||
/** |
||||
* Creates a boundary at the bottom of the screen. |
||||
* |
||||
* @param {object} config |
||||
* @param {number} config.x |
||||
* @param {number} config.y |
||||
* @param {number} config.height |
||||
* @param {number} config.width |
||||
* @returns {Shape} |
||||
*/ |
||||
export function makeBottomBoundary({ x, y, height, width }: { |
||||
x: number; |
||||
y: number; |
||||
height: number; |
||||
width: number; |
||||
}): Shape; |
||||
export type Shape = import('./shape').Shape; |
Loading…
Reference in new issue