Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <html>
- <body>
- <script>
- document.onkeydown = looper
- var badmy = 0;
- var speedmy = 50;
- var flying = 0;
- var shooting = 0;
- var alive = true;
- var valid = true;
- var bullet = true;
- var movey = 500;
- var speedy = 5;
- if (alive = true) {
- setInterval(badguy, 1000);
- }
- setInterval(collision, 1);
- function looper(e) {
- var moveleft = parseInt(move.style.left)
- var movel = moveleft - 20
- var moveright = parseInt(move.style.left)
- var mover = moveright + 20
- var moveup = parseInt(move.style.top)
- var moveu = moveup - 20
- var movedown = parseInt(move.style.top)
- var moved = movedown + 20
- var keycode;
- keyBuffer="";
- if(window.event)
- {keycode =window.event.keyCode;}
- else if(e)
- {keycode=e.which;}
- if(keycode == 37){move.style.left = movel;}
- if(keycode == 39){move.style.left = mover;}
- if(keycode == 38){move.style.top = moveu;}
- if(keycode == 40){move.style.top = moved;}
- if(keycode == 32){shoot();}
- }
- function shoot(){
- var pew = document.getElementById("pew");
- if (valid == true){
- pew.style.left = ((parseInt(player.style.left) + player.offsetWidth / 2));
- pew.style.top = player.style.top
- valid = false
- if(pew.style.top == player.style.top) {fire = setInterval(pewpew, 1)}
- }
- }
- function pewpew(){
- shooting = movey-=speedy;
- pew.style.top = shooting;
- if(shooting <= -50){clearInterval(fire);
- movey = parseInt(player.style.top);
- valid = true;
- }
- }
- function badguy(){
- flying = badmy+=speedmy;
- for (i = 1; i < 11; i++){
- document.getElementById(i).style.top = flying;
- }
- if (flying >= 800) {
- badmy = 0
- }
- }
- function collision(){
- var badg = document.getElementById("jj");
- var player = document.getElementById("player");
- var bullet = document.getElementById("pew");
- var btop = parseInt(bullet.style.top);
- var bleft = parseInt(bullet.style.left);
- var duca = parseInt(player.style.top);
- var ducab = parseInt(flying);
- var duca1 = parseInt(player.style.left);
- for (num = 1; num < 11; num++){
- 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)))
- {player.style.left = 250;
- player.style.top = 500;
- document.getElementById(num).style.top = 0;
- }
- }
- }
- //if ((btop < ducab + badg.offsetHeight)&&(btop + pew.offsetHeight > ducab)&&(bleft < ducab1 + badg.offsetWidth)&&(bleft + pew.offsetWidth > ducab1))
- //{badg.style.top = 0;
- //badmy = 0;}
- </script>
- <form name = "photos">
- <img src = "t1.jpg" id = "1" style = "position:absolute; left: 0; top: 0" width = 50 height = 50>
- <img src = "t1.jpg" id = "2" style = "position:absolute; left: 50; top: 0" width = 50 height = 50>
- <img src = "t1.jpg" id = "3" style = "position:absolute; left: 100; top: 0" width = 50 height = 50>
- <img src = "t1.jpg" id = "4" style = "position:absolute; left: 150; top: 0" width = 50 height = 50>
- <img src = "t1.jpg" id = "5" style = "position:absolute; left: 200; top: 0" width = 50 height = 50>
- <img src = "t1.jpg" id = "6" style = "position:absolute; left: 250; top: 0" width = 50 height = 50>
- <img src = "t1.jpg" id = "7" style = "position:absolute; left: 300; top: 0" width = 50 height = 50>
- <img src = "t1.jpg" id = "8" style = "position:absolute; left: 350; top: 0" width = 50 height = 50>
- <img src = "t1.jpg" id = "9" style = "position:absolute; left: 400; top: 0" width = 50 height = 50>
- <img src = "t1.jpg" id = "10" style = "position:absolute; left: 450; top: 0" width = 50 height = 50>
- <img src = "red.jpg" id = "pew" style = "position:absolute; left: 500; top: -50 " width = 3 height = 50 >
- <img src = "Shooter.jpg" name = "move" id = "player" style="left: 300; position:absolute; top: 500" width = 100 height = 100>
- </form>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement