aboutsummaryrefslogtreecommitdiff
path: root/src/view/scene.ts
diff options
context:
space:
mode:
authorJoris2021-02-14 20:25:55 +0100
committerJoris2021-02-14 20:25:55 +0100
commitf47b2e3f68e69238b731d6183e739805db20ae5b (patch)
tree2eaa3937cdec3dccf4e751f9b519833740e69aca /src/view/scene.ts
parent0b60fd8c2cf5746a45cea137d2eac918ca7a8307 (diff)
Control a ship that can fire missiles
Diffstat (limited to 'src/view/scene.ts')
-rw-r--r--src/view/scene.ts35
1 files changed, 35 insertions, 0 deletions
diff --git a/src/view/scene.ts b/src/view/scene.ts
new file mode 100644
index 0000000..fe88c12
--- /dev/null
+++ b/src/view/scene.ts
@@ -0,0 +1,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)
+}