this.collidesWith = function(sprite){ // a method of the sprite object //check for collision with another sprite //collisions only activated when both sprites are visible collision = false; if (this.visible){ if (sprite.visible){ //define borders myLeft = this.x; myRight = this.x + this.width; myTop = this.y; myBottom = this.y + this.height; otherLeft = sprite.x; otherRight = sprite.x + sprite.width; otherTop = sprite.y; otherBottom = sprite.y + sprite.height; //assume collision collision = true; //determine non-colliding states if ((myBottom < otherTop) || (myTop > otherBottom) || (myRight < otherLeft) || (myLeft > otherRight)) { collision = false; } // end if } // end 'other visible' if } // end 'I'm visible' if return collision; } // end collidesWith