1
0
Fork 0
Browse Source

refactor: import world object factories in app

Signed-off-by: André Jaenisch <andre.jaenisch@posteo.de>
combat-scorched-earth-from-outer-space
André Jaenisch 10 months ago
parent
commit
c0c6509428
Signed by: ryuno-ki
GPG Key ID: 5A668E771F1ED854
  1. BIN
      js13kgames.zip
  2. 39
      src/js/app.js

BIN
js13kgames.zip

Binary file not shown.

39
src/js/app.js

@ -1,12 +1,13 @@
import { drawShape } from './draw.js'
import { RigidShape } from './shape.js'
import { Vec2 } from './vector.js'
import { makeAstronaut, makeBottomBoundary } from './world.js'
/** @typedef {import('./shape').Shape} Shape */
// Global on purpose
/** @type {Shape} */
let astronaut
/** @type {Shape} */
let bottomBoundary
/** @type {HTMLCanvasElement} */
let canvas
/** @type {CanvasRenderingContext2D} */
@ -34,40 +35,22 @@ export function app () {
context = ctx
astronaut = makeAstronaut()
tick()
}
/**
* Creates player avatar.
*
* @returns {Shape}
*/
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
const boundaryHeight = 2
bottomBoundary = makeBottomBoundary({
x: 0,
y: canvas.height - boundaryHeight,
height: boundaryHeight,
width: canvas.width
})
return shape
tick()
}
/* TODO: Add some paint-FPS to UI */
// See https://developer.mozilla.org/en-US/docs/Web/API/window/requestAnimationFrame#notes
function tick () {
context.clearRect(0, 0, canvas.width, canvas.height)
drawShape(context, bottomBoundary)
drawShape(context, astronaut)
window.requestAnimationFrame(tick)
}

Loading…
Cancel
Save