summaryrefslogtreecommitdiff
path: root/2026/games_submissions/cammymoop/js/micro.js
blob: c825081aa6dfdd8b0f77d59b26e885a515accd36 (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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158

M.Vec2 = Phaser.Math.Vector2;

// Extend Phaser game objects for vector usage
Phaser.GameObjects.GameObject.prototype.setPosVec = function (newPos) {
    this.x = newPos.x;
    this.y = newPos.y;
};

Phaser.GameObjects.GameObject.prototype.addPosVec = function (newPos) {
    this.x += newPos.x;
    this.y += newPos.y;
};

Phaser.GameObjects.GameObject.prototype.getPosVec = function () {
    return new M.Vec2(this.x, this.y);
};

M.WaitScene = class extends Phaser.Scene
{
    preload()
    {
        //this.load.image('image', 'assets/image.png');
        this.load.image('background', 'assets/background.png');
        this.load.image('goblin', 'assets/goblin.png');

        this.load.image('explosion', 'assets/explosion.png');

        this.load.image('red_circle', 'assets/red_circle.png');
        this.load.image('target_arrow', 'assets/target_arrow.png');
        this.load.image('reroll', 'assets/reroll.png');

        this.load.image('yes', 'assets/yes.png');
        this.load.image('ohno', 'assets/ohno.png');

        this.load.image('stopwatch_frame', 'assets/stopwatch_frame.png');
        this.load.spritesheet('stopwatch_numbers', 'assets/stopwatch_numbers.png', {
            "frameWidth": 12, "frameHeight": 14,
        });

        this.load.image('arrow_icon', 'assets/arrow_icon.png');
        this.load.image('boom_icon', 'assets/boom_icon.png');
        this.load.image('dice_icon', 'assets/dice_icon.png');
        this.load.image('equal_icon', 'assets/equal_icon.png');
        this.load.image('greater_icon', 'assets/greater_icon.png');
        this.load.image('guard_break_icon', 'assets/guard_break_icon.png');
        this.load.image('less_icon', 'assets/less_icon.png');
        this.load.image('skull_icon', 'assets/skull_icon.png');
        this.load.spritesheet('number_icons', 'assets/number_icons.png', {
            "frameWidth": 8, "frameHeight": 8,
        });

        this.load.spritesheet('gob_small', 'assets/gob_small.png', {
            "frameWidth": 48, "frameHeight": 46,
        });
        this.load.spritesheet('bomb_gnome', 'assets/bomb_gnome.png', {
            "frameWidth": 42, "frameHeight": 50,
        });

        this.load.spritesheet('dices', 'assets/dices.png', {
            "frameWidth": 30, "frameHeight": 30,
        });

        this.load.audio('boom_sfx', 'assets/sfx/boom.wav');
        this.load.audio('fwoof_sfx', 'assets/sfx/fwoof.wav');
        this.load.audio('land_sfx', 'assets/sfx/land.wav');
        this.load.audio('punch_sfx', 'assets/sfx/punch.wav');
        this.load.audio('crack_sfx', 'assets/sfx/crack.wav');

        this.load.audio('laugh1_sfx', 'assets/sfx/laugh1.wav');
        this.load.audio('laugh2_sfx', 'assets/sfx/laugh2.wav');
        this.load.audio('hoo_sfx', 'assets/sfx/hoo.wav');

        this.load.audio('gnome_grunt1_sfx', 'assets/sfx/gnome_grunt1.wav');
        this.load.audio('gnome_grunt2_sfx', 'assets/sfx/gnome_grunt2.wav');
        this.load.audio('gnome_grunt3_sfx', 'assets/sfx/gnome_grunt3.wav');

        this.load.audio('gob1_sfx', 'assets/sfx/gob1.wav');
        this.load.audio('gob2_sfx', 'assets/sfx/gob2.wav');
        this.load.audio('gob_grunt_sfx', 'assets/sfx/gob_grunt.wav');
    }

    create()
    {
        this.difficulty = M.gameDifficulty;
        this.textures.get("bomb_gnome").setFilter(Phaser.Textures.FilterMode.Nearest);
        this.textures.get("dices").setFilter(Phaser.Textures.FilterMode.Nearest);

        Phaser.Display.Canvas.CanvasInterpolation.setCrisp(this.game.canvas);
        window.parent.postMessage({op: "ready"});
    }

    update(t, dt)
    {
        if (M.standalone && this.input.activePointer.primaryDown) {
            this.startDiceGame();
        }
    }

    timeToStart(difficulty) {
        this.difficulty = difficulty;
        this.startDiceGame();
    }

    startDiceGame()
    {
        const data = { difficulty: this.difficulty };
        this.scene.switch("play", data);
        this.scene.stop();
    }
}

M.gameDifficulty = 0;

M.waitingScene = new M.WaitScene("wait");
M.gameScene = new M.DiceGame({key: "play", active: false});

M.gameStarted = function () {
    window.parent.postMessage({op: "started", verb: "Defeat!"});
};

M.gameEnd = function (won) {
    window.parent.postMessage({op: "done", win: won});
};

M.handleMessage = function (msgData) {
    if (!msgData) {
        return;
    }
    if (msgData.data.op == "start") {
        console.log("detected start!");
        M.waitingScene.timeToStart(msgData.data.difficulty);
    }
}
window.addEventListener("message", M.handleMessage);

const config = {
    scale: {
        mode: Phaser.Scale.FIT,
        autoCenter: Phaser.Scale.CENTER_HORIZONTALLY,
    },
    type: Phaser.AUTO,
    parent: 'game-container',
    width: 240,
    height: 160,
    backgroundColor: '#304858',
    scene: [
        M.waitingScene, M.gameScene,
    ],
    smoothPixelArt: true,
    //antialias: false,
    //antialiasGL: true,
};

M.standalone = window.self === window.top

const game = new Phaser.Game(config);
M.game = game;