aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOskari Timperi <oskari.timperi@iki.fi>2011-08-04 22:07:13 +0300
committerOskari Timperi <oskari.timperi@iki.fi>2011-08-04 22:07:13 +0300
commit7959a10b847947d91601f1ed53f750cc0f77d878 (patch)
treef396c522eff43ea5908dd30bf9944b580bf1834c
parent1efecf008e7ef07d0d62fc067a8e67457c648114 (diff)
downloadcatgag-7959a10b847947d91601f1ed53f750cc0f77d878.tar.gz
catgag-7959a10b847947d91601f1ed53f750cc0f77d878.zip
Add Gag
-rw-r--r--Gag.js55
1 files changed, 55 insertions, 0 deletions
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))