Game
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

script.js 1.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. window.ontouchmove = function(evt) {
  2. evt.preventDefault();
  3. }
  4. var currentSoundtrack = -1;
  5. function playSoundtrack(tracks) {
  6. console.log("Playing track...");
  7. var keys = Object.keys(tracks);
  8. if (currentSoundtrack === -1)
  9. currentSoundtrack = randInt(0, keys.length);
  10. var key = keys[currentSoundtrack];
  11. var track = tracks[key];
  12. console.log("Playing track", key);
  13. var trackId = currentSoundtrack;
  14. while (currentSoundtrack === trackId)
  15. currentSoundtrack = randInt(0, keys.length);
  16. if (track.ready) {
  17. track.play();
  18. track.once("ended", function() { playSoundtrack(tracks) });
  19. console.log("playing immediately, as it's loaded");
  20. } else {
  21. console.log("loading it...");
  22. track.once("load", function() {
  23. console.log("loaded.");
  24. track.play();
  25. track.once("ended", function() { playSoundtrack(tracks) });
  26. });
  27. }
  28. }
  29. playSoundtrack(assets.soundtracks);
  30. function run() {
  31. var game = new Game(document.getElementById("canvas"));
  32. game.canvas.width = window.innerWidth;
  33. game.canvas.height = window.innerHeight;
  34. var worldgen = new WorldGen(game);
  35. game.start(worldgen);
  36. game.onstop = function(score) {
  37. alert("You lost! Score: "+score);
  38. run();
  39. }
  40. }
  41. run();