@@ -4,12 +4,12 @@ import com.illposed.osc.transport.OSCPortOut; | |||
import java.net.InetAddress; | |||
import java.util.Arrays; | |||
public class ArduinoCommunicator { | |||
public class ArduinoCommunication { | |||
private InetAddress address; | |||
private int port; | |||
private OSCPortOut oscPortOut; | |||
public ArduinoCommunicator(String ipAdress, int portNr) { | |||
public ArduinoCommunication(String ipAdress, int portNr) { | |||
try{ | |||
address = InetAddress.getByName(ipAdress); | |||
port = portNr; | |||
@@ -20,10 +20,9 @@ public class ArduinoCommunicator { | |||
} | |||
} | |||
public void sendMessage(double speed, double steer, boolean light){ | |||
public void sendMessage(int a, double x, double y){ | |||
String oscAddress = "/arduino/command"; // OSC-Adresse für die Nachricht | |||
OSCMessage message = new OSCMessage(oscAddress, Arrays.asList(speed, steer, light)); | |||
OSCMessage message = new OSCMessage(oscAddress, Arrays.asList(a, x, y)); | |||
try { | |||
oscPortOut.send(message); | |||
} |
@@ -1,4 +1,53 @@ | |||
public class GameLoop { | |||
int activePlayer = 0; | |||
Player player1; | |||
Player player2; | |||
boolean wasSmthTracked = false; | |||
public GameLoop(){ | |||
player1 = new Player(0, "ip", 9000); | |||
player2 = new Player(1, "ip", 9000); | |||
run(); | |||
} | |||
private void run(){ | |||
while(true){ | |||
communicate(); | |||
if(!wasSmthTracked) { | |||
track(); | |||
} | |||
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); | |||
} | |||
} | |||
} | |||
private void track(){ | |||
//suche Lampe | |||
//Wenn geklappt, setze wasSmthTracked auf true | |||
} | |||
private void draw(){ | |||
//Schicke für active Player letzte Koordinaten | |||
} | |||
} |
@@ -8,7 +8,7 @@ public class Player { | |||
private int y; | |||
Queue<int[]> trail = new LinkedList<>(); | |||
ArduinoCommunicator arduinoCommunicator; | |||
ArduinoCommunication arduinoCommunicator; | |||
@@ -17,7 +17,7 @@ public class Player { | |||
// Konstruktor | |||
public Player(int id, String finalIpAddress, int finalPortNr) { | |||
this.ID = id; | |||
arduinoCommunicator = new ArduinoCommunicator(finalIpAddress, finalPortNr); | |||
arduinoCommunicator = new ArduinoCommunication(finalIpAddress, finalPortNr); | |||
} | |||
@@ -42,8 +42,8 @@ public class Player { | |||
return trail; | |||
} | |||
public void sendToCar(double speed, double steer, boolean light){ | |||
arduinoCommunicator.sendMessage(speed, steer, light); | |||
public void sendToCar(int light, double steer, double speed){ | |||
arduinoCommunicator.sendMessage(light, steer, speed); | |||
} | |||