-Fungillume-

              
//Videospiel Pr1ojekt
//Mitglieder: Jael Lehner, Anina Hischier, Chrotinelle (Anna)
//Projektbeginn: 23.März.2023
int Zustand = 0; // Anfangsbildschirm
/*
Zustand = 1 -> Vorgeschichte
Zustand = 2 -> Gamestart
Zustand = 3 -> Während Spiel
Zustand = 4 -> Spiel verloren
Zustand = 5 -> Spiel gewonnen
*/
//Korbbild Quelle: https://creazilla.com/de/nodes/57890-korb-clipart

PImage Korb; //Korb, welcher gesteuert wird
PImage Hintergrund; //Hintergrund während Spiel
PImage Verlierhintergrund; //Hintergrund, wenn man verliert
PImage Gewinn; //Hintergrund, wenn man gewinnt

import processing.sound.*; //für Musik
SoundFile Maintheme; //Quelle: https://pixabay.com/music/search/cute%20music/?manual_search=1&order=None
SoundFile Lose; //Quelle: https://pixabay.com/music/search/creepy%20music/?manual_search=1&order=None
SoundFile Win; //Quelle: https://pixabay.com/music/search/victory/

int score = 0; //Punkte die man gesammelt hat

//Korb:
int xPos = 360; //Position des Korbes, welcher bewegt werden kann
float xSpeed = 5; //Geschwindigkeit des Korbs, erhöht sich bei gewissen Mengen an Punkten / float ermöglicht prozentual gleiche Geschwindigkeitsunterschied zu haben, wenn Geschwindigkeit höher oder tiefer ist

//Pilze
PImage [] Pilz = new PImage[4]; //Pilze die man im Spiel sieht
PImage [] bild = new PImage[8]; //Bilder für Pilze, Pilzbilder randomizable
int [] xPilz = new int[4]; //x-Position der Pilze randomizable
int [] yPilz = new int[4]; //y-Position der Pilze randomizable
float PilzSpeed = 2; //Gesch. der Pilze, erhöht sich bei gewissen Mengen and Punkten
int breite = 95;
int höhe = 120;
int pilzpunkt = 5; //ermöglicht es, bei höherer Gesch. mehr Punkte zu geben


void setup() {
  size(900,1000);
  fill(255); //Textfarbe
  textAlign(CENTER);
  
  Maintheme = new SoundFile(this, "test.mp3"); //Musik während dem Spiel
  Lose = new SoundFile(this, "lose.mp3"); //Musik, wenn man verliert
  Win = new SoundFile(this, "win.mp3"); //Musik, wenn man gewinnt
  
  //x- und y-Position für erste Runde ranomizen
  xPilz [0] = int (random(150,750));
  xPilz [1] = int (random(150,750));
  xPilz [2] = int (random(150,750));
  xPilz [3] = int (random(150,750));
  
  yPilz [0] = int (random(-300,-200));
  yPilz [1] = int (random(-500,-400));
  yPilz [2] = int (random(-700,-600));
  yPilz [3] = int (random(-900,-800));

  
  //Bilder
  bild[0] = loadImage("Pilz1.png");
  bild[1] = loadImage("Pilz2.png");
  bild[2] = loadImage("Pilz3.png");
  bild[3] = loadImage("Pilz4.png");
  bild[4] = loadImage("Pilz5.png");
  bild[5] = loadImage("Pilz6.png");
  bild[6] = loadImage("Pilz7.png");
  bild[7] = loadImage("Pilz8.png");
  Korb = loadImage("Korb.png");
  Hintergrund = loadImage("Hintergrund.jpg");
  Verlierhintergrund = loadImage("Verlierhintergrund.jpg");
  Gewinn = loadImage("Gewinn.jpg");
  
  //Bilder für erse Runde randomizen
  Pilz [0] = bild[int (random (0,8))];
  Pilz [1] = bild[int (random (0,8))];
  Pilz [2] = bild[int (random (0,8))];
  Pilz [3] = bild[int (random (0,8))];
  
  frameRate(60);
  //breite der Pilze
}

