Das beste Galaxiespiel jetzt verfügbar!
Die viereckige Figur wandert durch den Weltraum und um nicht zu verlieren, muss man über die Hindernisse springen.
import processing.sound.*; //Deklariert die Variabeln für die Bilder PImage hintergrund; PImage cube; SoundFile spring; SoundFile explosion; //Derklariert den Variabel für den Font PFont font; //Setzt das Position der Figur float posX = 200; float posY = 500; //Höhe für alles relatives int y; //Geschwindigkeit der Hindernisse int geschwindigkeitHindernisse = 2; int score = 0; int phase = 0; // 0 = Anfang | 1 = Anleitung | 2 = Spiel | 3 = Endzustand | 4 = Gewinnzustand Boolean springen = false; //Ein Boolean um zu sehen ob der Charakter springt int acc = 0; //Deklariert eine Liste für die X Positione der Hindernisse FloatList hindernisseX; FloatList hindernisseHohe; void setup() { size(1300, 800); //Schriftart laden und setzen font = createFont("robotocondensed.ttf", 40); textFont(font); //Geräüsche Laden spring = new SoundFile(this, "spring.wav"); explosion = new SoundFile(this, "explosion.wav"); //Ladet die Bilder hintergrund = loadImage("Galaxie.png"); cube = loadImage("Cube.png"); //Erstellt eine neue Liste aus Floats hindernisseX = new FloatList(); hindernisseHohe = new FloatList(); //Fügt 10 Hindernisse in die Liste ein und nutzt Cosinus um die Höhen zu erstellen for(int i = 0; i<=5; i++) { hindernisseX.push(width/2 + i*400); hindernisseX.push(width/2 + i*500); hindernisseHohe.push(abs(cos(i*400)*80)); hindernisseHohe.push(abs(cos(i*500)*80)); } //Initialisiert die vorherige deklartierte Y Variabel y = 550; //Koordinaten von Bilder und Texte werden in die Mitte gesetzt imageMode(CORNER); textAlign(CENTER); } void draw() { //Verschiedene Zustände für verschiedene Phasen if (phase == 0) startscreen(); else if(phase == 1) anleitung(); else if (phase == 2) game(); else if (phase == 3) verloren(); else if (phase == 4) gewonnen(); } void keyPressed() { //stellt sicher dass es die 2. Phase ist if (phase == 2) { if (!springen && key == ' ') { //Spielt den Spring Geräüsch spring.play(); springen = true; acc -= 20; } } } void button(String text, int x, int y, int new_phase) { push(); //Speichert die aktuelle Zeichensstatus des Programs //Stellt die Dicke der Linie der Reckteck zu 4 Pixeln und Weiss rectMode(CENTER); strokeWeight(4); stroke(255); //Schaut ob die Maus innerhalb den Knopf ist und ob es gedrückt ist if(mouseX >= x - 200 && mouseX <= x + 200 && mouseY >= y - 50 && mouseY <= y + 50) { if(mousePressed) { phase = new_phase; } //Setzt die Linie zu grau stroke(100); } //Gibt es eine graue Farbe fill(200); rect(x, y-10, 400, 100); fill(0); text(text, x, y); pop(); //Stellt die gespeicherte Zeichensstatus wiederher } void startscreen() { background(hintergrund); textSize(100); fill(100); text("Galaxy Run", width/2, 200); textSize(40); button("START", width/2, 450, 2); button("HILFE", width/2, 600, 1); } void anleitung() { background(hintergrund); button("ZURÜCK", width/2, 200, 0); push(); rectMode(CENTER); fill(200); stroke(255); strokeWeight(4); rect(width/2, 500, 1100, 300); fill(0); text("Springe durch drücken dem ewigen Weltall zu entkommen.", width/2, 400); text("der Leertaste über die Hindernisse und versuche", width/2, 500); text("dem ewigen Weltall zu entkommen. Erreiche 50 Pünkte zu gewinnen", width/2, 600); pop(); } void game() { noStroke(); background(hintergrund); rectMode(CORNER); fill(50); //Den Grundbau was der Figur drauf rollt rect(0, y, width, height-y); fill(100); image(cube, posX, posY); if(springen) { posY += acc; acc += 1; } if(posY >= y - 50) { springen = false; posY = y - 50; acc = 0; } else if(!springen && posY <= y + 50) { posY += acc; acc += 1; } for(int i = 0; i<=hindernisseX.size()-1; i++) { rect(hindernisseX.get(i), y - hindernisseHohe.get(i), 50, hindernisseHohe.get(i)); if(posX + 50>= hindernisseX.get(i) && posX <= hindernisseX.get(i) + 50 && posY + 50 >= y - hindernisseHohe.get(i)) { acc = 0; if(posY + 50 > y - hindernisseHohe.get(i) + 20) { explosion.play(); reset(3); } springen = false; posY = y - hindernisseHohe.get(i) - 50; } hindernisseX.add(i, -geschwindigkeitHindernisse); //Fügt neue Hindernisse zu und löscht die alten if(hindernisseX.get(i) < -50) { hindernisseX.remove(i); hindernisseHohe.remove(i); hindernisseX.push(width + i*400); hindernisseHohe.push(abs(cos(i*400)*80)); score++; } } if(score >= 50) { reset(4); } geschwindigkeitHindernisse *= 1.1; fill(255); text(score, 40, 40); } void verloren() { background(hintergrund); textSize(100); fill(100, 50, 50); text("CRASHED", width/2, 300); textSize(50); button("MENU", width/2, 400, 0); button("Spielen", width/2, 600, 2); } void gewonnen() { background(hintergrund); textSize(100); fill(100, 200, 100); text("GEWONNEN", width/2, 300); textSize(50); button("MENU", width/2, 400, 0); button("Spielen", width/2, 600, 2); } //Setzt alles zurück void reset(int aktuellPhase) { //Erstellt eine neue Liste aus Floats hindernisseX = new FloatList(); hindernisseHohe = new FloatList(); score = 0; geschwindigkeitHindernisse = 2; //Geht durch die Liste der Hindernisse und erstellt neue X Koordinaten aus zufällige Zahlen + die Breite des Bildschirms for(int i = 0; i<=5; i++) { hindernisseX.push(width/2 + i*400); hindernisseX.push(width/2 + i*500); hindernisseHohe.push(abs(cos(i*400)*80)); hindernisseHohe.push(abs(cos(i*500)*80)); } phase = aktuellPhase; }