aboutsummaryrefslogtreecommitdiff
path: root/catgag.js
blob: 7ef5e4fa40e2d311f25f7fd4813ab9a2f3d055b5 (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
(function(window) {

var Game = function() { };

Game.init = function() {
    this.canvas = document.getElementById("canvas");
    this.stage = new Stage(this.canvas);
    
    this.stage.preventDefaultKeys(["space", "up", "down", "left", "right"]);
    
    this.cat = new Cat();
    this.cat.x = this.canvas.width / 2;
    this.cat.y = this.canvas.height / 2;
    
    this.stage.addChild(this.cat);
    
    Ticker.addListener(this);
};

Game.tick = function() {
    this.handleKeys();
    this.stage.update();
};

Game.handleKeys = function() {
    var stage = this.stage;
    
    if (stage.isKeyPressed("space")) { this.cat.gag(); }
    
    if (stage.isKeyPressed("left")) { this.cat.x -= 5; }
    if (stage.isKeyPressed("right")) { this.cat.x += 5; }
    if (stage.isKeyPressed("up")) { this.cat.y -= 5; }
    if (stage.isKeyPressed("down")) { this.cat.y += 5; }
    
    if (stage.isKeyPressed("a")) { this.cat.barrelRoll(); }
}

Game.resMan = new ResourceMan();
Game.resMan.root = "gfx/";
Game.resMan.add("cat", "cat.jpg");
Game.resMan.add("catgag", "catgag.png");
Game.resMan.add("vacuum", "vacuum.png");
Game.resMan.add("vacuum1", "vacuum_1.png");
Game.resMan.add("vacuum2", "vacuum_2.png");
Game.resMan.add("vacuum11", "vacuum_11.png");
Game.resMan.add("vacuum12", "vacuum_12.png");
Game.resMan.add("vacuum21", "vacuum_21.png");
Game.resMan.add("vacuum22", "vacuum_22.png");
Game.resMan.done = function() {
    Gag.initialize();
    Game.init();
}

window.Game = Game;
}(window));

window.Log = function(str) {
    var ts = Date.now().toString();
    ts = ts.substr(ts.length - 6);
    window.LogElem.value = ts + " " + str + "\n" + window.LogElem.value;
}

window.onload = function() {
    window.LogElem = document.getElementById("log");
    window.Log("window.onload()");
    Ticker.setFPS(30);
    
    Game.resMan.loadAll(function() {
        window.Log(Game.resMan.progress() + "% loaded");
    });
    
    //Game.init();
}