From 380230e9551a219867567b1a96e14a49aff2067a Mon Sep 17 00:00:00 2001 From: Doug McInnes Date: Thu, 18 Feb 2010 21:55:40 -0800 Subject: [PATCH] added collidesWith to the objects --- game.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/game.js b/game.js index d397c1b..472242d 100644 --- a/game.js +++ b/game.js @@ -83,6 +83,8 @@ Sprite = function () { this.visible = false; this.reap = false; + this.collidesWith = []; + this.x = 0; this.y = 0; this.rot = 0; @@ -194,7 +196,9 @@ Sprite = function () { }; this.checkCollision = function (other) { - if (!other.visible || this == other) return; + if (!other.visible || + this == other || + this.collidesWith.indexOf(other.name) == -1) return; var trans = other.translatedPoints(); for (var i = 0; i < trans.length/2; i++) { var xi = i*2; @@ -248,6 +252,8 @@ var Ship = function () { this.delayBeforeBullet = 0; + this.collidesWith = ["asteroid"]; + this.preMove = function (delta) { if (KEY_STATUS.left) { this.vel.rot = -5; @@ -311,6 +317,9 @@ Ship.prototype = new Sprite(); var Bullet = function () { this.init("bullet"); this.time = 0; + // asteroid can look for bullets so doesn't have + // to be other way around + //this.collidesWith = ["asteroid"]; this.configureTransform = function () {}; this.draw = function () { @@ -366,6 +375,8 @@ var Asteroid = function () { this.visible = true; this.scale = 6; + this.collidesWith = ["ship", "bullet"]; + }; Asteroid.prototype = new Sprite();