74 lines
1.8 KiB
Plaintext
74 lines
1.8 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
|
|
// Roboter muss abprallen, kaputt gehen
|
|
|
|
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_zero.x, ship_zero.y);
|
|
|
|
// if the distance is less than the radius, collision!
|
|
return distance;
|
|
}
|
|
|
|
// -----
|
|
boolean isColliding = false;
|
|
|
|
Ship ship_zero;
|
|
Saw saw_zero;
|
|
Bob bob;
|
|
|
|
Log[] logs = {new Log(100, 200, 100, 100, false), new Log(500, 200, 200, 100, false), new Log(400, 400, 20, 100, true) };
|
|
//Log log_zero = new Log(100,200,100,100,false);
|
|
void setup() {
|
|
size(600, 600);
|
|
ship_zero = new Ship();
|
|
saw_zero = new Saw(100, 100, 20, 50);
|
|
bob = new Bob(100, 400, 20, 40);
|
|
}
|
|
|
|
void draw() {
|
|
background(50);
|
|
|
|
|
|
for(int i = 0; i < logs.length; i++) {
|
|
logs[i].drawLog(i);
|
|
}
|
|
|
|
|
|
// 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].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.newX);
|
|
}
|