Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- this.crashWith = function(otherobj) {
- var myleft = this.x;
- var myright = this.x + (this.width);
- var mytop = this.y;
- var mybottom = this.y + (this.height);
- var otherleft = otherobj.x;
- var otherright = otherobj.x + (otherobj.width);
- var othertop = otherobj.y;
- var otherbottom = otherobj.y + (otherobj.height);
- var crash = true;
- if ((mybottom < othertop) || (mytop > otherbottom) || (myright < otherleft) || (myleft > otherright)) {
- crash = false;
- }
- return crash;
- }
- for (i = 0; i < myObstacles.length; i += 1) {
- if (myGamePiece.crashWith(myObstacles[i])) {
- myGameArea.stop();
- return;
- }
- }
Add Comment
Please, Sign In to add comment