function draw() {
	if (!gameOver && !paused) {
		if (used_tm%2 == 0) ctx.clearRect(0,0,canvas.width,canvas.height);
		frames++;
		
		//if (frames%Math.round(40-Math.sin(frames))) n.create();
		//if (frames%Math.round(40-frames/50) <= 0) n.create();
		//if (frames%Math.round(1/frames) == 0) n.create();
		if (frames%50 == 0) for (var i = 0; i < frames/500; i++) n.create();
		
		n.update();
		h.update();
		t.update();
		
		$("info").innerHTML = t.s;
	}
	else if (gameOver && !paused) {
		// send/get data
		if ((t.s > 0) && (++gameOverTimes == 1)) {
			timesPlayed++;
		
			if (!mobile) {
				var off_x = window.innerWidth / 2 - canvas.width / 2;
				var off_y = window.innerHeight / 2 - canvas.height / 2;
				$("score").style.left = off_x + canvas.width/4 + "px";
				$("score").style.top = off_y + canvas.height/4 + "px";
				$("score").innerHTML = "GAME OVER - Press enter to reset<br/>";
			} else {
				$("score").style.left = canvas.width/30 + "px";
				$("score").style.top = canvas.height/4 + "px";
				$("score").innerHTML = "GAME OVER<br/>Tap the screen with three fingers to restart<br/><br/>";
			}
			
			var d = new Date();
			var timePlayed = (d.getTime() - start_time) / 1000;
			
			var device;
			if (mobile) {
				var userAgent = navigator.userAgent.toLowerCase();
				if (userAgent.indexOf("android") != -1) device = "android";
				if (userAgent.indexOf("iphone") != -1) device = "iphone";
				if (userAgent.indexOf("ipod") != -1) device = "ipod";
				if (userAgent.indexOf("ipad") != -1) device = "ipad";
			}
			else {
				device = "computer";
			}
			
			xmlhttp = new XMLHttpRequest();
			
			xmlhttp.open("GET", "addScore.php?name="+$("username").value+"&score="+t.s+"&kills="+n.k+"&timePlayed="+timePlayed+"&timesPlayed="+timesPlayed+"&tm="+used_tm+"&device="+device, true);
			xmlhttp.send();
									
			xmlhttp.onreadystatechange = function() {
				if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
					$("score").innerHTML += xmlhttp.responseText;
				}
			};
		}
	}
}
