Advertisement
Guest User

Untitled

a guest
Jan 21st, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var ovr=new Image();
  2. ovr.src = "overlay.png"
  3. //YOUR PLAYER COORDINATES
  4. var myX = 640, myY = 580;
  5. //BACKGROUND
  6. let BackGroundX = 0, BackGroundY = 0;
  7. //CYCLE VARIABLES
  8. var x, i, y;
  9. //BULET COORDINATES
  10. var MyBulletsX = [], MyBulletsY = [], broiPatroni=0;
  11. //LIVES & POINTS
  12. var lives = 1;
  13. var points=0;
  14. //ENEMY COORDINATES
  15. var vragX = [], vragY = [];
  16. //"TO BE CONTINUED" IMAGE & SOUND
  17. //sound
  18. var jojo;
  19. jojo = new sound("jojo.mp3");
  20. jojo.loop =false;
  21. //image
  22. var tbc = new Image();
  23. tbc.src = "tbc.png"
  24. //ENEMY IMAGE & SOUND
  25. var dank;
  26. dank = new sound("dank.mp3");
  27. //sound
  28. dank.loop = false;
  29. //image
  30. var vrag = new Image();
  31. vrag.src = "vrag.png";
  32. //BULLET IMAGE
  33. var bullet = new Image();
  34. bullet.src = "bullet.png"
  35. //BACKGROUND IMAGE
  36. var backgroundImage = new Image();
  37. backgroundImage.src = "da3.png";
  38. //PLAYER IMAGE
  39. var kartinageroi = new Image();
  40. kartinageroi.src = "player.png";
  41. for(x = 0; x < 10; x ++){
  42.     vragX[x] = Math.random()*1280 - 50;
  43.     vragY[x] = Math.random()*(-450) - 150;
  44. }
  45. //SOUND FUNCTION
  46. function sound(src) {
  47.     this.sound = document.createElement("audio");
  48.     this.sound.src = src;
  49.     this.sound.setAttribute("preload", "auto");
  50.     this.sound.setAttribute("controls", "none");
  51.     this.sound.style.display = "none";
  52.     document.body.appendChild(this.sound);
  53.     this.play = function(){
  54.         this.sound.play();
  55.     }
  56.     this.stop = function(){
  57.         this.sound.pause();
  58.     }
  59. }
  60. //end
  61.  
  62.  
  63. function update() {
  64.     //WHEN POINTS BECOME 10
  65.     //LIVES BECOME +1
  66.     if(points==10){
  67.         lives++
  68.         points=0
  69.     }
  70.     if(lives > 0){
  71.         jojo.stop();
  72.         for(i=0;i<broiPatroni;i++){
  73.         MyBulletsY[i] = MyBulletsY[i] - 5;
  74.         if(MyBulletsY[i]<0){
  75.             MyBulletsX.splice(i,1);
  76.             MyBulletsY.splice(i,1);
  77.             i--;
  78.             broiPatroni--;
  79.         }
  80.     }
  81.  
  82.     if(isKeyPressed[68]){
  83.         myX = myX + 8;
  84.        }
  85.     if(isKeyPressed[65]){
  86.         myX = myX - 8;
  87.        }
  88.     if(isKeyPressed[83]){
  89.        myY = myY + 8;
  90.        }
  91.     if(isKeyPressed[87]){
  92.        myY = myY - 8;
  93.     }
  94.        
  95.     if(myX >= 1250){
  96.         myX = 1250;
  97.     }
  98.     if(myX <= 0){
  99.        myX = 0;
  100.        }
  101.     if(myY >=570){
  102.        myY = 570
  103.        }
  104.     if(myY <= 0){
  105.         myY = 0;
  106.     }
  107.     for(x = 0; x < 10; x ++){
  108.      vragY[x] = vragY[x] + 2;
  109.         if(vragY[x] >= 600) {
  110.     vragX[x] = Math.random()*1100 - 50;
  111.     vragY[x] = Math.random()*(-20) -40;
  112.         }
  113.     }
  114.      for(x = 0; x < 10; x ++){
  115.          for(y = 0; y < broiPatroni; y ++){
  116.     if(areColliding(MyBulletsX[y], MyBulletsY[y], 15, 25, vragX[x], vragY[x], 40, 40)){
  117.         vragX[x] = Math.random()*1100 - 50;
  118.         vragY[x] = Math.random()*(-20) -40;
  119.         dank.play();
  120.         MyBulletsX.splice(i,1);
  121.         MyBulletsY.splice(i,1);
  122.         i--;
  123.         broiPatroni--;
  124.         points++
  125.                 }
  126.             }
  127.         }
  128.         for(x = 0; x < 10; x ++){
  129.         if(areColliding(myX, myY, 55, 70, vragX[x], vragY[x], 30, 30)){
  130.            lives --;
  131.             vragX[x] = Math.random()*1100 - 50;
  132.         vragY[x] = Math.random()*(-20) -40;
  133.            
  134.            }
  135.         }
  136.  
  137.     }else{
  138.         if(lives<=0){
  139.           jojo.play();
  140.         }else{
  141.         jojo.stop();
  142.         }
  143. }
  144.    
  145. }
  146.  
  147.  
  148. function draw() {
  149.     context.drawImage(backgroundImage, BackGroundX, BackGroundY, 1280, 660);
  150.     context.drawImage(kartinageroi, myX, myY, 55, 70);
  151.     for(x = 0; x < 10; x ++){
  152.         context.drawImage(vrag, vragX[x], vragY[x], 40, 40)
  153.     }
  154.     if(lives>0)
  155.     {   for(i=0;i<broiPatroni;i++){
  156.         context.drawImage(bullet, MyBulletsX[i], MyBulletsY[i], 15, 25)
  157.     }}
  158.      if(lives <= 0){
  159.         context.drawImage(tbc, 930, 538, 350, 100);
  160.          context.drawImage(ovr, 0, 0, 8000, 6000);
  161.     }
  162. context.font = "20px Comic Sans MS";
  163.                     context.fillText(points, 40, 40);
  164.     context.fillText(lives, 40, 60);
  165. };
  166.  
  167. function keyup(key) {
  168.     // Show the pressed keycode in the console
  169.     console.log("Pressed", key);
  170.      if(key == 32){
  171.         MyBulletsX[broiPatroni]=myX+10;
  172.         MyBulletsY[broiPatroni]=myY+50;
  173.         broiPatroni++;
  174.     }
  175. };
  176.  
  177. function mouseup() {
  178.     // Show coordinates of mouse on click
  179.     console.log("Mouse clicked at", mouseX, mouseY);
  180. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement