import * as Ship from 'view/ship' import * as Colors from 'view/colors' import * as Vec2 from 'model/vec2' import * as Size from 'model/size' export interface State { canvas: HTMLCanvasElement, context: CanvasRenderingContext2D, timestamp: number, ship: Ship.State, windowSize: Size.Size, } export function init(): State { const canvas = document.querySelector('canvas') as HTMLCanvasElement const context = canvas.getContext("2d") as CanvasRenderingContext2D const windowSize = { width: window.innerWidth, height: window.innerHeight } canvas.width = windowSize.width canvas.height = windowSize.height return { canvas, context, timestamp: 0, ship: Ship.init(windowSize), windowSize } } export function update(state: State, timestamp: number) { const dt = timestamp - state.timestamp state.timestamp = timestamp Ship.update(state.ship, dt, state.windowSize) } export function resize(state: State, size: Size.Size) { Ship.project(state.ship, state.windowSize, size) state.windowSize = size state.canvas.width = size.width state.canvas.height = size.height } export function view(state: State) { // Clear state.context.fillStyle = Colors.colors.blue state.context.fillRect(0, 0, state.windowSize.width, state.windowSize.height) Ship.view(state.context, state.ship) }