aboutsummaryrefslogtreecommitdiff
path: root/src/view/scene.ts
diff options
context:
space:
mode:
authorJoris2022-07-05 22:11:00 +0200
committerJoris2022-07-05 22:11:00 +0200
commit8c1ab4c5756ac43d52bc8773f5e72dde90f79e77 (patch)
treede0db8c859e4204c90ddaa762f4d743fab1dedb2 /src/view/scene.ts
parent1d855b7a50b61650f7ddf40f604c788de1c9e914 (diff)
WIP
Diffstat (limited to 'src/view/scene.ts')
-rw-r--r--src/view/scene.ts32
1 files changed, 25 insertions, 7 deletions
diff --git a/src/view/scene.ts b/src/view/scene.ts
index fe88c12..6d35edc 100644
--- a/src/view/scene.ts
+++ b/src/view/scene.ts
@@ -1,35 +1,53 @@
import * as Ship from 'view/ship'
import * as Colors from 'view/colors'
-import * as Screen from 'screen'
+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 {
- let canvas = document.querySelector('canvas') as HTMLCanvasElement
- let context = canvas.getContext("2d") as CanvasRenderingContext2D
+ 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(),
+ ship: Ship.init(windowSize),
+ windowSize
}
}
export function update(state: State, timestamp: number) {
- let delta = timestamp - state.timestamp
+ const dt = timestamp - state.timestamp
state.timestamp = timestamp
- Ship.update(state.ship, state.timestamp, delta)
+ 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, Screen.width, Screen.height)
+ state.context.fillRect(0, 0, state.windowSize.width, state.windowSize.height)
Ship.view(state.context, state.ship)
}