|
|
@@ -1,53 +1,88 @@ |
|
|
|
import processing.core.PApplet; |
|
|
|
|
|
|
|
import java.awt.Point; |
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.List; |
|
|
|
|
|
|
|
public class GameLoop { |
|
|
|
int activePlayer = 0; |
|
|
|
|
|
|
|
Tracker tracker; |
|
|
|
|
|
|
|
GraphicsProgram graphics; |
|
|
|
|
|
|
|
GameLogic gl; |
|
|
|
|
|
|
|
Player player1; |
|
|
|
Player player2; |
|
|
|
|
|
|
|
boolean wasSmthTracked = false; |
|
|
|
|
|
|
|
public GameLoop(){ |
|
|
|
player1 = new Player(0, "ip", 9000); |
|
|
|
player2 = new Player(1, "ip", 9000); |
|
|
|
tracker = new Tracker(); |
|
|
|
graphics = new GraphicsProgram(); |
|
|
|
String[] args = {"GraphicsProgram"}; |
|
|
|
PApplet.runSketch(args, graphics); |
|
|
|
gl = new GameLogic(1080,720); |
|
|
|
run(); |
|
|
|
} |
|
|
|
|
|
|
|
private void run(){ |
|
|
|
while(true){ |
|
|
|
communicate(); |
|
|
|
if(!wasSmthTracked) { |
|
|
|
track(); |
|
|
|
List<Point> positions = track(); |
|
|
|
if(checkP1(positions.get(0))){ |
|
|
|
break; |
|
|
|
} |
|
|
|
if(checkP2(positions.get(1))){ |
|
|
|
break; |
|
|
|
} |
|
|
|
addPositions(positions); |
|
|
|
draw(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private void communicate() { |
|
|
|
if(wasSmthTracked){ |
|
|
|
//Beide sollen ausgehen |
|
|
|
player1.sendToCar(0, 0.0, 0.0); |
|
|
|
player2.sendToCar(0, 0.0, 0.0); |
|
|
|
activePlayer++; |
|
|
|
} else { |
|
|
|
//Schicke die Nachrichten fürs angehen |
|
|
|
activePlayer = activePlayer%2; |
|
|
|
if (activePlayer == 0){ |
|
|
|
player1.sendToCar(1, 0.0, 0.0); |
|
|
|
player2.sendToCar(0, 0.0, 0.0); |
|
|
|
} |
|
|
|
else { |
|
|
|
player1.sendToCar(0, 0.0, 0.0); |
|
|
|
player2.sendToCar(1, 0.0, 0.0); |
|
|
|
} |
|
|
|
//offen für Auto Kommunikation |
|
|
|
} |
|
|
|
|
|
|
|
private boolean checkP1(Point point){ |
|
|
|
if(gl.checkPlayer(point, 0)){ |
|
|
|
return true; |
|
|
|
} |
|
|
|
else { |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private boolean checkP2(Point point){ |
|
|
|
if(gl.checkPlayer(point, 0)){ |
|
|
|
return true; |
|
|
|
} |
|
|
|
else { |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private void track(){ |
|
|
|
//suche Lampe |
|
|
|
//Wenn geklappt, setze wasSmthTracked auf true |
|
|
|
private void addPositions(List positions){ |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
private List<Point> track(){ |
|
|
|
Point p1 = tracker.getP1(); |
|
|
|
Point p2 = tracker.getP2(); |
|
|
|
|
|
|
|
player1.setKoords(p1.x, p1.y); |
|
|
|
player2.setKoords(p2.x, p2.y); |
|
|
|
|
|
|
|
List<Point> output = new ArrayList<>(); |
|
|
|
output.set(0, p1); |
|
|
|
output.add(p2); |
|
|
|
return output; |
|
|
|
} |
|
|
|
|
|
|
|
private void draw(){ |
|
|
|
//Schicke für active Player letzte Koordinaten |
|
|
|
graphics.drawTrail(player1.getTrail(), 0); |
|
|
|
graphics.drawTrail(player2.getTrail(), 1); |
|
|
|
} |
|
|
|
} |