summaryrefslogtreecommitdiff
path: root/2026/games_submissions/crm148/game.js
blob: 00f1cc659d6083637e6036a102e15da2ed867a06 (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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101

import { View, globalView } from './view.js';
import { getCosmos } from './cosmos.js';
import Vec2 from './vec2.js';

import { victory, death, initInput, getDebugInfo } from './control.js';

startButton.onclick = function (ev) {
    window.postMessage({op:"start", difficulty: 1});
}

plusButton.onclick = function(ev) {
    window.testAngle += 0.1;
}

minusButton.onclick = function(ev) {
    window.testAngle -= 0.1;
}

testButton.onclick = function (ev) {
    if (!cosmos) {
        cosmos = getCosmos();
        cosmos.init(1);
        initInput(cosmos);
    }

    cosmos.running = false;
    cosmos.player.state = 'start_testing';

    cosmos.pulses = [
        new Pulse(Math.PI / 4, Math.PI, 70, 0, 30),
    ];

    cosmos.update(0);
    cosmos.render();

    //     if (!cosmos.running) {
    //         if (lasttime === undefined) {
    //             render(0);
    //             lasttime = undefined;
    //             starttime = undefined;
    //         } else {
    //             render(lasttime);
    //         }
    //     }
}

var cosmos;

function start(difficulty) {
    cosmos = getCosmos();
    cosmos.init(difficulty);
    initInput(cosmos);

    window.requestAnimationFrame(render);
    // TODO: set up mouse input listener, remove it on game over
    window.parent.postMessage({op: "started", verb: "dodge!"});
}

// input - mouse click
// point the ship and thrust
// add particle (time, position, velocity)
// expire the particles - maybe wait until all of them are over time limit so
// new ones keep the old ones alive
// fade to black and keep it there
// smoke on the grey background of space

// TODO: game is over after some amount of energy (increases with difficulty) is
// expelled from the star
function nop() {
    ;
}

var starttime;
var lasttime;
// var start = startGame;

function render(timestamp) {
    if (starttime === undefined) {
        starttime = timestamp;
        lasttime = starttime;
    } else {
        nop();
    }
    // const elapsed = timestamp - starttime;
    const dt = (timestamp - lasttime) / 1000.0;
    cosmos.update(dt);
    cosmos.render();
    lasttime = timestamp;
    if (cosmos.running) {
        window.requestAnimationFrame(render);
    } else {
        // console.log('over');
    }
}


export {
    start,
}