Browse Source

Version 1 des Gameloop und Logic

noch nicht voll fiunktionsfähig
4.12.24 16:19
master
Paul-1108 2 weeks ago
parent
commit
95fb97f847
3 changed files with 81 additions and 26 deletions
  1. 20
    0
      src/main/java/GameLogic.java
  2. 59
    24
      src/main/java/GameLoop.java
  3. 2
    2
      src/main/java/GraphicsProgram.java

+ 20
- 0
src/main/java/GameLogic.java View File

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;
}

}

+ 59
- 24
src/main/java/GameLoop.java View File

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) {
track();
List<Point> positions = 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){
//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(){ private void draw(){
//Schicke für active Player letzte Koordinaten
graphics.drawTrail(player1.getTrail(), 0);
graphics.drawTrail(player2.getTrail(), 1);
} }
} }

+ 2
- 2
src/main/java/GraphicsProgram.java View File

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…
Cancel
Save