Version 1 des Gameloop und Logic
noch nicht voll fiunktionsfähig 4.12.24 16:19
This commit is contained in:
parent
c5e0dec777
commit
95fb97f847
20
src/main/java/GameLogic.java
Normal file
20
src/main/java/GameLogic.java
Normal file
@ -0,0 +1,20 @@
|
||||
import java.awt.*;
|
||||
|
||||
public class GameLogic {
|
||||
|
||||
private final int width;
|
||||
private final int height;
|
||||
|
||||
private int[][] pitch;
|
||||
|
||||
public GameLogic(int width, int height){
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
pitch = new int[width][height];
|
||||
}
|
||||
|
||||
public boolean checkPlayer(Point point, int id){
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
@ -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);
|
||||
//offen für Auto Kommunikation
|
||||
}
|
||||
|
||||
private boolean checkP1(Point point){
|
||||
if(gl.checkPlayer(point, 0)){
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
player1.sendToCar(0, 0.0, 0.0);
|
||||
player2.sendToCar(1, 0.0, 0.0);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private void track(){
|
||||
//suche Lampe
|
||||
//Wenn geklappt, setze wasSmthTracked auf true
|
||||
private boolean checkP2(Point point){
|
||||
if(gl.checkPlayer(point, 0)){
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
@ -30,9 +30,9 @@ public class GraphicsProgram extends PApplet {
|
||||
int x = koordinates[0];
|
||||
int y = koordinates[1];
|
||||
|
||||
if(playerID == 1){
|
||||
if(playerID == 0){
|
||||
image(imgBlue, x, y, particleSize, particleSize);
|
||||
} else if (playerID == 2) {
|
||||
} else if (playerID == 1) {
|
||||
image(imgRed, x, y, particleSize, particleSize);
|
||||
}else{
|
||||
fill(0, 255, 0);
|
||||
|
Loading…
x
Reference in New Issue
Block a user