Advertisement
Guest User

Untitled

a guest
Mar 23rd, 2019
228
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.71 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4.     <title></title>
  5. </head>
  6. <body>
  7.     <canvas  style="border: 1px solid black" id="canvas"><
  8. <style type="text/css">
  9.   body{
  10.     padding:0;
  11.     margin: 0;
  12.   }
  13. </style>
  14. <script type="text/javascript">
  15.     var cvs = document.getElementById("canvas");
  16.     var ctx = cvs.getContext("2d");
  17.   cvs.width = window.innerWidth;
  18.   cvs.height = window.innerHeight;
  19.     var x = 0;
  20.     var y = cvs.height/1.5;
  21.     var bird = new Image();
  22.     var yPos = y-26;
  23.     var vPos = 5;
  24.     var g = 0.4;
  25.     var xPos = 20
  26.     var grd = ctx.createLinearGradient(0, 0, cvs.width, cvs.height);
  27.     bird.src = "flappy_bird_bird.png";
  28.     var rep = new Image();
  29.     rep.src = "reeat.png"
  30.     var score = 0;
  31.     var enemy = [];
  32.     var yR = 0;
  33.     enemy[0] = {
  34.         x:cvs.width,
  35.         y: cvs.height/1.5-50
  36.  
  37.     }
  38.   console.log('Рекорд',cvs.height);
  39.     function yourscore(){
  40.         ctx.font = "50px Verdana";
  41.         ctx.fillText("Счет: "+score,500,50);
  42.     }
  43.     function Enemes(){
  44.         for (var i = 0; i < enemy.length; i++){
  45.             ctx.beginPath();
  46.         ctx.fillStyle = "black";
  47.         ctx.fillRect(enemy[i].x, enemy[i].y-100, 50, 150)
  48.         enemy[i].x--;
  49.         yR = Math.random()*623;
  50.         if (enemy[i].x == 125) {
  51.             enemy.push({
  52.                 x : cvs.width,
  53.                 y : yR
  54.             })}
  55.             if(enemy[i].x==5){
  56.              score++;
  57.             }
  58.  
  59.             else if (xPos+bird.width>=enemy[i].x
  60.                 && xPos<= enemy[i].x +50
  61.                 && yPos + bird.height >= enemy[i].y-100
  62.                 && yPos <= enemy[i].y +150
  63.                 ){
  64.               ctx.font = "50px Verdana"
  65.               ctx.fillText("game over", 200,200)  
  66.               repeat()
  67.  
  68.               /*document.location.reload()*/
  69.             }
  70.  
  71.         }
  72.  
  73.  
  74.  
  75.         }
  76.         function zxc(){
  77.             Enemes()
  78.             Enemes()
  79.             Enemes()
  80.             Enemes()
  81.             Enemes()
  82.            
  83.  
  84.             Enemes()
  85.             Enemes()
  86.             Enemes()
  87.             Enemes()
  88.             Enemes()
  89.  
  90.             Enemes()
  91.             Enemes()
  92.             Enemes()
  93.             Enemes()
  94.             Enemes()
  95.             Enemes()
  96.  
  97.           requestAnimationFrame(zxc)
  98.       }
  99.      
  100.         requestAnimationFrame(zxc   )
  101.        
  102.  
  103.      
  104.         /*if (20 + bird.width >= enemy[i].x
  105.             && yPos + bird.height >= enemy[i].y){
  106.             location.reload()
  107.         }*/
  108. function repeat(){
  109. ctx.drawImage(rep, 10,10,100,100)
  110.  
  111. }
  112.  
  113.     function drawBird(){
  114.         ctx.clearRect(0, 0, cvs.width, cvs.height)
  115.         drawG();
  116.  
  117.         ctx.drawImage(bird, xPos, yPos);
  118.         draww();
  119.         yourscore()
  120. // function moveUp(){
  121. //         vPos = 10;
  122. //         vPos = -vPos;
  123. //     }
  124.  
  125.         yPos=yPos+vPos;
  126.         vPos=vPos+g;
  127.  
  128.  
  129.         if (yPos+bird.height < 0){
  130.             vPos=5;
  131.         }
  132.  
  133.         if (yPos+bird.height > y) {
  134.             yPos = y-bird.height
  135.         }
  136.         /*
  137.         else if(yPos-bird.height-50 <y-76){
  138.             yPos+2
  139.         }
  140.     */
  141.  
  142.     }
  143.     function drawG(){
  144.         grd.addColorStop(0, "purple")
  145.         grd.addColorStop(1, "pink")
  146.         ctx.fillStyle = grd;
  147.         ctx.fillRect(0, 0, cvs.width, cvs.height)
  148.     }
  149.     function draww(){
  150.         ctx.beginPath();
  151.         ctx.fillStyle = "black"
  152.         ctx.fillRect(0,y, cvs.width, 20)
  153.     }
  154.     document.addEventListener("keypress", moveUp)
  155.      //   document.addEventListener("keyup", moveDown)
  156.     function moveUp(){
  157.         vPos = 10;
  158.         vPos = -vPos;
  159.     }
  160.  
  161.   //  function moveDown(){
  162.   //    yPos+=50;
  163.    // }
  164.     setInterval(drawBird, 10);
  165.  
  166. </script>
  167. </body>
  168. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement