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 1000B

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