Skip to content

Commit

Permalink
added collidesWith to the objects
Browse files Browse the repository at this point in the history
  • Loading branch information
dmcinnes committed Feb 19, 2010
1 parent fe11dbc commit 380230e
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion game.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ Sprite = function () {
this.visible = false;
this.reap = false;

this.collidesWith = [];

this.x = 0;
this.y = 0;
this.rot = 0;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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 () {
Expand Down Expand Up @@ -366,6 +375,8 @@ var Asteroid = function () {
this.visible = true;
this.scale = 6;

this.collidesWith = ["ship", "bullet"];

};
Asteroid.prototype = new Sprite();

Expand Down

0 comments on commit 380230e

Please sign in to comment.