Advertisement
ellyeqka

Untitled

Oct 21st, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.98 KB | None | 0 0
  1. <!DOCTYPE html>
  2.  
  3. <html>
  4. <head>
  5. <title>JAVA</title>
  6. <style >
  7. body{
  8. position:relative;
  9. background-color:white;
  10. }
  11. img{
  12. position:absolute;
  13. width:150px;
  14. height:150px;
  15. z-index:-1;
  16.  
  17. }
  18. </style>
  19. </head>
  20. <body onload="init();" style="relative;">
  21.  
  22. <button onclick="start();">start</button>
  23. <button onclick="move();">move</button>
  24. <button onclick="repeat();">repeat</button>
  25.  
  26. <div id = "snimki" style="border:2px solid black; width:100%; height:600px; position:relative; margin:0 auto;">
  27. <img id="pracence" src="pig.png" style="top:20px; left:-150px; " />
  28. <img id="4ovece" src="snow.png" style="top:220px; left:-150px;"/>
  29. <img id="risyncica" src="gun.png" style="top:0px; left:0px;"/>
  30. </div>
  31.  
  32.  
  33. <script>
  34.  
  35. var started;
  36. var pigSpeed = 20;
  37. var snowSpeed = 30;
  38. var pigPosition = -150;
  39. var snowPosition = -150;
  40. var gunPosition = 0;
  41. var pigTop = 20;
  42. var snowTop = 220;
  43. var gunTop = 0;
  44. let move = function()
  45. {
  46. let width = window.innerWidth;
  47. pigPosition=pigPosition+pigSpeed;
  48. if (pigPosition >= width){
  49. pigPosition = -150;
  50.  
  51. }
  52. var pig = document.getElementById("pracence");
  53. pig.style.left=pigPosition+"px";
  54. //document.getElementById("pracence").src="pig.png";
  55.  
  56. snowPosition = snowPosition+snowSpeed;
  57. if (snowPosition > width){
  58. snowPosition = -150;
  59. }
  60. var snow = document.getElementById("4ovece");
  61. snow.style.left = snowPosition+"px";
  62. //document.getElementById("4ovece").src="snow.png";
  63. }
  64.  
  65. function repeat() {
  66. document.getElementById("pracence").src="pig.png";
  67. document.getElementById("4ovece").src="snow.png";
  68. }
  69.  
  70. let msg=function()
  71. {
  72. alert("hiiiiiii ");
  73. }
  74. function start(){
  75. if (started == undefined) {
  76. started = setInterval(move, 100);
  77. }
  78. }
  79. function kill(){
  80. let pigLeft = document.getElementById("pracence").style.left;
  81. let snowLeft = document.getElementById("4ovece").style.left;
  82. alert(pigLeft);
  83. alert(snowLeft);
  84. }
  85. function init(){
  86. document.body.addEventListener("keypress", keys )
  87. }
  88. function keys(event){
  89. let userKey = event.char||event.charCode||event.which;
  90. //alert(typeof(userKey));
  91. switch(userKey){
  92. case 56:gunTop = gunTop + -20;document.getElementById("risyncica").style.top= gunTop + "px";break;//up
  93. case 54:gunPosition = gunPosition + 20;document.getElementById("risyncica").style.left = gunPosition + "px";break;//right
  94. case 52:gunPosition = gunPosition + -20;document.getElementById("risyncica").style.left = gunPosition + "px";break;//left
  95. case 50:gunTop = gunTop + 20;document.getElementById("risyncica").style.top = gunTop + "px";break;//down
  96. case 13:strike();break;
  97. }
  98. var pig = document.getElementById("pracence");
  99. gun.style.left=gunPosition+"px";
  100. gun.style.top=gunTop+"px";
  101. }
  102. function strike() {
  103. var pigLeftD=gunPosition-pigPosition;
  104. var pigTopD=gunPosition-pigTop;
  105. let check=(pigLeftD>-120 &&pigLeftD<120) && (pigTopD>-120 && pigTopD<120);
  106.  
  107. if(check){
  108. //alert("bravo");
  109.  
  110. pigPosition = -150;
  111. var pig = document.getElementById("pracence");
  112. pig.style.left=pigPosition+"px";
  113. }else{
  114. alert("ne stavash");
  115. }
  116. }
  117.  
  118.  
  119.  
  120.  
  121. </script>
  122.  
  123. </body>
  124. </body>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement