blob: fe88c12b4c297f09b6960cd2c597fedf62fd238f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
import * as Ship from 'view/ship'
import * as Colors from 'view/colors'
import * as Screen from 'screen'
export interface State {
context: CanvasRenderingContext2D,
timestamp: number,
ship: Ship.State,
}
export function init(): State {
let canvas = document.querySelector('canvas') as HTMLCanvasElement
let context = canvas.getContext("2d") as CanvasRenderingContext2D
return {
context,
timestamp: 0,
ship: Ship.init(),
}
}
export function update(state: State, timestamp: number) {
let delta = timestamp - state.timestamp
state.timestamp = timestamp
Ship.update(state.ship, state.timestamp, delta)
}
export function view(state: State) {
// Clear
state.context.fillStyle = Colors.colors.blue
state.context.fillRect(0, 0, Screen.width, Screen.height)
Ship.view(state.context, state.ship)
}
|