107 lines
2.2 KiB
Plaintext
107 lines
2.2 KiB
Plaintext
class Menus {
|
|
|
|
boolean drawRectWithMouseColission(float x, float y, float rectwidth, float rectheight) {
|
|
// Draw A Rect
|
|
rectMode(CENTER);
|
|
rect(x, y, rectwidth, rectheight);
|
|
rectMode(CORNER);
|
|
|
|
// Check it for collission
|
|
if((mouseX > x - rectwidth/2 && mouseX < x + rectwidth/2) && (mouseY > y - rectheight/2 && mouseY < y + rectheight/2)) {
|
|
return true;
|
|
} else {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
class MainMenu extends Menus {
|
|
|
|
void playButton(float x, float y, float w, float h) {
|
|
fill(100, 100, 100);
|
|
if(drawRectWithMouseColission(x, y, w, h) && mousePressed) {
|
|
ismenu = false;
|
|
isgame = true;
|
|
}
|
|
text("Play", x, y);
|
|
}
|
|
|
|
void statsButton(float x, float y, float w, float h) {
|
|
fill(100, 100, 100);
|
|
if(drawRectWithMouseColission(x, y, w, h) && mousePressed) {
|
|
ismenu = false;
|
|
isstats = true;
|
|
}
|
|
text("Stats", x, y);
|
|
}
|
|
|
|
void drawMenu() {
|
|
// color maincolor = color(100, 100, 100);
|
|
playButton(300, 300, 150, 50);
|
|
statsButton(300, 400, 150, 50);
|
|
}
|
|
|
|
void draw() {
|
|
println("test");
|
|
}
|
|
}
|
|
|
|
class Stats extends Menus {
|
|
int trees_sawed = 0;
|
|
|
|
void menuButton() {
|
|
fill(100, 100, 100);
|
|
if(drawRectWithMouseColission(300, 300, 150, 50) && mouse_released) {
|
|
ismenu = true;
|
|
isgame = false;
|
|
isstats = false;
|
|
}
|
|
fill(0);
|
|
text("Main Menu", 300, 300);
|
|
}
|
|
|
|
void draw() {
|
|
background(50);
|
|
menuButton();
|
|
|
|
text("Best Game Time", 50, 50);
|
|
text("Trees Sawed", 50, 70);
|
|
text("Insgesamt Spielzeit", 50, 90);
|
|
}
|
|
}
|
|
|
|
class StopWatchTimer {
|
|
int startTime = 0, stopTime = 0;
|
|
boolean running = false;
|
|
|
|
|
|
void start() {
|
|
startTime = millis();
|
|
running = true;
|
|
}
|
|
void stop() {
|
|
stopTime = millis();
|
|
running = false;
|
|
}
|
|
int getElapsedTime() {
|
|
int elapsed;
|
|
if (running) {
|
|
elapsed = (millis() - startTime);
|
|
}
|
|
else {
|
|
elapsed = (stopTime - startTime);
|
|
}
|
|
return elapsed;
|
|
}
|
|
int second() {
|
|
return (getElapsedTime() / 1000) % 60;
|
|
}
|
|
int minute() {
|
|
return (getElapsedTime() / (1000*60)) % 60;
|
|
}
|
|
int hour() {
|
|
return (getElapsedTime() / (1000*60*60)) % 24;
|
|
}
|
|
}
|