Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- PImage dSenpai;
- PImage uslogo;
- PImage imgGameOver;
- PImage imgTextDoYouWanna;
- PImage initScreenBG;
- PImage playerL;
- PImage playerR;
- PImage indeks;
- PImage congratz;
- PImage usg;
- String[] tablica1 = {"", ""};
- Platforma platform;
- String pieklo = "";
- int screen = 0; //initial screen
- int platformWidth = 228, platformHeight = 216, platformSpeed = 3, platformDirection = 1; //platforma global variables
- int playerSize = 130, playerWidth = 70;
- int iloscWarunkow;
- boolean playerDirection;
- int playerSpeed = 14;
- float playerPosX = 0;
- float usX;
- boolean lost = false;
- ArrayList<Indeks> indeksy;
- int points;
- void setup()
- {
- size(476,533);
- fill(0);
- textSize(40);
- playerDirection = true;
- uslogo = loadImage("uslogo.png");
- uslogo.resize(uslogo.width/3, uslogo.height/3);
- dSenpai = loadImage("dSaw.png");
- imgTextDoYouWanna = loadImage("play a game.png");
- imgTextDoYouWanna.resize(imgTextDoYouWanna.width/2,imgTextDoYouWanna.height/2);
- imgGameOver = loadImage("survivalFail.png");
- initScreenBG = loadImage("initScreenBG.png");
- playerL = loadImage("pL.png");
- playerR = loadImage("pR.png");
- indeks = loadImage("indeks.png");
- congratz = loadImage("congratz.png");
- usg = loadImage("survivallogo.png");
- indeksy = new ArrayList<Indeks>();
- float rand = random(0,width); //set-up for platform
- float randX = rand>=width-platformWidth ? rand-platformWidth : rand;
- platform = new Platforma(randX, 0);
- points = 0;
- }
- void draw()
- {
- if(screen == 0)
- initScreen();
- else if(screen == 1)
- gameScreen();
- else if(screen == 2)
- gameOverScreen();
- else if(screen == 3)
- gameWonScreen();
- }
- void keyPressed()
- {
- if(key=='a')
- {
- playerDirection = false;
- if(playerPosX>0)
- playerPosX -= playerSpeed;
- }
- if(key=='d')
- {
- playerDirection = true;
- if(playerPosX<width-playerWidth*1.26)
- playerPosX += playerSpeed;
- }
- }
- public void mousePressed()
- {
- if(screen == 0)
- {
- points = 0;
- indeksy = new ArrayList<Indeks>();
- startSurvival();
- }
- else if(screen == 2 || screen == 3)
- screen = 0;
- //startSurvival();
- }
- //width/height
- //screen functions
- void initScreen()
- {
- points = 0;
- lost = false;
- background(0);
- tint(100,0,0);
- image(initScreenBG,0,0);
- tint(255,255);
- textAlign(CENTER);
- image(usg, 0,0);
- image(imgTextDoYouWanna, height/2-randomVal33(), width/2+imgTextDoYouWanna.width+randomVal33());
- drawTv();
- }
- void drawTv()
- {
- tint(randomVal75());
- image(dSenpai, 0, height-dSenpai.height);
- tint(255,255);
- }
- void gameScreen()
- {
- if(!lost && points <25)
- {
- background(255);
- textSize(10);
- text("Current objective: Survive || Points: " + points, width/2, height-50);
- line(0, 450, 533, 450);
- drawPlayer(playerPosX);
- if(random(0,200)<10)
- {
- indeksy.add(new Indeks());
- }
- for(Indeks i : indeksy)
- {
- if(!i.zlapany)
- {
- i.move();
- i.display();
- }
- }
- image(uslogo, usX,0);
- platform.display();
- platform.move();
- }
- else if (lost) youLost();
- else if (points > 24 && !lost) youWon();
- }
- void gameOverScreen()
- {
- image(imgGameOver,0,0);
- tekst("Przegrałeś || "+points+" punktów",width/2,25,255);
- }
- void gameWonScreen()
- {
- background(0);
- congratz.resize(476,533);
- image(congratz,0,0);//(width/2)-0.5*congratz.width,0
- }
- void tekst(String info, float x, float y, int bg)
- {
- color(bg,bg,bg);
- textSize(30);
- text(info, x, y);
- }
- void drawPlayer(float x)
- {
- fill(255,255,255);
- stroke(255,255,255);
- rect(x, 320,90,130-1);
- if(playerDirection)
- {
- playerR.resize(90,130);
- image(playerR,x,320);
- }
- else
- {
- playerL.resize(90,130);
- image(playerL,x,320);
- }
- stroke(0,0,0);
- }
- void startSurvival()
- {
- screen = 1;
- }
- void youLost()
- {
- screen = 2;
- }
- void youWon()
- {
- screen = 3;
- }
- float randomVal33()
- {
- return random(-3,3);
- }
- float randomVal75()
- {
- return random(75);
- }
- class Indeks
- {
- float x, y;
- boolean zlapany;
- Indeks()
- {
- x = usX;
- y = 0;
- zlapany = false;
- }
- void move()
- {
- y+=3.2;
- }
- void display()
- {
- collision();
- if(!zlapany)
- {
- checkIfPlayground();
- image(indeks,x,y,80,30);
- }
- }
- void checkIfPlayground()
- {
- if(y>=450)
- lost=true;
- }
- void collision()
- {
- float xd = x+(0.5*80);
- float yd = y+(0.5*30);
- if((xd>=playerPosX && xd<=playerPosX+playerL.width) && (yd>=320 && yd<=320+playerL.height))
- {
- points++;
- zlapany = true;
- }
- }
- }
- class Gracz
- {
- float x, y;
- Gracz(float x, float y)
- {
- rect(x,y,playerSize,playerWidth);
- }
- }
- class Platforma
- {
- //size
- float y;
- Platforma(float x, float y)
- {
- usX = x;
- this.y = y;
- }
- void display()
- {
- fill(255,0,0);
- //tutaj
- fill(0,0,0);
- }
- void move()
- {
- if(usX>=width-uslogo.width && platformDirection == 1 || usX<=0 && platformDirection == -1)
- platformDirection*= -1;
- usX+=platformSpeed*platformDirection;
- //(width/2)-(uslogo.width/2)
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement