window.ontouchmove = function(evt) {
	evt.preventDefault();
}

var currentSoundtrack = -1;
function playSoundtrack(tracks) {
	var keys = Object.keys(tracks);
	if (currentSoundtrack === -1)
		currentSoundtrack = randInt(0, keys.length);

	var key = keys[currentSoundtrack];
	var track = tracks[key];

	var trackId = currentSoundtrack;
	while (currentSoundtrack === trackId)
		currentSoundtrack = randInt(0, keys.length);

	if (track.ready) {
		track.play();
		track.once("ended", function() { playSoundtrack(tracks) });
	} else {
		track.once("load", function() {
			track.play();
			track.once("ended", function() { playSoundtrack(tracks) });
		});
	}
}
playSoundtrack(assets.soundtracks);

function run() {
	var game = new Game(document.getElementById("canvas"));
	game.canvas.width = window.innerWidth;
	game.canvas.height = window.innerHeight;

	var worldgen = new WorldGen(game);

	game.start(worldgen);

	game.onstop = function(score) {
		alert("You lost! Score: "+score);
		run();
	}
}

run();
