//Musik (Library)
import ddf.minim.spi.*;
import ddf.minim.signals.*;
import ddf.minim.*;
import ddf.minim.analysis.*;
import ddf.minim.ugens.*;
import ddf.minim.effects.*;
//Musik
Minim minim;
AudioPlayer dou;
AudioPlayer pou;
//
final int TOP_BORDER_PLAYER = 0; // PIXEL from the middle to the top position
// states
final int stateMenu = 0;
final int Start = 1;
final int Steuerung = 2;
int state = stateMenu;
//
// IMAGES
PImage backgroundObjects;
PImage backg;
PImage meteor;
PImage peachy;
//
// Coordinates
int y = 0,
x = 0;
// ----------------------------------------------------------------------
// main functions
void setup()
{
// runs only once
//
size(500, 500);
smooth();
font = createFont("ARCARTER-78.vlw", 14);
textFont(font);
//Musik(eigene Musik)
minim = new Minim(this);
dou = minim.loadFile("SoundtrackNeu.mp3");
dou.loop();
//backgroundObjects
backgroundObjects = loadImage("objects.png");
backg = loadImage("backg.png");
meteor = loadImage("peachymeteor.png");
peachy = loadImage ("peachy.png");
} // func
// the main routine. It handels the states.
// runs again and again
switch (state) {
case stateMenu:
showMenu();
break;
case Start:
background(255);
displayBackground(); //handleStart();
hitTest();
displayPlayer();
displayHighScore();
break;
case Steuerung:
handleSteuerung();
break;
default:
println ("Unknown state (in draw) "
+ state
+ " ++++++++++++++++++++++");
exit();
break;
}
playerControl();
} // func
// ----------------------------------------------------------------
// keyboard functions
void keyPressed() {
// keyboard. Also different depending on the state.
switch (state) {
case stateMenu:
keyPressedForStateMenu();
break;
case Start:
break;
case Steuerung:
keyPressedForSteuerung();
break;
default:
println ("Unknown state (in keypressed) "
+ state
+ " ++++++++++++++++++++++");
exit();
break;
} // switch
}
void keyPressedForStateMenu() {
//
switch(key) {
case '1':
state =Start;
break;
case '2':
state = Steuerung;
break;
case 'x':
case 'X':
// quit
exit();
break;
default:
// do nothing
break;
}// switch
//
} // func
void keyPressedForSart() {
// any key is possible
switch(key) {
default:
state = stateMenu;
break;
//
}
}// func
void keyPressedForSteuerung() {
// any key is possible
switch(key) {
default:
state = stateMenu;
break;
// ----------------------------------------------------------------
// functions to show the menu and functions that are called from the menu.
// They depend on the states and are called by draw().
void showMenu() {
background(0);
fill(255);
textSize(100);
text("Peachy", 100, 100);
textSize(30);
text("Press 1 to Start ", 100, 250);
text("Press 2 to Controls ", 100, 320);
//text("Highsocre", 100, 390);
//
} // func
void handleStart() {
background(255, 204, 0);
fill(0);
textSize(32);
text(" Start ", 150, 100, 3);
textSize(14);
text("..... some text ", 100, 200);
//
} // func
//
void handleSteuerung() {
background(0);
fill(255);
textSize(32);
text(" Controls ", 150, 100, 3);
textSize(14);
text("Press Left Arrow to move meteorits to the left", 110, 200);
text("Press Right Arrow to move meteorits to the right",100,250);
text ("Press DOWN Arrow to make meteorits faster and move straight upward",50,300);
text ("Press X to quit/move back",165,350);
//
} // func
// ----------------------------------------------------------------
--------------------------------------------------------------------------------------------------------
//Display
void displayBackground() {
pushMatrix();
translate(x, y);
image(backgroundObjects, 0, -backgroundObjects.height);
ellipse(abs(x) + width/2, backgroundObjects.height + height/2 - y, 20, 20);
//ellipse(width/2, -200, 20, 20);
//if(dist(width/2, height/2, width/2, -200 + y) < 100){
// background(25, 0, 0);
//}
popMatrix();
//Richtiges Bild
pushMatrix();
translate (x,y);
image(backg, 0, -backg.height+500);
popMatrix();
//Meteoriten
pushMatrix();
translate(x,y);
image (meteor, 0, -meteor.height);
popMatrix();
if(backgroundObjects.height+height < y)
state = Start;
void displayPlayer() {
image(peachy,150,150,130,130);
}
void displayHighScore(){
fill(255);
text(abs(y/4), width-100, 50);
//String displayHighScore = "";
---------------------------------------------------------------------------------------------------------
//Interaction
void hitTest() {
color c = backgroundObjects.get(abs(x) + width/2, (backgroundObjects.height - y) + height/2 + TOP_BORDER_PLAYER);
// fill(c);
// rect(0, 0, 35, 35);
// println(c, backgroundObjects.height - y, y);
if (red(c) == 247) {
println("treffer");
y = 0;
minim = new Minim(this);
pou = minim.loadFile("Komet explodiert 3.mp3");
void playerControl() {
if (keyCode == LEFT) {
if (x*-1 < backgroundObjects.width - width) {
x = x - 3;
}
} else if (keyCode == RIGHT) {
if (x < 0) {
x = x + 3;
}
} else if (keyCode == DOWN) {
y = y +4;
}
}