Advertisement
8u

simple shooting game html prototype

8u
Aug 19th, 2021
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 2.70 KB | None | 0 0
  1. —-note this is for my website and other works on my pastebin are too
  2.  
  3. <!DOCTYPE html>
  4. <html>
  5. <head><title>Simple Game</title></head>
  6.  
  7. <style>
  8. #score{
  9. background-color: white;
  10. height:50px;
  11. width:140px;
  12. top:10px;
  13. left:540px;
  14. font-size:30px;
  15. }
  16. #board{
  17. position:absolute;
  18. width:5000px;
  19. height:300px;
  20. }
  21. #background{
  22. position:absolute;
  23. width:700px;
  24. height:500px;
  25. }
  26. #ball{
  27. position:absolute;
  28. width:70px;
  29. height:70px;
  30. top: 410px;
  31. left: 300px;
  32. }
  33. #goalie{
  34. position:absolute;
  35. width:100px;
  36. top:200px;
  37. left:300px;
  38. }
  39. #rules{
  40. position:absolute;
  41. top:0px;
  42. left:730px;
  43. }
  44. </style>
  45.  
  46. <body>
  47. <div id="board">
  48. <img id="background" src="img/background.jpg" />
  49. <img id="ball" src="img/ball.jpg"/>
  50. <img id="goalie" src="img/goalie.jpg"/>
  51. <div id="score" style="position:absolute;" >Score</div>
  52. </div>
  53. <div id="rules" style="position:absolute;" >
  54.  
  55. <h1>Simple Shooter Game</h1>
  56.  
  57. <p>On building this simple game I learnt more about how the programming languages HTML5, CSS and JavaScript worked. The rules are stated below<p>
  58.  
  59. <ul>
  60. <li>jkdsgjs</li>
  61. <li>hfdja</li>
  62. <li>`jeatngdadv</li>
  63. </ul>
  64.  
  65. <p>Have fun!!</p>
  66.  
  67.  
  68. <button onclick="shootLeft()" style="top:400px; left:100px;" type="leftButton">Shoot left</button>
  69. <button onclick="shootRight()" style="top:400px; left:200px;" type="rightButton">Shoot right</button>
  70.  
  71. <div>
  72. <p id="gameover"></p>
  73. </div>
  74. </div>
  75.  
  76. <script>
  77. var ball = null;
  78. var x = 1;
  79. var score = 0;
  80. document.getElementById('score').innerHTML = '0';
  81. var animate;
  82. ball = document.getElementById('ball');
  83.  
  84. function shootLeft(){
  85. var ran = Math.random();
  86.  
  87. while(parseInt(ball.style.top) != 300){
  88. ball.style.left = parseInt(ball.style.left) - 1 + 'px';
  89. ball.style.top = parseInt(ball.style.top) - 1 + 'px';
  90. animate = setTimeout(shootLeft,20);
  91. }
  92. if(ran<0.3){
  93. score = score + 1;
  94. document.getElementById('score').innerHTML = score;
  95. }
  96. else{
  97. document.getElementById('score').innerHTML = score;
  98. }
  99. x++;
  100. if(x==10){
  101. document.getElementById('gameover').innerHTML = "Game over! You got a score of " + score;
  102. }
  103. ball.style.left = '300px';
  104. ball.style.top = '410px';
  105. }
  106.  
  107. function shootRight(){
  108. van ran = Math.random();
  109.  
  110. while(parseInt(ball.style.top != 300){
  111. ball.style.left = parseInt(ball.style.left) + 1 + 'px';
  112. ball.style.top = parseInt(ball.style.top) - 1 + 'px';
  113. animate = setTimeout(shootRight,20);
  114. }
  115. if(ran>0.7){
  116. score = score + 1;
  117. document.getElementById('score').innerHTML = score;
  118. }
  119. else{
  120. document.getElementById('score').innerHTML = score;
  121. }
  122. x++;
  123. if(x==10){
  124. document.getElementById('gameover').innerHTML = "Game over! You got a score of " + score;
  125. }
  126. ball.style.left = '300px';
  127. ball.style.top = '410px';
  128. }
  129.  
  130. }
  131.  
  132.  
  133. </script>
  134.  
  135. </body>
  136.  
  137.  
  138. </html>
  139.  
  140. —-by 8u
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement