Advertisement
Nakumas

UŚ Survival processing

Jun 3rd, 2019
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5.17 KB | None | 0 0
  1. PImage dSenpai;
  2. PImage uslogo;
  3. PImage imgGameOver;
  4. PImage imgTextDoYouWanna;
  5. PImage initScreenBG;
  6. PImage playerL;
  7. PImage playerR;
  8. PImage indeks;
  9. PImage congratz;
  10. PImage usg;
  11.  
  12. String[] tablica1 = {"", ""};
  13. Platforma platform;
  14. String pieklo = "";
  15. int screen = 0; //initial screen
  16. int platformWidth = 228, platformHeight = 216, platformSpeed = 3, platformDirection = 1; //platforma global variables
  17. int playerSize = 130, playerWidth = 70;
  18. int iloscWarunkow;
  19. boolean playerDirection;
  20. int playerSpeed = 14;
  21. float playerPosX = 0;
  22. float usX;
  23. boolean lost = false;
  24. ArrayList<Indeks> indeksy;
  25. int points;
  26.  
  27.  
  28. void setup()
  29. {
  30.   size(476,533);
  31.   fill(0);
  32.   textSize(40);
  33.  
  34.   playerDirection = true;
  35.   uslogo = loadImage("uslogo.png");
  36.   uslogo.resize(uslogo.width/3, uslogo.height/3);
  37.   dSenpai = loadImage("dSaw.png");
  38.   imgTextDoYouWanna = loadImage("play a game.png");
  39.   imgTextDoYouWanna.resize(imgTextDoYouWanna.width/2,imgTextDoYouWanna.height/2);
  40.   imgGameOver = loadImage("survivalFail.png");
  41.   initScreenBG = loadImage("initScreenBG.png");
  42.   playerL = loadImage("pL.png");
  43.   playerR = loadImage("pR.png");
  44.   indeks = loadImage("indeks.png");
  45.   congratz = loadImage("congratz.png");
  46.   usg = loadImage("survivallogo.png");
  47.  
  48.   indeksy = new ArrayList<Indeks>();
  49.  
  50.  
  51.   float rand = random(0,width); //set-up for platform
  52.   float randX = rand>=width-platformWidth ? rand-platformWidth : rand;
  53.   platform = new Platforma(randX, 0);
  54.   points = 0;
  55. }
  56.  
  57. void draw()
  58. {
  59.   if(screen == 0)
  60.     initScreen();
  61.   else if(screen == 1)
  62.      gameScreen();
  63.   else if(screen == 2)
  64.     gameOverScreen();
  65.   else if(screen == 3)
  66.     gameWonScreen();
  67. }
  68.  
  69. void keyPressed()
  70. {
  71.   if(key=='a')
  72.   {
  73.     playerDirection = false;
  74.     if(playerPosX>0)
  75.       playerPosX -= playerSpeed;
  76.      
  77.   }
  78.   if(key=='d')
  79.   {
  80.     playerDirection = true;
  81.     if(playerPosX<width-playerWidth*1.26)
  82.       playerPosX += playerSpeed;
  83.   }
  84.  
  85. }
  86.  
  87. public void mousePressed()
  88. {
  89.   if(screen == 0)
  90.   {
  91.     points = 0;
  92.     indeksy = new ArrayList<Indeks>();
  93.     startSurvival();
  94.   }
  95.   else if(screen == 2 || screen == 3)
  96.     screen = 0;
  97.     //startSurvival();
  98. }
  99. //width/height
  100. //screen functions
  101. void initScreen()
  102. {
  103.   points = 0;
  104.   lost = false;
  105.   background(0);
  106.   tint(100,0,0);
  107.   image(initScreenBG,0,0);
  108.   tint(255,255);
  109.   textAlign(CENTER);
  110.   image(usg, 0,0);
  111.   image(imgTextDoYouWanna, height/2-randomVal33(), width/2+imgTextDoYouWanna.width+randomVal33());
  112.   drawTv();
  113. }
  114. void drawTv()
  115. {
  116.   tint(randomVal75());
  117.   image(dSenpai, 0, height-dSenpai.height);
  118.   tint(255,255);
  119. }
  120. void gameScreen()
  121. {
  122.   if(!lost && points <25)
  123.   {
  124.     background(255);
  125.     textSize(10);
  126.     text("Current objective: Survive || Points: " + points, width/2, height-50);
  127.    
  128.     line(0, 450, 533, 450);
  129.     drawPlayer(playerPosX);
  130.     if(random(0,200)<10)
  131.     {
  132.       indeksy.add(new Indeks());
  133.     }
  134.    
  135.     for(Indeks i : indeksy)
  136.     {
  137.       if(!i.zlapany)
  138.       {
  139.         i.move();
  140.         i.display();
  141.       }
  142.     }
  143.     image(uslogo, usX,0);
  144.     platform.display();
  145.     platform.move();
  146.   }
  147.   else if (lost) youLost();
  148.   else if (points > 24 && !lost) youWon();
  149.  
  150. }
  151.  
  152. void gameOverScreen()
  153. {
  154.   image(imgGameOver,0,0);
  155.   tekst("Przegrałeś || "+points+" punktów",width/2,25,255);
  156. }
  157.  
  158. void gameWonScreen()
  159. {
  160.   background(0);
  161.   congratz.resize(476,533);
  162.   image(congratz,0,0);//(width/2)-0.5*congratz.width,0
  163. }
  164.  
  165. void tekst(String info, float x, float y, int bg)
  166. {
  167.   color(bg,bg,bg);
  168.   textSize(30);
  169.   text(info, x, y);
  170. }
  171.  
  172. void drawPlayer(float x)
  173. {
  174.   fill(255,255,255);
  175.   stroke(255,255,255);
  176.   rect(x, 320,90,130-1);
  177.   if(playerDirection)
  178.   {
  179.     playerR.resize(90,130);
  180.     image(playerR,x,320);
  181.   }
  182.   else
  183.   {
  184.     playerL.resize(90,130);
  185.     image(playerL,x,320);
  186.   }
  187.  
  188.   stroke(0,0,0);
  189. }
  190.  
  191. void startSurvival()
  192. {
  193.   screen = 1;
  194. }
  195.  
  196. void youLost()
  197. {
  198.   screen = 2;
  199. }
  200.  
  201. void youWon()
  202. {
  203.   screen = 3;
  204. }
  205.  
  206. float randomVal33()
  207. {
  208.   return random(-3,3);
  209. }
  210.  
  211. float randomVal75()
  212. {
  213.   return random(75);
  214. }
  215.  
  216. class Indeks
  217. {
  218.   float x, y;
  219.   boolean zlapany;
  220.   Indeks()
  221.   {
  222.     x = usX;
  223.     y = 0;
  224.     zlapany = false;
  225.   }
  226.   void move()
  227.   {
  228.     y+=3.2;
  229.   }
  230.   void display()
  231.   {
  232.     collision();
  233.     if(!zlapany)
  234.     {
  235.       checkIfPlayground();
  236.       image(indeks,x,y,80,30);
  237.     }
  238.   }
  239.   void checkIfPlayground()
  240.   {
  241.     if(y>=450)
  242.       lost=true;
  243.   }
  244.  
  245.   void collision()
  246.   {
  247.     float xd = x+(0.5*80);
  248.     float yd = y+(0.5*30);
  249.     if((xd>=playerPosX && xd<=playerPosX+playerL.width) && (yd>=320 && yd<=320+playerL.height))
  250.     {
  251.       points++;
  252.       zlapany = true;
  253.     }
  254.   }
  255.  
  256. }
  257.  
  258. class Gracz
  259. {
  260.   float x, y;
  261.   Gracz(float x, float y)
  262.   {
  263.     rect(x,y,playerSize,playerWidth);
  264.   }
  265. }
  266.  
  267. class Platforma
  268. {
  269.   //size
  270.   float y;
  271.   Platforma(float x, float y)
  272.   {
  273.     usX = x;
  274.     this.y = y;
  275.   }
  276.   void display()
  277.   {
  278.     fill(255,0,0);
  279.     //tutaj
  280.     fill(0,0,0);
  281.   }
  282.   void move()
  283.   {
  284.     if(usX>=width-uslogo.width && platformDirection == 1 || usX<=0 && platformDirection == -1)
  285.       platformDirection*= -1;
  286.       usX+=platformSpeed*platformDirection;
  287.       //(width/2)-(uslogo.width/2)
  288.   }
  289. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement