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 {
|
public class GameLoop {
|
||||||
int activePlayer = 0;
|
int activePlayer = 0;
|
||||||
|
|
||||||
|
Tracker tracker;
|
||||||
|
|
||||||
|
GraphicsProgram graphics;
|
||||||
|
|
||||||
|
GameLogic gl;
|
||||||
|
|
||||||
Player player1;
|
Player player1;
|
||||||
Player player2;
|
Player player2;
|
||||||
|
|
||||||
boolean wasSmthTracked = false;
|
|
||||||
|
|
||||||
public GameLoop(){
|
public GameLoop(){
|
||||||
player1 = new Player(0, "ip", 9000);
|
player1 = new Player(0, "ip", 9000);
|
||||||
player2 = new Player(1, "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();
|
run();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void run(){
|
private void run(){
|
||||||
while(true){
|
while(true){
|
||||||
communicate();
|
communicate();
|
||||||
if(!wasSmthTracked) {
|
List<Point> positions = track();
|
||||||
track();
|
if(checkP1(positions.get(0))){
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
if(checkP2(positions.get(1))){
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
addPositions(positions);
|
||||||
draw();
|
draw();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void communicate() {
|
private void communicate() {
|
||||||
if(wasSmthTracked){
|
//offen für Auto Kommunikation
|
||||||
//Beide sollen ausgehen
|
}
|
||||||
player1.sendToCar(0, 0.0, 0.0);
|
|
||||||
player2.sendToCar(0, 0.0, 0.0);
|
private boolean checkP1(Point point){
|
||||||
activePlayer++;
|
if(gl.checkPlayer(point, 0)){
|
||||||
} else {
|
return true;
|
||||||
//Schicke die Nachrichten fürs angehen
|
}
|
||||||
activePlayer = activePlayer%2;
|
else {
|
||||||
if (activePlayer == 0){
|
return false;
|
||||||
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(){
|
private boolean checkP2(Point point){
|
||||||
//suche Lampe
|
if(gl.checkPlayer(point, 0)){
|
||||||
//Wenn geklappt, setze wasSmthTracked auf true
|
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(){
|
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 x = koordinates[0];
|
||||||
int y = koordinates[1];
|
int y = koordinates[1];
|
||||||
|
|
||||||
if(playerID == 1){
|
if(playerID == 0){
|
||||||
image(imgBlue, x, y, particleSize, particleSize);
|
image(imgBlue, x, y, particleSize, particleSize);
|
||||||
} else if (playerID == 2) {
|
} else if (playerID == 1) {
|
||||||
image(imgRed, x, y, particleSize, particleSize);
|
image(imgRed, x, y, particleSize, particleSize);
|
||||||
}else{
|
}else{
|
||||||
fill(0, 255, 0);
|
fill(0, 255, 0);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user