mirror of
https://github.com/jokerx3/HeatUp
synced 2026-07-27 11:39:45 +02:00
Anpassungen an der Config für SpeedMultiplicator von Player und Opponent
This commit is contained in:
@@ -36,4 +36,9 @@ public class Config {
|
|||||||
* Methoden
|
* Methoden
|
||||||
* de.heatup.ein.anderes.package.*
|
* de.heatup.ein.anderes.package.*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Initiale Attribute für Player und Opponent
|
||||||
|
*/
|
||||||
|
public static int initialSpeedMultiplicator = 2;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -88,11 +88,11 @@ public class GameLoopD extends JFrame implements Runnable {
|
|||||||
|
|
||||||
opponent02 = new Opponent();
|
opponent02 = new Opponent();
|
||||||
gamePanel.add(opponent02);
|
gamePanel.add(opponent02);
|
||||||
opponent02.setBounds(50,50,25,25);
|
opponent02.setBounds(150,150,25,25);
|
||||||
|
|
||||||
opponent03 = new Opponent();
|
opponent03 = new Opponent();
|
||||||
gamePanel.add(opponent03);
|
gamePanel.add(opponent03);
|
||||||
opponent03.setBounds(50,50,25,25);
|
opponent03.setBounds(550,450,25,25);
|
||||||
|
|
||||||
|
|
||||||
gamePanel.setFocusable(true);
|
gamePanel.setFocusable(true);
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import java.util.Random;
|
|||||||
|
|
||||||
import javax.imageio.ImageIO;
|
import javax.imageio.ImageIO;
|
||||||
|
|
||||||
|
import de.heatup.cfg.Config;
|
||||||
import de.heatup.mapengine.MapGrid;
|
import de.heatup.mapengine.MapGrid;
|
||||||
|
|
||||||
public class Opponent extends Player {
|
public class Opponent extends Player {
|
||||||
@@ -42,7 +43,7 @@ public class Opponent extends Player {
|
|||||||
this.d = (rand.nextInt(10) <= 4) ? 'x' : 'y';
|
this.d = (rand.nextInt(10) <= 4) ? 'x' : 'y';
|
||||||
this.i = (rand.nextInt(10) <= 4) ? 1 : -1;
|
this.i = (rand.nextInt(10) <= 4) ? 1 : -1;
|
||||||
|
|
||||||
// Sicher stellen das man nicht in die Richtung aus der man gekommen ist.
|
// Sicher stellen das man nicht in die Richtung geht aus der man gekommen ist.
|
||||||
if ( redecide && this.d == this.prevd && this.i != this.previ ) {
|
if ( redecide && this.d == this.prevd && this.i != this.previ ) {
|
||||||
this.i *= -1;
|
this.i *= -1;
|
||||||
}
|
}
|
||||||
@@ -57,6 +58,8 @@ public class Opponent extends Player {
|
|||||||
this.prevY = this.getGridLocation().y;
|
this.prevY = this.getGridLocation().y;
|
||||||
// Blockade Erkennung
|
// Blockade Erkennung
|
||||||
|
|
||||||
|
//TODO: Bei Kreuzung umentscheiden
|
||||||
|
|
||||||
// Blockade auflösen, gehe doch in die Richtung aus man gekommen ist
|
// Blockade auflösen, gehe doch in die Richtung aus man gekommen ist
|
||||||
if ( this.blocked ) {
|
if ( this.blocked ) {
|
||||||
System.out.println("Warning: Block detected!");
|
System.out.println("Warning: Block detected!");
|
||||||
@@ -66,10 +69,7 @@ public class Opponent extends Player {
|
|||||||
}
|
}
|
||||||
// Blockade auflösen
|
// Blockade auflösen
|
||||||
|
|
||||||
|
// Neue Koordinaten bestimmen
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (d == 'x') {
|
if (d == 'x') {
|
||||||
testX=this.getGridLocation().x + i;
|
testX=this.getGridLocation().x + i;
|
||||||
testY=this.getGridLocation().y;
|
testY=this.getGridLocation().y;
|
||||||
@@ -78,6 +78,7 @@ public class Opponent extends Player {
|
|||||||
testX=this.getGridLocation().x;
|
testX=this.getGridLocation().x;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Testen ob die gewählte Richtung begehbar ist
|
||||||
if (MapGrid.getGridCell(testX,testY).isPath()) {
|
if (MapGrid.getGridCell(testX,testY).isPath()) {
|
||||||
this.setGridLocation(testX, testY);
|
this.setGridLocation(testX, testY);
|
||||||
this.prevd = d;
|
this.prevd = d;
|
||||||
@@ -94,7 +95,7 @@ public class Opponent extends Player {
|
|||||||
int newx = this.getX();
|
int newx = this.getX();
|
||||||
int newy = this.getY();
|
int newy = this.getY();
|
||||||
|
|
||||||
for (int s = 0; s<2; s++) { // speed multiplikator
|
for (int s = 0; s < this.speedMultiplicator; s++) { // speed multiplikator
|
||||||
if (d == 'x' && i == -1) {
|
if (d == 'x' && i == -1) {
|
||||||
newx = newx - 1;
|
newx = newx - 1;
|
||||||
} else if (d == 'x' && i == 1) {
|
} else if (d == 'x' && i == 1) {
|
||||||
|
|||||||
@@ -8,9 +8,12 @@ import java.awt.RenderingHints;
|
|||||||
import java.awt.image.BufferedImage;
|
import java.awt.image.BufferedImage;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
import javax.imageio.ImageIO;
|
import javax.imageio.ImageIO;
|
||||||
import javax.swing.JComponent;
|
import javax.swing.JComponent;
|
||||||
|
|
||||||
|
import de.heatup.cfg.Config;
|
||||||
|
|
||||||
public class Player extends JComponent {
|
public class Player extends JComponent {
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
protected BufferedImage bf1;
|
protected BufferedImage bf1;
|
||||||
@@ -19,6 +22,7 @@ public class Player extends JComponent {
|
|||||||
private double rescaleFactorY = 0.0;
|
private double rescaleFactorY = 0.0;
|
||||||
public boolean startMove = false;
|
public boolean startMove = false;
|
||||||
public boolean animate = false;
|
public boolean animate = false;
|
||||||
|
protected int speedMultiplicator = Config.initialSpeedMultiplicator;
|
||||||
protected char d;
|
protected char d;
|
||||||
protected int i;
|
protected int i;
|
||||||
final int stepx = 25;
|
final int stepx = 25;
|
||||||
@@ -28,7 +32,20 @@ public class Player extends JComponent {
|
|||||||
int stepCounter = 25;
|
int stepCounter = 25;
|
||||||
private Point currentGridPosition;
|
private Point currentGridPosition;
|
||||||
|
|
||||||
public void setGridLocation(int x, int y) {
|
public void setSpeedMultiplicator(int factor) {
|
||||||
|
this.speedMultiplicator *= factor;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSpeedMultiplicatorAbsolute(int value) {
|
||||||
|
this.speedMultiplicator = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void resetSpeedMultiplicator() {
|
||||||
|
this.speedMultiplicator = Config.initialSpeedMultiplicator;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void setGridLocation(int x, int y) {
|
||||||
currentGridPosition.setLocation(x, y);
|
currentGridPosition.setLocation(x, y);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -79,7 +96,7 @@ public class Player extends JComponent {
|
|||||||
if ( startMove || animate ) {
|
if ( startMove || animate ) {
|
||||||
int newx = this.getX();
|
int newx = this.getX();
|
||||||
int newy = this.getY();
|
int newy = this.getY();
|
||||||
for (int s = 0; s<2; s++) { // speed multiplikator
|
for (int s = 0; s < this.speedMultiplicator; s++) { // speed multiplikator
|
||||||
if (d == 'x' && i == -1) {
|
if (d == 'x' && i == -1) {
|
||||||
newx = newx - 1;
|
newx = newx - 1;
|
||||||
} else if (d == 'x' && i == 1) {
|
} else if (d == 'x' && i == 1) {
|
||||||
|
|||||||
Reference in New Issue
Block a user