SHARE
TWEET

egor

a guest Dec 15th, 2018 52 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. int Xcar=0, repeatY=0; //Координаты машины
  2. float  blockX=58, blockY=0;   //Препядствие
  3. float  blockZ=58, blockC=0;
  4. float  blockU=58, blockI=0;
  5. int score=0;
  6. int NUMline=0;
  7. float r=0.0;
  8. PImage imgUP, imgLEFT, imgRIGHT;
  9. PImage imgCAR;
  10. PImage imgTREE;
  11. PImage imgGameOver;
  12. PImage title1, title2, text1, text2;
  13. //==============================================
  14.  
  15. void setup()
  16. {
  17.   size(1080, 800);  //1080x1600
  18.   frameRate(10);
  19.  
  20.   title1 = loadImage("title_1.png");
  21.   title2 = loadImage("title_2.png");
  22.   text1 = loadImage("text_1.png");
  23.   text2 = loadImage("text_2.png");
  24.  
  25.   //Машины 400х400px
  26.   imgUP = loadImage("car_1_300x300_UP.png");
  27.   imgLEFT = loadImage("car_1_300x300_LEFT.png");
  28.   imgRIGHT = loadImage("car_1_300x300_RIGHT.png");
  29.   Xcar=0;
  30.   r=0;
  31.  
  32.   imgCAR = loadImage("car_2_300x300_UP.png");
  33.  
  34.   //Карта
  35.   imgTREE = loadImage("palm_1_300x300.png");
  36.  
  37.   //Game over 600x600px
  38.   imgGameOver = loadImage("game_over.png");
  39.  
  40.   object1 = new MapObjectsBackground(-400, imgTREE);
  41.   object2 = new MapObjectsBackground(-800, imgTREE);
  42.   object3 = new MapObjectsBackground(-1200, imgTREE);
  43.   object4 = new MapObjectsBackground(-1600, imgTREE);
  44.  
  45.   line1 = new MapObjectsRoad(0);
  46.   line2 = new MapObjectsRoad(-300);
  47.   line3 = new MapObjectsRoad(-600);
  48.   line4 = new MapObjectsRoad(-900);
  49.   line5 = new MapObjectsRoad(-1200);
  50.  
  51.  
  52. }
  53.  
  54. void draw()
  55. {
  56.  
  57.   //КАРТА
  58.   //background(random(200, 255), random(0, 200), random(200, 255));
  59.   background(11, 124, 23);
  60.  
  61.   fill(30);
  62.   rect(216, 0, 216*3, 1600);
  63.  
  64.   //РАЗМЕТКА
  65.   stroke(255, 205, 0);
  66.   strokeWeight(10);
  67.   line(216, 0, 216, 1600);
  68.   line(216*4, 0, 216*4, 1600);
  69.  
  70.   line1.move();
  71.   line2.move();
  72.   line3.move();
  73.   line4.move();
  74.   line5.move();
  75.  
  76.   //ДЕРЕВЬЯ
  77.   object1.move();
  78.   object2.move();
  79.   object3.move();
  80.   object4.move();
  81.  
  82.   //ПРЕПЯДСТВИЕ 1
  83.   float hitX = blockX-100, hitY = blockY+280; //хитбокс препядствия
  84.   fill(0, 0, 0, 0);
  85.   noStroke();
  86.   rect(blockX-100, blockY+280, 200, 20);
  87.  
  88.   pushMatrix();
  89.   translate(216, 0);
  90.   fill(230);
  91.   image(imgCAR, blockX, blockY);
  92.   //rect(blockX, blockY, 100, 300);
  93.   blockY+=20;
  94.   if (blockY > height)
  95.   {
  96.       blockY=-300;
  97.       blockX=round(random(0, 2))*216+58;
  98.        score++;
  99.   }
  100.   popMatrix();
  101.    
  102.    pushMatrix();
  103.   translate(216, 0);
  104.   fill(230);
  105.   image(imgCAR, blockZ, blockC);
  106.   //rect(blockX, blockY, 100, 300);
  107.   blockC+=20;
  108.   if (blockC > height)
  109.   {
  110.       blockC=-300;
  111.       blockZ=round(random(0, 2))*216+58;
  112.       score++;
  113.   }
  114.   popMatrix();
  115.  
  116.   pushMatrix();
  117.     translate(390, 500);
  118.    
  119.     //Влево
  120.   if (keyPressed)
  121.   {
  122.     if (key == 'a' || key == 'A' || key == 'ф' || key == 'Ф')
  123.     {
  124.       Xcar-=10;
  125.         image(imgLEFT, Xcar, 0);
  126.     }
  127.   }
  128.  
  129.   //Вправо
  130.     if (keyPressed)
  131.   {
  132.     if (key == 'd' || key == 'D' || key == 'в' || key == 'В')
  133.     {
  134.       Xcar+=10;
  135.         image(imgRIGHT, Xcar, 0);
  136.     }
  137.   }
  138.   else
  139.   {
  140.     image(imgUP, Xcar, 0);
  141.   }
  142.   popMatrix();
  143.  
  144.  
  145.   //СТОЛКНОВЕНИЯ
  146.   if (Xcar < -240 || Xcar > 240)
  147.   {
  148.     image(imgGameOver, 240, 500);
  149.     frameRate(1);
  150.   }
  151.   if (Xcar >= (hitX-250) && Xcar <= (hitX-100) && hitY==1300)
  152.   {
  153.     image(imgGameOver, 240, 500);
  154.     frameRate(1);
  155.   }
  156.   textSize(30);
  157. fill(255,0,0);
  158. text(score/2, 10,30);
  159.   //МЕНЮ
  160.  
  161. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top