void draw() {
  if(Zustand == 0) { //Startbildschirm
    background(#5a7d5c);
    textSize(50);
    text("Welcome to -Fungillume-",width/2,500);
    textSize(30);
    text("Press ENTER to start", width/2,750);
    if(keyPressed && key == ENTER) { //Spiel starten
      Zustand = 1;
    }
  }
  
  else if(Zustand == 1) { //Vorgeschichte und Spielerklärung
    background(#5a7d5c);
    textSize(30);
    //Vorgeschichte
    text("You're a young girl from a small village.", width/2,230);
    text("Your people have been worried about the upcoming winter.", width/2, 270);
    text("They did not prepare enough resources to last throughout it.", width/2, 310);
    text("The shaman has sent you to the forest to collect mushrooms.", width/2, 350);
    text("Collect enough mushrooms for your village or they will die.", width/2, 390);
    //Erklärung wie Spiel funktioniert
    textSize(35);
    text("Instructions:", width/2, 510);
    textSize(20);
    text("Use 'a' and 'd' to move left and right.", width/2, 700);
    text("Catch the mushrooms that fall down with your basket.", width/2, 730);
    image(bild[0], width/2 - breite/2, 535, breite, höhe);
    textSize(30);
    text("Press SPACE to continue.", width/2, 820);
    if(keyPressed && key == ' ') {
      Zustand = 2;
    }
  }
  
  else if(Zustand == 2) { //Gamestart
//    background(#9ebaa0);
    Win.stop(); //damit die Musik nicht weiterspielt
    Lose.stop(); //damit die Musik nicht weiterspielt
    image(Hintergrund, -200, -200, 1300, 1400); //Hintergrund des Spiels
    image(Korb, width/2-90, 800, 180, 140); //Startposition des Korbs
    fill(255); //Textfarbe schwarz
    textSize(40);
    text("Score: "+ score , 800,100); //Score
    textSize(30);
    text("press ENTER to start the game", width/2, 500);
    if(keyPressed && key == ENTER) { //ändert von Gamestart zum Spielvorgang
      Zustand = 3;
    }
  }
  
  else if(Zustand == 3) {
//   background(#9ebaa0);
     if(!Maintheme.isPlaying()) {
      Maintheme.loop();
     }
    image(Hintergrund, -200, -200, 1300, 1400); //Hintergrund des Spiels
    image(Korb, xPos, 800, 180, 140); //Korb der bewegt wird
    textSize(40);
    fill(255);
    text("Score: "+ score, 800, 100); //Punktemenge: erhöht sich, wenn man Pilze fängt
    if(keyPressed && key == 'a') { //Korb nach links bewegen
      xPos -= xSpeed;
    }
    if(keyPressed && key == 'd') { //Korb nach rechts bewegen
      xPos += xSpeed;
    }
    for(int i=0; i < 4;i++) { 
      image(Pilz [i], xPilz [i], yPilz [i], breite, höhe); //Pilz wird oberhalb des Spielblickes generiert
      yPilz [i] += PilzSpeed; //Pilz bewegt sich nach unten
      if(yPilz [i] >= 700 && yPilz [i] <= 800) { //Wenn mit Korb Pilz einfängt -> Pilz geht oberhalb von Spielblick, verändert Bild + x-Position
        if(xPilz[i] >= xPos && xPilz[i] + breite <= xPos +180) {
          Pilz[i] = bild[int (random(0,8))]; //Bild random
          xPilz[i] = int (random(150,750)); //x-Position random
          yPilz[i] = int (random(-250,-200)); //Höhe random
          score += pilzpunkt; //Punkte werden hinzugefügt
        }
      }
      if(yPilz[i] > 800) { //Wenn Korb nicht Pilz einfängt
        Zustand = 4; //geht zu Verlierbildschirm
      }
    }
    if(score >= 20) { //Spiel wird schneller + mehr Punkte
      pilzpunkt = 10;
      PilzSpeed = 3;
      xSpeed = 7.5;
    }
    if(score >= 60) { //Spiel schneller + mehr Punkte
      pilzpunkt = 15;
      PilzSpeed = 4;
      xSpeed = 10;
    }
    if(score >= 120) { //Spiel schneller + mehr Punkte
      pilzpunkt = 20;
      PilzSpeed = 5;
      xSpeed = 12.5;
    }
    if(score >= 200) { //Spiel gewinnen, geht zu Gewinnbildschirm
      Zustand = 5;
    }
  }
  
  else if(Zustand == 4) { //Bildschirm, wenn man verliert
    Maintheme.stop(); //damit die Musik nicht weiterspielt
    if(!Lose.isPlaying()) {
      Lose.loop();
     }
    image(Verlierhintergrund, 0, 0, 900, 1000);
    fill(0); //man sieht den Text dadurch besser
    textSize(35);
    text("You have lost.", width/2, 200);
    text("Your village died.", width/2, 240);
    text("You couldn't catch enough mushrooms for them.", width/2, 280);
    text("They won't frogive you.", width/2, 320);
    text("They'll haunt you as ghosts.", width/2, 360);
    textSize(25);
    text("Press SPACE to try again.", width/2, 450);
    xPos = 360; //alles reseten
    score = 0;
    PilzSpeed = 2;
    xSpeed = 5;
    pilzpunkt = 5;
    
    xPilz [0] = int (random(150,750)); //x-Position nochmals randomizen
    xPilz [1] = int (random(150,750));
    xPilz [2] = int (random(150,750));
    xPilz [3] = int (random(150,750));
  
    yPilz [0] = int (random(-300,-200)); //Pilze wieder oberhalb setzen
    yPilz [1] = int (random(-500,-400));
    yPilz [2] = int (random(-700,-600));
    yPilz [3] = int (random(-900,-800));

    Pilz [0] = bild[int (random (0,8))]; //Bilder der Pilze nochmals randomizen
    Pilz [1] = bild[int (random (0,8))];
    Pilz [2] = bild[int (random (0,8))];
    Pilz [3] = bild[int (random (0,8))];
    if(keyPressed && key == ' ') { //geht zurück zu Gamestart
      Zustand = 2;
    }
  }
  
  else if(Zustand == 5) { //Bildschirm, wenn man gewinnt
    Maintheme.stop(); //damit die Musik nicht weiterspielt
    if(!Win.isPlaying()) {
      Win.loop();
     }
//    background (175);
    image(Gewinn, 0, -150, 900, 1200);
    textSize(40);
    fill(#bc9005);
    text("You have won, congratulations!", width/2, 200);
    text("Your village has survived... for now.", width/2, 250);
    text("The Fungillume is congratulating you.", width/2, 300);
    textSize(30);
    text("Press Space to play again", width/2, 450);
    
    xPos = 360; //alles reseten
    score = 0;
    PilzSpeed = 2;
    xSpeed = 5;
    pilzpunkt = 5;
    
    xPilz [0] = int (random(150,750)); //x-Position nochmals randomizen
    xPilz [1] = int (random(150,750));
    xPilz [2] = int (random(150,750));
    xPilz [3] = int (random(150,750));
  
    yPilz [0] = int (random(-300,-200)); //Pilze wieder oberhalb setzen
    yPilz [1] = int (random(-500,-400));
    yPilz [2] = int (random(-700,-600));
    yPilz [3] = int (random(-900,-800));

    Pilz [0] = bild[int (random (0,8))]; //Bilder der Pilze nochmals randomizen
    Pilz [1] = bild[int (random (0,8))];
    Pilz [2] = bild[int (random (0,8))];
    Pilz [3] = bild[int (random (0,8))];
    if(keyPressed && key == ' ') { //geht zurück zum Spielstart
      Zustand = 2;
    }
  }
  if(xPos <= 0) { //Damit Korb links nicht heraus gehen kann
    xPos = 0;
  }
  if(xPos >= width - 180) { //Korb rechts nicht aus Bildschirm
    xPos = width - 180;
  }
}