|  |  |  | @ -26,7 +26,7 @@ | 
			
		
	
		
			
				
					|  |  |  |  | 	let currentGame=null; | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | 	// forward-declare functions
 | 
			
		
	
		
			
				
					|  |  |  |  | 	let resizeCanvas, getLevel, startGame, stopGame, handleWin, handleDeath, menu, help, settings, restart; | 
			
		
	
		
			
				
					|  |  |  |  | 	let resizeCanvas, getLevel, startGame, stopGame, handleWin, handleDeath, menu, help, settings, restart, updateHud; | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | 	// handle window resize and fullscreen
 | 
			
		
	
		
			
				
					|  |  |  |  | 	resizeCanvas=() => { | 
			
		
	
	
		
			
				
					|  |  |  | @ -126,6 +126,7 @@ | 
			
		
	
		
			
				
					|  |  |  |  | 			if(evt=='tick') { | 
			
		
	
		
			
				
					|  |  |  |  | 				input.framefn(); | 
			
		
	
		
			
				
					|  |  |  |  | 				snek.handleInputs(input.inputs); | 
			
		
	
		
			
				
					|  |  |  |  | 				updateHud(); | 
			
		
	
		
			
				
					|  |  |  |  | 			} else if(evt=='win') { | 
			
		
	
		
			
				
					|  |  |  |  | 				handleWin(snek); | 
			
		
	
		
			
				
					|  |  |  |  | 			} else if(evt=='die') { | 
			
		
	
	
		
			
				
					|  |  |  | @ -195,9 +196,10 @@ | 
			
		
	
		
			
				
					|  |  |  |  | 		let popup=new Popup("Finished!"); | 
			
		
	
		
			
				
					|  |  |  |  | 		popup.addStrong("You won!"); | 
			
		
	
		
			
				
					|  |  |  |  | 		popup.addContent({ | 
			
		
	
		
			
				
					|  |  |  |  | 			"Time": snek.playTime/1000+'s', | 
			
		
	
		
			
				
					|  |  |  |  | 			"Time": snek.endPlayTime/1000+'s', | 
			
		
	
		
			
				
					|  |  |  |  | 			"Score": snek.score, | 
			
		
	
		
			
				
					|  |  |  |  | 			"Final length": snek.length | 
			
		
	
		
			
				
					|  |  |  |  | 			"Final length": snek.length, | 
			
		
	
		
			
				
					|  |  |  |  | 			"Final speed": snek.speed+'tps' | 
			
		
	
		
			
				
					|  |  |  |  | 		}); | 
			
		
	
		
			
				
					|  |  |  |  | 		popup.buttons={ | 
			
		
	
		
			
				
					|  |  |  |  | 			retry: "Retry", | 
			
		
	
	
		
			
				
					|  |  |  | @ -233,9 +235,10 @@ | 
			
		
	
		
			
				
					|  |  |  |  | 		let popup=new Popup("Finished!"); | 
			
		
	
		
			
				
					|  |  |  |  | 		popup.addStrong("You died..."); | 
			
		
	
		
			
				
					|  |  |  |  | 		popup.addContent({ | 
			
		
	
		
			
				
					|  |  |  |  | 			"Time": snek.playTime/1000+'s', | 
			
		
	
		
			
				
					|  |  |  |  | 			"Time": snek.endPlayTime/1000+'s', | 
			
		
	
		
			
				
					|  |  |  |  | 			"Score": snek.score, | 
			
		
	
		
			
				
					|  |  |  |  | 			"Final length": snek.length | 
			
		
	
		
			
				
					|  |  |  |  | 			"Final length": snek.length, | 
			
		
	
		
			
				
					|  |  |  |  | 			"Final speed": snek.speed+'tps' | 
			
		
	
		
			
				
					|  |  |  |  | 		}); | 
			
		
	
		
			
				
					|  |  |  |  | 		popup.buttons={ | 
			
		
	
		
			
				
					|  |  |  |  | 			retry: "Retry", | 
			
		
	
	
		
			
				
					|  |  |  | @ -254,6 +257,28 @@ | 
			
		
	
		
			
				
					|  |  |  |  | 		} | 
			
		
	
		
			
				
					|  |  |  |  | 	}; | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | 	// draw status hud
 | 
			
		
	
		
			
				
					|  |  |  |  | 	updateHud=() => { | 
			
		
	
		
			
				
					|  |  |  |  | 		// stay safe
 | 
			
		
	
		
			
				
					|  |  |  |  | 		if(!currentGame) return; | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | 		// get the actual elements
 | 
			
		
	
		
			
				
					|  |  |  |  | 		const speedDisplay=document.querySelector('#hud .speed'); | 
			
		
	
		
			
				
					|  |  |  |  | 		const scoreDisplay=document.querySelector('#hud .score'); | 
			
		
	
		
			
				
					|  |  |  |  | 		const timeDisplay=document.querySelector('#hud .time'); | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | 		// rpad is useful
 | 
			
		
	
		
			
				
					|  |  |  |  | 		const rpad=(n, digits=2, pad=' ') => | 
			
		
	
		
			
				
					|  |  |  |  | 			((''+n).length>=digits)?(''+n):(rpad(pad+n, digits, pad)); | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | 		// actually do the hud
 | 
			
		
	
		
			
				
					|  |  |  |  | 		speedDisplay.innerText=rpad(currentGame.speed, 2, '0')+'tps'; | 
			
		
	
		
			
				
					|  |  |  |  | 		scoreDisplay.innerText=currentGame.score; | 
			
		
	
		
			
				
					|  |  |  |  | 		timeDisplay.innerText=rpad(Math.floor(currentGame.playTime/60000), 2, '0')+ | 
			
		
	
		
			
				
					|  |  |  |  | 			':'+rpad(Math.floor(currentGame.playTime/1000)%60, 2, '0')+ | 
			
		
	
		
			
				
					|  |  |  |  | 			':'+rpad(currentGame.playTime%1000, 3, '0'); | 
			
		
	
		
			
				
					|  |  |  |  | 	}; | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | 	// quick restart
 | 
			
		
	
		
			
				
					|  |  |  |  | 	restart=() => { | 
			
		
	
		
			
				
					|  |  |  |  | 		if(currentGame && currentGame.playing) { | 
			
		
	
	
		
			
				
					|  |  |  | 
 |