index.html 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. <html>
  2. <body>
  3. <canvas id="game" width="480" height="320"></canvas>
  4. <script type="text/JavaScript" src="menus.js"></script>
  5. <script type='text/javascript'>
  6. //Input
  7. var input = false, touchX = 0, touchY = 0;
  8. //Initialize canvas
  9. var canvas = document.getElementById('game');
  10. canvas.onmousedown = function(e)
  11. {
  12. input = true;
  13. touchX = e.pageX - canvas.offsetLeft;
  14. touchY = e.pageY - canvas.offsetTop;
  15. }
  16. var context = canvas.getContext('2d');
  17. var width = 480;
  18. var height = 320;
  19. //Font
  20. context.font = '20pt Arial';
  21. context.textAlign="center";
  22. var fontSize = 20;
  23. //Shadow
  24. context.shadowOffsetX = 2;
  25. context.shadowOffsetY = 2;
  26. context.shadowBlur = 5;
  27. //Draw loading state
  28. context.fillText('Loading...', width/2, height/2);
  29. //Menu
  30. var menu, background;
  31. var bFirstChar = true;
  32. var bSound = true;
  33. //Images
  34. //var n = 100;
  35. //var sample = new Array();
  36. //for (var i = 0; i < n; i++)
  37. // sample.push(i);
  38. //var n = 41;
  39. //var image = new Array();
  40. //for (i = 0; i < n; i++)
  41. // image[i] = new Image();
  42. var image = [new Image(), new Image(), new Image(), new Image(), new Image(),
  43. new Image(), new Image(), new Image(), new Image(), new Image(),
  44. new Image(), new Image(), new Image(), new Image(), new Image(),
  45. new Image(), new Image(), new Image(), new Image(), new Image(),
  46. new Image(), new Image(), new Image(), new Image(), new Image(),
  47. new Image(), new Image(), new Image(), new Image(), new Image(),
  48. new Image(), new Image(), new Image(), new Image(), new Image(),
  49. new Image(), new Image(), new Image(), new Image(), new Image(),
  50. new Image()];
  51. image[0].src = 'images/background_bottom_0.png';
  52. image[1].src = 'images/background_bottom_1.png';
  53. image[2].src = 'images/background_top.png';
  54. image[3].src = 'images/cloud_back.png';
  55. image[4].src = 'images/cloud_front.png';
  56. image[5].src = 'images/tree_0.png';
  57. image[6].src = 'images/tree_1.png';
  58. image[7].src = 'images/title.png';
  59. image[8].src = 'images/button.png';
  60. //image[9].src = 'images/tutorial.png';
  61. image[10].src = 'images/dark_dimension_logo.png';
  62. //image[11].src = 'images/facebook.png';
  63. //image[12].src = 'images/twitter.png';
  64. //image[13].src = 'images/tumblr.png';
  65. //image[14].src = 'images/google_play_store.png';
  66. image[15].src = 'images/ground_0_0.png';
  67. image[16].src = 'images/ground_1_0.png';
  68. image[17].src = 'images/ground_2_0.png';
  69. image[18].src = 'images/ground_damaged_0.png';
  70. image[19].src = 'images/ground_damaged_1.png';
  71. image[20].src = 'images/ground_damaged_2.png';
  72. image[21].src = 'images/crystal.png';
  73. image[22].src = 'images/magic_mana.png';
  74. image[23].src = 'images/shield.png';
  75. image[24].src = 'images/double_score.png';
  76. image[25].src = 'images/spikes.png';
  77. image[26].src = 'images/sound_yes.png';
  78. image[27].src = 'images/sound_no.png';
  79. image[28].src = 'images/darek_run_0.png';
  80. image[29].src = 'images/darek_run_1.png';
  81. image[30].src = 'images/darek_run_2.png';
  82. image[31].src = 'images/darek_run_3.png';
  83. image[32].src = 'images/darek_run_4.png';
  84. image[33].src = 'images/darek_run_5.png';
  85. image[34].src = 'images/darek_run_6.png';
  86. image[35].src = 'images/darek_run_7.png';
  87. image[36].src = 'images/darek_fall.png';
  88. image[37].src = 'images/darek_jump.png';
  89. image[38].src = 'images/shield_active_0.png';
  90. image[39].src = 'images/shield_active_1.png';
  91. image[40].src = 'images/air_jump_darek.png';
  92. var sound = new Audio('foot_step.wav');
  93. sound.play();
  94. var imagesLoaded = 0;
  95. for (i = 0; i < 41; i++)
  96. image[i].onload = function()
  97. {
  98. if (++imagesLoaded == 36)
  99. {
  100. //Initialize Game state
  101. background = Background();
  102. menu = MainMenu(false);
  103. //Start loop
  104. setInterval(function()
  105. {
  106. update();
  107. if (menu.bDraw) draw();
  108. }, 1000/30);
  109. }
  110. };
  111. //Basic Game Loop
  112. //Update
  113. function update()
  114. {
  115. var nextMenu = menu.update();
  116. switch (nextMenu)
  117. {
  118. case 0:
  119. menu = MainMenu(menu.hardReset);
  120. break;
  121. case 1:
  122. menu = ExtraMenu();
  123. break;
  124. case 2:
  125. menu = GameMenu(menu.hardReset);
  126. break;
  127. }
  128. }
  129. //Draw
  130. function draw()
  131. {
  132. //Sky
  133. context.fillStyle="#FE9E70";
  134. context.fillRect(0, 0, width, height*3/4);
  135. //Sea
  136. context.fillStyle="#58B6DE";
  137. context.fillRect(0, height*3/4, width, height);
  138. //Reset for font
  139. context.fillStyle="white";
  140. //Draw Menu
  141. menu.draw();
  142. }
  143. </script>
  144. </body>
  145. </html>