120 lines
2.6 KiB
Plaintext
120 lines
2.6 KiB
Plaintext
// Level mit 2 Bereichen. Erster Bereich Straße und Kettensäge und End/Startpunkt. Zweiter Bereich Wald und Bob
|
|
|
|
// Statistikseite: Spielzeit, Bäume gefällt, Zeit gestoppt
|
|
// Wir brauchen Geräusche
|
|
// Robi muss noch beschleunigen können
|
|
|
|
float checkDistance(Log log, Ship ship) {
|
|
float testX = ship.x;
|
|
float testY = ship.y;
|
|
|
|
// which edge is closest?
|
|
if (ship.x < log.x) testX = log.x;
|
|
else if (ship.x > log.x+log.logwidth) testX = log.x+log.logwidth;
|
|
if (ship.y < log.y) testY = log.y;
|
|
else if (ship.y > log.y+log.logheight) testY = log.y+log.logheight;
|
|
|
|
// get distant
|
|
float distX = ship.x-testX;
|
|
float distY = ship.y-testY;
|
|
float distance = sqrt( (distX*distX) + (distY*distY) );
|
|
|
|
line(testX, testY, ship.x, ship.y);
|
|
|
|
// if the distance is less than the radius, collision!
|
|
return distance;
|
|
}
|
|
|
|
// Main Game entry
|
|
void play() {
|
|
background(50);
|
|
|
|
text(playtime.second(), 20, 20);
|
|
// println(playtime.second());
|
|
|
|
|
|
// for(int i = 0; i < trees.length; i++) {
|
|
// trees[i].draw();
|
|
// }
|
|
|
|
ship_zero.draw();
|
|
saw_zero.drawSaw();
|
|
ship_zero.collect(saw_zero);
|
|
bob.drawBob();
|
|
ship_zero.collect(bob);
|
|
|
|
|
|
for(int i = 0; i < logs.length; i++) {
|
|
logs[i].drawLog(i);
|
|
}
|
|
|
|
for(int i = 0; i < logs.length; i++) {
|
|
logs[i].strokecolor = logs[i].logcolor;
|
|
}
|
|
|
|
|
|
logs[ship_zero.nextLog].strokecolor = color(255, 0, 0);
|
|
|
|
// println(ship_zero.newX, " : ", ship_zero.newY);
|
|
|
|
// println("x: ", ship_zero.x, " : ", ship_zero.y);
|
|
println(stats_menu.trees_sawed);
|
|
}
|
|
|
|
// -----
|
|
MainMenu main_menu = new MainMenu();
|
|
Stats stats_menu = new Stats();
|
|
|
|
//Log log_zero = new Log(100,200,100,100,false);
|
|
void setup() {
|
|
// size(1280, 720);
|
|
size(600, 600);
|
|
textAlign(CENTER, CENTER);
|
|
|
|
// surface.setResizable(true);
|
|
|
|
ship_zero = new Ship();
|
|
saw_zero = new Saw(100, 100, 20, 50);
|
|
bob = new Bob(100, 400, 20, 40);
|
|
}
|
|
|
|
|
|
// global state
|
|
boolean isgame = false;
|
|
boolean ismenu = true;
|
|
boolean isend = false;
|
|
boolean isstats = false;
|
|
|
|
Log[] logs = {new Log(100, 200, 100, 100, false), new Log(500, 200, 200, 100, false), new Log(400, 400, 20, 100, true) };
|
|
Ship ship_zero;
|
|
Saw saw_zero;
|
|
Bob bob;
|
|
|
|
// stopwatch
|
|
StopWatchTimer playtime = new StopWatchTimer();
|
|
|
|
void draw() {
|
|
|
|
|
|
if (isgame) {
|
|
play();
|
|
|
|
if(keyPressed) {
|
|
println(mouseX, " : ", mouseY);
|
|
}
|
|
|
|
if (playtime.running) {} else playtime.start();
|
|
} else if (ismenu){
|
|
// menu code
|
|
// play();
|
|
main_menu.drawMenu();
|
|
if (playtime.running) playtime.stop();
|
|
} else if (isstats) {
|
|
stats_menu.draw();
|
|
} else if (isend) {
|
|
// end screen code
|
|
}
|
|
|
|
mouse_released = false;
|
|
}
|