// DONE Level mit 2 Bereichen. Erster Bereich Straße und Kettensäge und End/Startpunkt. Zweiter Bereich Wald und Bob // DONE Statistikseite: Spielzeit, Bäume gefällt, Zeit gestoppt // TODO Wir brauchen Geräusche // DONE Robi muss noch beschleunigen können float checkDistance(Log log, Ship ship) { float testX = ship.pos.x; float testY = ship.pos.y; // which edge is closest? if (ship.pos.x < log.x) testX = log.x; else if (ship.pos.x > log.x+log.logwidth) testX = log.x+log.logwidth; if (ship.pos.y < log.y - log.logheight) testY = log.y - log.logheight; else if (ship.pos.y > log.y) testY = log.y; // get distant float distX = ship.pos.x-testX; float distY = ship.pos.y-testY; float distance = sqrt( (distX*distX) + (distY*distY) ); line(testX, testY, ship.pos.x, ship.pos.y); // if the distance is less than the radius, collision! return distance; } // Main Game entry void play() { background(50); text(playtime.second(), 20, 20); ship_zero.draw(); saw_zero.drawSaw(); ship_zero.collect(saw_zero); bob.drawBob(); ship_zero.collect(bob); // draw wall for(int i = 0; i < walls.length; i++) { walls[i].drawLog(i); } // draw log for(int i = 0; i < logs.length; i++) { logs[i].drawLog(i); } // log normal stroke for(int i = 0; i < logs.length; i++) { logs[i].strokecolor = logs[i].logcolor; } // nearest log stroke (debug) logs[ship_zero.nextLog].strokecolor = color(255, 0, 0); } // ----- // global state boolean isgame = false; boolean ismenu = true; boolean isend = false; boolean isstats = false; boolean ispause = false; boolean start_slide = true; // ----- Objectives MainMenu main_menu = new MainMenu(); Stats stats_menu = new Stats(); Log[] logs; // player Ship ship_zero; // collectables Saw saw_zero; Bob bob; // stopwatch StopWatchTimer playtime = new StopWatchTimer(); PImage player_sprite; PImage saw_sprite; PImage bob_sprite; void setup() { size(600, 600); textAlign(CENTER, CENTER); create_level(30); println(logs[1]); ship_zero = new Ship(); saw_zero = new Saw(-width+100, 100, 20, 50); bob = new Bob(500, 400, 20, 40); player_sprite = loadImage("./assets/Sprite-0001.png"); saw_sprite = loadImage("./assets/Sprite-saege.png"); bob_sprite = loadImage("./assets/Sprite-bob.png"); } void draw() { // time debug // println(millis(), " start: ", playtime.startTime, " pause: ", playtime.pauseTime); // game state if (isgame) { // Go to second or first slide if(ship_zero.pos.x > 0) { start_slide = false; } else { start_slide = true; } // actually move the camera if(start_slide) { translate(600, 0); } else { translate(0, 0); } // Main Entry play(); // Timer if (playtime.running) {} else playtime.start(); if (playtime.pause) playtime.resume(); // Win if(bob.is_attached && dist(ship_zero.pos.x, ship_zero.pos.y ,-400, 300) < 100) { isgame = false; isend = true; } fill(150, 0, 0, 50); ellipse(-400, 300, 200, 200); } 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 } else if (ispause) { main_menu.drawMenu(); if (playtime.running && playtime.pause == false) playtime.pause_start(); } mouse_released = false; }