aboutsummaryrefslogtreecommitdiff
path: root/client/src/components/GameCanvas.svelte
blob: ed16f33fbc37a5313b8501121b317f9e84fbc2f3 (plain) (blame)
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
<script lang="ts">
  import { onMount } from "svelte";
  import { loadAssets } from "@engine/config";
  import { Game } from "@engine/Game";
  import { JumpStorm } from "../JumpStorm";
  
  let canvas: HTMLCanvasElement;
  let ctx: CanvasRenderingContext2D;

  export let width: number;
  export let height: number;

  onMount(async () => {
    ctx = canvas.getContext("2d");
    ctx.imageSmoothingEnabled = false;

    await loadAssets();

    const game = new Game();
    const jumpStorm = new JumpStorm(game);

    const url = new URL(document.location);
    await jumpStorm.init(ctx, "http", "ws", url.host  + "/api");
    jumpStorm.play();
  });
</script>

<canvas bind:this={canvas} {width} {height} />