Advertisement
Guest User

Untitled

a guest
Dec 11th, 2017
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.99 KB | None | 0 0
  1. <html>
  2. <body>
  3. <script>
  4. document.onkeydown = looper
  5.  
  6. var badmy = 0;
  7. var speedmy = 50;
  8. var flying = 0;
  9. var shooting = 0;
  10. var alive = true;
  11. var valid = true;
  12. var bullet = true;
  13. var movey = 500;
  14. var speedy = 5;
  15. if (alive = true) {
  16. setInterval(badguy, 1000);
  17. }
  18. setInterval(collision, 1);
  19.  
  20. function looper(e) {
  21. var moveleft = parseInt(move.style.left)
  22. var movel = moveleft - 20
  23. var moveright = parseInt(move.style.left)
  24. var mover = moveright + 20
  25. var moveup = parseInt(move.style.top)
  26. var moveu = moveup - 20
  27. var movedown = parseInt(move.style.top)
  28. var moved = movedown + 20
  29. var keycode;
  30. keyBuffer="";
  31. if(window.event)
  32. {keycode =window.event.keyCode;}
  33. else if(e)
  34. {keycode=e.which;}
  35. if(keycode == 37){move.style.left = movel;}
  36. if(keycode == 39){move.style.left = mover;}
  37. if(keycode == 38){move.style.top = moveu;}
  38. if(keycode == 40){move.style.top = moved;}
  39. if(keycode == 32){shoot();}
  40. }
  41. function shoot(){
  42. var pew = document.getElementById("pew");
  43. if (valid == true){
  44. pew.style.left = ((parseInt(player.style.left) + player.offsetWidth / 2));
  45. pew.style.top = player.style.top
  46. valid = false
  47. if(pew.style.top == player.style.top) {fire = setInterval(pewpew, 1)}
  48. }
  49. }
  50. function pewpew(){
  51. shooting = movey-=speedy;
  52. pew.style.top = shooting;
  53. if(shooting <= -50){clearInterval(fire);
  54. movey = parseInt(player.style.top);
  55. valid = true;
  56. }
  57. }
  58.  
  59. function badguy(){
  60.  
  61. flying = badmy+=speedmy;
  62.  
  63. for (i = 1; i < 11; i++){
  64. document.getElementById(i).style.top = flying;
  65. }
  66.  
  67. if (flying >= 800) {
  68. badmy = 0
  69. }
  70. }
  71.  
  72. function collision(){
  73.  
  74. var badg = document.getElementById("jj");
  75. var player = document.getElementById("player");
  76. var bullet = document.getElementById("pew");
  77.  
  78.  
  79. var btop = parseInt(bullet.style.top);
  80. var bleft = parseInt(bullet.style.left);
  81.  
  82. var duca = parseInt(player.style.top);
  83. var ducab = parseInt(flying);
  84. var duca1 = parseInt(player.style.left);
  85.  
  86.  
  87. for (num = 1; num < 11; num++){
  88.  
  89.  
  90.  
  91.  
  92. if ((duca < ducab + document.getElementById(num).offsetHeight) && (duca + player.offsetHeight > ducab) && (duca1 < parseInt(document.getElementById(num).style.left) + document.getElementById(num).offsetWidth)&&(duca1 + player.offsetWidth > parseInt(document.getElementById(num).style.left)))
  93. {player.style.left = 250;
  94. player.style.top = 500;
  95. document.getElementById(num).style.top = 0;
  96. }
  97. }
  98.  
  99. }
  100. //if ((btop < ducab + badg.offsetHeight)&&(btop + pew.offsetHeight > ducab)&&(bleft < ducab1 + badg.offsetWidth)&&(bleft + pew.offsetWidth > ducab1))
  101. //{badg.style.top = 0;
  102. //badmy = 0;}
  103.  
  104.  
  105.  
  106.  
  107.  
  108.  
  109. </script>
  110. <form name = "photos">
  111. <img src = "t1.jpg" id = "1" style = "position:absolute; left: 0; top: 0" width = 50 height = 50>
  112. <img src = "t1.jpg" id = "2" style = "position:absolute; left: 50; top: 0" width = 50 height = 50>
  113. <img src = "t1.jpg" id = "3" style = "position:absolute; left: 100; top: 0" width = 50 height = 50>
  114. <img src = "t1.jpg" id = "4" style = "position:absolute; left: 150; top: 0" width = 50 height = 50>
  115. <img src = "t1.jpg" id = "5" style = "position:absolute; left: 200; top: 0" width = 50 height = 50>
  116. <img src = "t1.jpg" id = "6" style = "position:absolute; left: 250; top: 0" width = 50 height = 50>
  117. <img src = "t1.jpg" id = "7" style = "position:absolute; left: 300; top: 0" width = 50 height = 50>
  118. <img src = "t1.jpg" id = "8" style = "position:absolute; left: 350; top: 0" width = 50 height = 50>
  119. <img src = "t1.jpg" id = "9" style = "position:absolute; left: 400; top: 0" width = 50 height = 50>
  120. <img src = "t1.jpg" id = "10" style = "position:absolute; left: 450; top: 0" width = 50 height = 50>
  121.  
  122. <img src = "red.jpg" id = "pew" style = "position:absolute; left: 500; top: -50 " width = 3 height = 50 >
  123. <img src = "Shooter.jpg" name = "move" id = "player" style="left: 300; position:absolute; top: 500" width = 100 height = 100>
  124. </form>
  125. </body>
  126. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement