int score ; PImage img ; int Zustand = 0; //Spielbildschirm float [] Hoehe = new float [4]; // ermöglicht es, die Höhe zu randomizen float [] xPosRectangle = new float [4]; // ermöglicht es, 4 Obstacles zu haben float yPosCircle = 562.5; // Y-Position Kreis float xPosCircle = 150 ; // X-Position Kreis float circleRadius = 75 ; // Kreisradius float rectWidth = 50 ; //Breite der Rectangles float randomNumber = random(200, 250); // random Nummer (wird für die Höhe der Rectangles gebraucht /* Zustand = 0; Startbildschirm Zustand = 1; Spielanleitung Zustand = 2; Spiel (vor Anfang) Zustand = 3; Spiel (während Vorgang) Zustand = 4; Game Over */ void setup () { frameRate (30) ; size (800, 600) ; img = loadImage ("space.jpeg") ; // Bildquelle ; https://wallpapercave.com/wp/3wPVPxQ.jpg PFont myFont = createFont ("Georgia", 32); textFont(myFont); Hoehe [0] = randomNumber; // randomized Höhen der Rectangles Hoehe [1] = randomNumber; Hoehe [2] = randomNumber; Hoehe [3] = randomNumber; xPosRectangle [0] = random(width, width - 50); // randomized Abstand zwischen Rectangles xPosRectangle [1] = random(width + 375, width + 425); xPosRectangle [2] = random(width + 200, width + 250); xPosRectangle [3] = random(width + 550, width + 700); } void draw () { if (Zustand == 0) { // Startbildschirm background (100, 100, 155) ; fill(255); textSize (40) ; text ("Willkommen bei", 240, 150) ; text ("SpacePearl !", 280, 230) ; textSize (20) ; text ("Drücke 'a', um zur Spielanleitung zu gelangen.", 60, 400) ; text ("Drücke 's', um das Spiel zu starten.", 60, 440) ; if(keyPressed) { if(key == 'a') { Zustand = 1; } else if (key == 's') { Zustand = 2; } } } else if (Zustand == 1) { // Spielanleitung background (100, 100, 155) ; fill(255); textSize (15) ; text ("Drücke 'b' um wieder zum Startbildschirm zu gelangen.", 30, 60) ; text ("Drücke 's', um zum Spielstart zu gelangen.", 30, 38) ; textSize (40) ; text ("- Spielanleitung -", 250, 150) ; textSize (20); text ("Deine Spielfigur ist ein Kreis der Farbe Lila. Von rechts nach links werden", 80, 200) ; text ("Rechtecke von verschiedenen Grössen geschoben und deine Aufgabe ist es,", 80, 220) ; text ("deinen Kreis durch die Abstände der Rechtecke zu manövrieren, ohne", 80, 240) ; text ("jene zu berühren. Kommst du mit einem der Rechtecke in Berührung, ist", 80, 260); text ("das Spiel vorbei. Den Kreis lenkst du mit der Leertaste; ist sie gedrückt,", 80, 280) ; text ("verschiebt sich der Kreis nach oben, sobald die Leertaste nicht mehr gedrückt", 80, 300) ; text ("ist, verschiebt er sich automatisch wieder nach unten. Recht simpel, oder ?", 80, 320) ; text ("Ausserdem wird dir oben rechts in der Ecke die Anzahl erfolgreich", 80, 340) ; text ("überwundene Hindernisse angezeigt (=Score)", 80, 360) ; if(keyPressed) { if(key == 'b') { Zustand = 0; } if(key == 's') { Zustand = 2; } } } else if (Zustand == 2) { // Spielstart image (img, 0, 0, width, height) ; // background //background(100, 100, 155) ; fill(255); textSize (40) ; text ("Drücke die Leertaste und das Spiel beginnt !!", 30, 150) ; textSize (15) ; text ("Mit 'b' gelangst du wieder zurück zum Startbildschirm.", 30, 60) ; text ("Mit 'a' kannst du dir die Anleitung nochmals durchlesen.", 30, 38) ; if(keyPressed) { if(key == 'b') { Zustand = 0; } if(key == 'a') { Zustand = 1; } if(key == ' ') { Zustand = 3; } } stroke(255) ; strokeWeight(2) ; fill(#AB8CF0); circle(xPosCircle, yPosCircle, circleRadius); } else if (Zustand == 3) { // Spiel (während Vorgang) image (img, 0, 0, width, height) ; // background //background(100,100,155); stroke(255); strokeWeight(2); fill(#887FF2); for (int i = 0; i < 2; i++) { //Rectangles von unten rect(xPosRectangle [i], height-Hoehe[i], rectWidth, Hoehe[i]); xPosRectangle [i] -= 6; // if(xPosRectangle [i] <= -50) { xPosRectangle [i] = random(width, width + 50); Hoehe[i] = randomNumber; score++; // erhöht den Score (+1, weil man 1 Hindernis überwunden hat) } if (xPosCircle + 75/2 >= xPosRectangle [i]) {//Kolission für Rectangles unten if(yPosCircle + 75/2 >= height - Hoehe[i]) { Zustand = 4; } if (xPosCircle - 75/2 >= xPosRectangle[i]) { Zustand = 3; } } } for (int i = 2; i < 4; i++) { //Rectangles von oben stroke(255); strokeWeight(2); fill(#887FF2); rect(xPosRectangle [i], 0, rectWidth, Hoehe[i]); xPosRectangle [i] -= 6; // if(xPosRectangle [i] < -50) { xPosRectangle [i] = random(width, width + 50); Hoehe[i] = randomNumber; score ++ ; // erhöht den Score (gleich wie oben) } if (xPosCircle + 75/2 >= xPosRectangle [i]) { if(yPosCircle - 75/2 <= Hoehe [i]) { Zustand = 4; } if (xPosCircle - 75/2 >= xPosRectangle [i]) { Zustand = 3; } } } stroke(255); strokeWeight(2) ; fill(#AB8CF0); circle(xPosCircle, yPosCircle, circleRadius); if (keyPressed && key == ' ') { yPosCircle -= 10; } yPosCircle += 4; if(yPosCircle >= height-75/2) { yPosCircle = height-75/2; } if(yPosCircle <= 75/2) { yPosCircle = 75/2; } fill(255); textSize(20); text("Score = " + score, 700, 80); } else if (Zustand == 4) { // Game-Over-Bildschirm background(100,100,155); text("Game Over", 350, 300); text("Drücke 's', um wieder zum Spielstart zu gelangen.", 200, 350); //setzt alles auf Originalposition Hoehe [0] = randomNumber; // randomized Höhen der Rectangles Hoehe [1] = randomNumber; Hoehe [2] = randomNumber; Hoehe [3] = randomNumber; xPosRectangle [0] = random(width, width - 50); // randomized Abstand zwischen Rectangles xPosRectangle [1] = random(width + 375, width + 425); xPosRectangle [2] = random(width + 200, width + 250); xPosRectangle [3] = random(width + 550, width + 700); score = 0; yPosCircle = 562.5; // Y-Position Kreis xPosCircle = 150 ; // X-Position Kries if(keyPressed && key == 's') { Zustand = 2; } } }