Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2017
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.15 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <!--
  3. To change this license header, choose License Headers in Project Properties.
  4. To change this template file, choose Tools | Templates
  5. and open the template in the editor.
  6. -->
  7. <html>
  8. <head>
  9. <meta charset="UTF-8">
  10. <title></title>
  11. </head>
  12. <body>
  13. <canvas id="ctx" width="800" height="500" style="border:1px solid #000000;background-image:url('space-1.jpg')"></canvas>
  14.  
  15.  
  16. <script>
  17. /* Základní popisky*/
  18. var ctx = document.getElementById("ctx").getContext("2d");
  19. ctx.font = '30px Arial';
  20. ctx.fillStyle = 'white';
  21. var count = 0;
  22. var points = 0;
  23. var pressed_start = false;
  24. /* Interakce s klávesnicí */
  25. document.onkeydown = function(event){
  26. if (event.keyCode === 68 && falcon.x < 600 ) { //d
  27. falcon.x += 10;
  28. bullet.x +=10;
  29. }
  30. if (event.keyCode === 83 && falcon.y < 360){ //s
  31. falcon.y +=10;
  32. }
  33. if (event.keyCode === 65 && falcon.x > 0) { //a
  34. falcon.x -=10;
  35. bullet.x -=10;
  36. }
  37. if (event.keyCode === 87 && falcon.y > 0) { //w
  38. falcon.y -=10;
  39. }
  40. if (event.keyCode === 80) { //p
  41. pressed_start = true;
  42. }
  43. if (event.keyCode === 32) {
  44.  
  45. }
  46. };
  47. //32 mezerník
  48.  
  49. /* Entity*/
  50. falcon = {
  51. x : 600,
  52. y : 10,
  53. img : 'falcon1.png'
  54. };
  55.  
  56. bullet = {
  57. x : falcon.x,
  58. y : falcon.y+55,
  59. img : 'bullet.png'
  60. };
  61.  
  62. enemy = {
  63. x: 0,
  64. y : Math.round(Math.ceil((Math.random() * 360) + 1)/10)*10,
  65. img : 'enemy_1.png'
  66. };
  67.  
  68. setInterval(update,10);
  69.  
  70.  
  71. function drawEntity(entity){
  72. var Img = new Image();
  73. Img.src = entity.img;
  74. ctx.drawImage(Img,entity.x,entity.y);
  75. }
  76.  
  77. function hittedEnemy(){
  78. if(bullet.y === enemy.y) {
  79. return true;
  80. } else {
  81. return false;
  82. }
  83. }
  84.  
  85. function fireBullet(){
  86. bullet.x -=10;
  87. }
  88.  
  89. function game(){
  90. drawEntity(enemy);
  91. }
  92.  
  93. function update(){
  94.  
  95. /* Vyčištění */
  96. ctx.clearRect(0,0,800,500);
  97.  
  98. /*Vypsání/Vykreslíní XY/Falcona*/
  99. drawEntity(falcon);
  100. ctx.fillText("X : " + falcon.x + " Y : " + falcon.y, 600,480);
  101. ctx.fillText("X : " + enemy.x + " Y : " + enemy.y, 500,380);
  102.  
  103.  
  104. /* Kulla*/
  105. drawEntity(bullet);
  106. bullet.y = falcon.y+55;
  107.  
  108. /* Hra*/
  109. setTimeout(drawEntity(enemy),5000);
  110. }
  111.  
  112. </script>
  113. </body>
  114. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement