Guest User

Untitled

a guest
Sep 26th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.73 KB | None | 0 0
  1. this.crashWith = function(otherobj) {
  2. var myleft = this.x;
  3. var myright = this.x + (this.width);
  4. var mytop = this.y;
  5. var mybottom = this.y + (this.height);
  6. var otherleft = otherobj.x;
  7. var otherright = otherobj.x + (otherobj.width);
  8. var othertop = otherobj.y;
  9. var otherbottom = otherobj.y + (otherobj.height);
  10. var crash = true;
  11. if ((mybottom < othertop) || (mytop > otherbottom) || (myright < otherleft) || (myleft > otherright)) {
  12. crash = false;
  13. }
  14. return crash;
  15. }
  16.  
  17. for (i = 0; i < myObstacles.length; i += 1) {
  18. if (myGamePiece.crashWith(myObstacles[i])) {
  19. myGameArea.stop();
  20. return;
  21. }
  22. }
Add Comment
Please, Sign In to add comment