summaryrefslogtreecommitdiff
path: root/2026/games_submissions/asrael_io/source/index.html
blob: 5002f2740d2d3de4098eb86cd25f6450dc9072ed (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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<!doctype html>
<html>
    <head>
        <link data-trunk rel="scss" href="index.scss" />
        <link data-trunk rel="rust" />
        <script>
            window.jamStart = false;
            window.jamDifficulty = 0;
            window.jamShouldStart = () =>
                window.jamStart || Boolean(window.lcolonqJamStart);
            window.jamGetDifficulty = () => {
                if (window.jamDifficulty) return window.jamDifficulty;
                if (typeof window.lcolonqJamStart === "number") return window.lcolonqJamStart;
                return 0;
            };
            window.jamStarted = (verb) => window.parent.postMessage({op: "started", verb});
            window.jamDone = (win) => window.parent.postMessage({op: "done", win});

            window.addEventListener("message", (e) => {
                if (e.data && e.data.op === "start") {
                    window.jamStart = true;
                    if (typeof e.data.difficulty === "number") {
                        window.jamDifficulty = e.data.difficulty;
                    }
                }
            });

            if (window.parent === window) {
                window.jamStart = true;
                window.jamDifficulty = Math.floor(Math.random() * 8);
                console.log("difficulty", window.jamDifficulty);
            } else {
                window.parent.postMessage({op: "ready"});
            }

            const fit = () => {
                const c = document.querySelector("canvas");
                if (!c) {
                    requestAnimationFrame(fit);
                    return;
                }

                const r = Math.max(
                    1,
                    Math.min(Math.floor(innerWidth / 240), Math.floor(innerHeight / 160), 4),
                );
                c.style.transform = `translate(-50%, -50%) scale(${r})`;
            };
            window.addEventListener("resize", fit);
            fit();
        </script>
    </head>
</html>