Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/2.0.2/jquery.min.js"></script>
<meta charset=utf-8 />
<title>JS Bin</title>
</head>
<body>
  <button>CLICK TO SIMULATE COLLISION</button>
</body>
</html>
 
var startTime = new Date().getTime();
var time   = 0;
var collided  = false;
var engine;
function collision(){
  collided = true;
  time = parseInt((new Date().getTime()-startTime)/1000, 10);
}
function game(){  
  if(collided){
    alert("GAME OVER "+ time); 
    return clearInterval( engine ); 
  }
  /* GAME LOGIC HERE */
}
engine = setInterval(function(){ 
   game();
},25);
$('button').click(collision); 
Output

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
roXonpro
0viewers