diff options
| author | Oskari Timperi <oskari.timperi@iki.fi> | 2011-08-02 23:59:57 +0300 |
|---|---|---|
| committer | Oskari Timperi <oskari.timperi@iki.fi> | 2011-08-02 23:59:57 +0300 |
| commit | a30babdeca01469d4cbd4ce12176d0ccb161f16e (patch) | |
| tree | bed4f4e83927d18672009d6ca0cea785a6172c5f | |
| parent | 9549dbd722bc2c69b3eae53b77cf13d1955fd70b (diff) | |
| download | catgag-master.tar.gz catgag-master.zip | |
Added a couple of comments, renamed stuff for your pleasure :-)master
| -rw-r--r-- | catgag.js | 41 |
1 files changed, 19 insertions, 22 deletions
@@ -1,14 +1,11 @@ -/*var game = (function(window) { - var self = {}; - return self; -}(window));*/ - -function game() { +function CatGAGGame() { + //! Returns true if the item is outside the canvas. function outsideCanvas(item) { return (item.x < 0 || item.y < 0 || item.x > jaws.width || item.y > jaws.height); } - var Kissa = function() { + //! Our hero, the Cat! + var Cat = function() { this.barrelRolling = false; this.anchor("center"); this.setImage("cat.jpg"); @@ -58,14 +55,14 @@ function game() { this.gags.draw(); } }; - Kissa.prototype = new jaws.Sprite({}); + Cat.prototype = new jaws.Sprite({}); var CatGag = function(cat, x, y, dir) { this.x = x; this.y = y; this.dir = dir; this.cat = cat; - this.escaped = false; + this.escaped = false; //! False if the gag hasn't escaped the cat yet this.update = function() { if (!this.escaped && !this.rect().collideRect(this.cat.rect())) { @@ -78,46 +75,46 @@ function game() { }; CatGag.prototype = new jaws.Sprite({image: "catgag.png"}); - var kisu; + var cat; this.setup = function() { jaws.preventDefaultKeys(["up", "down", "left", "right", "space"]) - kisu = new Kissa(); - kisu.x = 100; kisu.y = 100; + cat = new Cat(); + cat.x = 100; cat.y = 100; }; this.update = function() { if (jaws.pressed("left")) { - kisu.x -= 5; + cat.x -= 5; } if (jaws.pressed("right")) { - kisu.x += 5; + cat.x += 5; } if (jaws.pressed("up")) { - kisu.y -= 5; + cat.y -= 5; } if (jaws.pressed("down")) { - kisu.y += 5; + cat.y += 5; } - if (jaws.pressed("space") && !kisu.barrelRolling) { - kisu.barrelRoll(); + if (jaws.pressed("space") && !cat.barrelRolling) { + cat.barrelRoll(); } if (jaws.pressed("z")) { - kisu.shoot(); + cat.shoot(); } - kisu.update(); + cat.update(); }; this.draw = function() { jaws.clear(); - kisu.draw(); + cat.draw(); }; } @@ -125,5 +122,5 @@ window.onload = function() { jaws.assets.add("cat.jpg"); jaws.assets.add("catgag.png"); - jaws.start(game, {fps: 30}); + jaws.start(CatGAGGame, {fps: 30}); }; |
