PageRenderTime 43ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/index.php

https://bitbucket.org/GoryMoon/gameengine
PHP | 130 lines | 74 code | 9 blank | 47 comment | 2 complexity | 1321cefde85d7b5d6914c95c397673d1 MD5 | raw file
  1. <?php
  2. $files = array();
  3. $files[] = glob("core/*.js");
  4. $files[] = glob("entities/*.js");
  5. $files[] = glob("levels/*.js");
  6. $files[] = glob("config/*.js");
  7. ?>
  8. <!DOCTYPE html>
  9. <html>
  10. <head>
  11. <title>HTML5 canvas game</title>
  12. <link rel="stylesheet" href="game.css" type="text/css" />
  13. <!-- Load libraries -->
  14. <script type="text/javascript" src="libraries/require.js"></script>
  15. <script type="text/javascript" src="libraries/prototype.js"></script>
  16. <script type="text/javascript">
  17. // Cross-browser compability
  18. window.requestAnimFrame = (function(){
  19. return window.requestAnimationFrame ||
  20. window.webkitRequestAnimationFrame ||
  21. window.mozRequestAnimationFrame ||
  22. window.oRequestAnimationFrame ||
  23. window.msRequestAnimationFrame ||
  24. function(callback){
  25. window.setTimeout(callback, 1000 / 60);
  26. };
  27. })();
  28. var tileSize = 32;
  29. /**
  30. * Convert tile X and Y positions to pixels
  31. * @param Int x
  32. * @param Int y
  33. * @return Object
  34. */
  35. function translate(x, y)
  36. {
  37. return {
  38. x: Math.ceil(x * tileSize),
  39. y: Math.ceil(y * tileSize)
  40. }
  41. }
  42. /**
  43. * Check if number is in range
  44. * @param Int x
  45. * @param Int min
  46. * @param Int max
  47. * @return Booelan
  48. */
  49. function inRange(x, min, max)
  50. {
  51. return x >= min && x <= max;
  52. }
  53. // Declare global variables
  54. var Main, Game, Log, Classes = Entities = Renderers = {};
  55. // Define files to load
  56. var files = [
  57. <?php
  58. $tab = "";
  59. foreach($files as $stack)
  60. {
  61. foreach($stack as $file)
  62. {
  63. echo $tab."'".$file."',\n";
  64. // Some align stuff
  65. if(!$tab)
  66. {
  67. $tab = " ";
  68. }
  69. }
  70. }
  71. ?>
  72. ];
  73. // Load files and initialize system
  74. require(files, function()
  75. {
  76. Main = new Classes.Main();
  77. Game.start();
  78. });
  79. </script>
  80. </head>
  81. <body>
  82. <div id="game">
  83. <span id="top">
  84. <b>FPS:</b> <span id="fps_value">0</span> |
  85. <b>Mouse:</b> <span id="coordinates">(?,?)</span> |
  86. <a href="javascript:void(0)" onClick="Main.Loop.toggle(this)">Pause</a> |
  87. <a href="javascript:void(0)" onClick="Game.DevTools.toggleEditor(this)">Edit level</a> |
  88. <a href="javascript:void(0)" onClick="Game.Effects.toggleRain()">Toggle rain</a> |
  89. <a href="javascript:void(0)" onClick="Game.Effects.toggleSnow()">Toggle snow</a> |
  90. <a href="javascript:void(0)" onClick="Game.Effects.toggleNight()">Toggle night</a> |
  91. <a href="javascript:void(0)" onClick="Game.Effects.toggleThunder()">Toggle thunder</a> |
  92. <a href="javascript:void(0)" onClick="Game.Effects.toggleEarthquake()">Toggle earthquake</a>
  93. </span>
  94. <div id="canvases">
  95. <canvas id="background" width="800" height="480"></canvas>
  96. <canvas id="foreground" width="800" height="480"></canvas>
  97. <canvas id="entities" width="800" height="480"></canvas>
  98. <canvas id="ui" width="800" height="480"></canvas>
  99. <canvas id="dev" width="800" height="480"></canvas>
  100. </div>
  101. <div id="editor">
  102. <a style="background-color:#fff;float:right;width:128px;" href="javascript:void(0)" onClick="Game.DevTools.Editor.toggleSolid(this)">Type: block</a>
  103. <a style="background-color:#00baff" href="javascript:void(0)" onClick="Game.DevTools.Editor.setType(-1, this)">Air</a>
  104. <a style="background-color:#00baff" href="javascript:void(0)" onClick="Game.DevTools.Editor.setType(0, this)">Barrier</a>
  105. <a style="background-image:url(resources/grass.png)" href="javascript:void(0)" onClick="Game.DevTools.Editor.setType(1, this)" class="active"></a>
  106. <a style="background-image:url(resources/dirt.png)" href="javascript:void(0)" onClick="Game.DevTools.Editor.setType(2, this)"></a>
  107. <a style="background-image:url(resources/stone.png)" href="javascript:void(0)" onClick="Game.DevTools.Editor.setType(3, this)"></a>
  108. <a style="background-image:url(resources/sand.png)" href="javascript:void(0)" onClick="Game.DevTools.Editor.setType(4, this)"></a>
  109. <a style="background-image:url(resources/glass.png)" href="javascript:void(0)" onClick="Game.DevTools.Editor.setType(5, this)"></a>
  110. <a style="background-image:url(resources/wood.png)" href="javascript:void(0)" onClick="Game.DevTools.Editor.setType(6, this)"></a>
  111. <a style="background-image:url(resources/leaves.png)" href="javascript:void(0)" onClick="Game.DevTools.Editor.setType(7, this)"></a>
  112. <div style="clear:both;"></div>
  113. </div>
  114. </div>
  115. </body>
  116. </html>