1
0
Fork 0
Browse Source

feat: create a rigid shape and draw it onto the screen

Signed-off-by: André Jaenisch <andre.jaenisch@posteo.de>
combat-scorched-earth-from-outer-space
André Jaenisch 10 months ago
parent
commit
8b240251d5
Signed by: ryuno-ki
GPG Key ID: 5A668E771F1ED854
  1. 42
      src/js/app.js
  2. 2
      types/app.d.ts

42
src/js/app.js

@ -1,3 +1,9 @@
import { drawShape } from './draw.js'
import { RigidShape } from './shape.js'
import { Vec2 } from './vector.js'
/** @typedef {import('./shape').Shape} Shape */
/**
* Entry point into the game.
*
@ -11,5 +17,39 @@ export function app () {
}
const context = /** @type {HTMLCanvasElement} */(game).getContext('2d')
console.log('Painting onto', context)
if (!context) {
console.error('Could not start game!')
return
}
const astronaut = makeAstronaut()
drawShape(context, astronaut)
}
/**
* 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
})
return shape
}

2
types/app.d.ts vendored

@ -1,6 +1,8 @@
/** @typedef {import('./shape').Shape} Shape */
/**
* Entry point into the game.
*
* @returns {void}
*/
export function app(): void;
export type Shape = import('./shape').Shape;

Loading…
Cancel
Save