|
|
|
|
|
|
|
|
import processing.core.PApplet; |
|
|
import processing.core.PApplet; |
|
|
|
|
|
|
|
|
import java.awt.Point; |
|
|
import java.awt.Point; |
|
|
import java.util.ArrayList; |
|
|
import java.util.ArrayList; |
|
|
import java.util.List; |
|
|
import java.util.List; |
|
|
|
|
|
|
|
|
Player player2; |
|
|
Player player2; |
|
|
|
|
|
|
|
|
public GameLoop(){ |
|
|
public GameLoop(){ |
|
|
player1 = new Player(0, "192.168.33.33", 9000); |
|
|
|
|
|
player2 = new Player(1, "192.168.33.44", 9000); |
|
|
|
|
|
|
|
|
player1 = new Player(0, "ip", 9000); |
|
|
|
|
|
player2 = new Player(1, "ip", 9000); |
|
|
tracker = new Tracker(); |
|
|
tracker = new Tracker(); |
|
|
graphics = new GraphicsProgram(); |
|
|
graphics = new GraphicsProgram(); |
|
|
String[] args = {"GraphicsProgram"}; |
|
|
String[] args = {"GraphicsProgram"}; |
|
|
PApplet.runSketch(args, graphics); |
|
|
PApplet.runSketch(args, graphics); |
|
|
gl = new GameLogic(1080,720); |
|
|
|
|
|
|
|
|
gl = new GameLogic(); |
|
|
run(); |
|
|
run(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
private void run(){ |
|
|
private void run(){ |
|
|
while(true){ |
|
|
while(true){ |
|
|
communicate(); |
|
|
communicate(); |
|
|
|
|
|
|
|
|
List<Point> positions = track(); |
|
|
List<Point> positions = track(); |
|
|
if(checkP1(positions.get(0))){ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
addPositions(positions); |
|
|
|
|
|
|
|
|
|
|
|
if(gl.doCheck(player2.getTrail(), positions.get(0))){ //Check Position von P1 mit Spur von P2 |
|
|
|
|
|
System.out.println("Spieler 1 hat verloren"); |
|
|
break; |
|
|
break; |
|
|
} |
|
|
} |
|
|
if(checkP2(positions.get(1))){ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(gl.doCheck(player1.getTrail(), positions.get(1))){ //Check Position von P2 mit Spur von P1 |
|
|
|
|
|
System.out.println("Spieler 2 hat verloren"); |
|
|
break; |
|
|
break; |
|
|
} |
|
|
} |
|
|
addPositions(positions); |
|
|
|
|
|
|
|
|
|
|
|
draw(); |
|
|
draw(); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
//offen für Auto Kommunikation |
|
|
//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 addPositions(List positions){ |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private List<Point> track(){ |
|
|
private List<Point> track(){ |
|
|
org.opencv.core.Point p1 = tracker.getP1(); |
|
|
|
|
|
org.opencv.core.Point p2 = tracker.getP2(); |
|
|
|
|
|
|
|
|
|
|
|
java.awt.Point p1Java = new java.awt.Point((int) p1.x, (int) p1.y); |
|
|
|
|
|
java.awt.Point p2Java = new java.awt.Point((int) p2.x, (int) p2.y); |
|
|
|
|
|
|
|
|
Point p1 = tracker.getP1(); |
|
|
|
|
|
Point p2 = tracker.getP2(); |
|
|
|
|
|
|
|
|
player1.setKoords(p1Java.x, p1Java.y); |
|
|
|
|
|
player2.setKoords(p2Java.x, p2Java.y); |
|
|
|
|
|
|
|
|
player1.setKoords(p1.x, p1.y); |
|
|
|
|
|
player2.setKoords(p2.x, p2.y); |
|
|
|
|
|
|
|
|
List<Point> output = new ArrayList<>(); |
|
|
List<Point> output = new ArrayList<>(); |
|
|
output.set(0, p1Java); |
|
|
|
|
|
output.set(1, p2Java); |
|
|
|
|
|
|
|
|
output.set(0, p1); |
|
|
|
|
|
output.set(1, p2); |
|
|
return output; |
|
|
return output; |
|
|
} |
|
|
} |
|
|
|
|
|
|