aboutsummaryrefslogtreecommitdiff
path: root/js/mygame.js
blob: 6293150e93f73cd273564deb42e4ab0fd7cb4ca5 (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
const floor = Math.floor;
const max = Math.max;
const min = Math.min;

class MyGame extends Game {
    constructor(canvas) {
        super(canvas);
        this.width = 320;
        this.height = 240;

        this.data = {
            sound: "snd/test.ogg",
            world: "json/world.json",
            player: "img/player.png"
        };
        this.dataSize = Object.keys(this.data).length;
    }

    init() {
        /* log the JSON */
        console.log(this.res.world);
    }

    update(dt) {
    }

    draw() {
        this.drawStart();

        /* draw an image */
        this.ctx.drawImage(this.res.player, 0, 0);

        /* play a sound then z is pressed */
        if (this.keys["a"]) {
            this.playSnd(this.res.sound);
        }

        this.drawEnd();
    }
}