From 7959a10b847947d91601f1ed53f750cc0f77d878 Mon Sep 17 00:00:00 2001 From: Oskari Timperi Date: Thu, 4 Aug 2011 22:07:13 +0300 Subject: Add Gag --- Gag.js | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 Gag.js (limited to 'Gag.js') diff --git a/Gag.js b/Gag.js new file mode 100644 index 0000000..33a068d --- /dev/null +++ b/Gag.js @@ -0,0 +1,55 @@ +(function(window) { + +var Gag = function(cat, x, y, dir) { + this.initialize(cat, x, y, dir); +} +var p = Gag.prototype = new Container(); + + Gag.initialize = function() { + Gag.img = new Image(); + Gag.img.onload = function() { + Gag.gfx = new Bitmap(Gag.img); + } + Gag.img.src = "catgag.png"; + } + Gag.initialize(); + Gag.count = 0; + + p.escaped = false; + p.dir = 0; + p.cat = null; + + p.base_initialize = p.initialize; + p.initialize = function(cat, x, y, dir) { + p.base_initialize(); + + this.id = Gag.count; + Gag.count++; + + this.x = x; + this.y = y; + this.dir = dir; + this.cat = cat; + + this.gfx = new Bitmap(Gag.img); + this.addChild(this.gfx); + + cat.getStage().addChild(this); + } + + p.tick = function() { + if (!this.escaped && !this.rect().collidesWith(this.cat.rect())) { + this.escaped = true; + window.Log("(" + this.id + ") " + this.x + "," + this.y + " escaped"); + } + + this.x += Math.cos(this.dir * Math.PI / 180.0) * 2; + this.y += Math.sin(this.dir * Math.PI / 180.0) * 2; + } + + p.rect = function() { + return new Rectangle(this.x, this.y, Gag.img.width, Gag.img.height); + } + +window.Gag = Gag; +}(window)) -- cgit v1.2.3