mirror of
https://github.com/jokerx3/HeatUp
synced 2026-07-27 08:59:44 +02:00
PowerUps funktionieren nun, bitte commit lesen!
2 von 3 Power Ups sind vollstaendig implementiert. Freeze: friert Gegner/Spieler fuer x Sekunden ein Speed: erhoeht Bewegungsgeschwindigkeit von Gegner/Spieler fuer x Sekunden Score <benoetigt implementierung in StatusPanel/ScoreHandler/wasauchimmer>: erhoeht bei pick up durch spieler die score um x - bei pick up des gegners reduziert sich score um x @Felix: bitte im StatusPanelAdder den Logger.write() Aufruf entfernen der staendig die Temperatur ausgibt -> sehen wir ja jetzt schon im Spielfenster :) @Tim: Bitte fuer weniger Spam im stdout sorgen durch folgende Aenderung in Main.java => in methode run() die Zeile Logger.write(updates +" Ticks, fps "+frames); in this.setTitle("HeatUP! - "+updates+" Ticks, fps "+frames); aendern. Und damit frohe Weihnachten alle :D
This commit is contained in:
@@ -4,9 +4,9 @@ import java.awt.Point;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import de.heatup.logging.Logger;
|
||||
import de.heatup.objects.Opponent;
|
||||
import de.heatup.objects.Player;
|
||||
import de.heatup.objects.PowerUp;
|
||||
import de.heatup.objects.PowerUpHandler;
|
||||
|
||||
public class CollisionHandler {
|
||||
private static ArrayList<Player> movingObjects = new ArrayList<Player>();
|
||||
@@ -19,39 +19,11 @@ public class CollisionHandler {
|
||||
*/
|
||||
public static boolean checkCollision(Player movingObject, char d) {
|
||||
if (movingObject == (movingObjects.get(0))) {
|
||||
// return normalCheck(movingObject, d);
|
||||
// if (movingObject.equals(movingObjects.get(0))) {
|
||||
// enemyCollision(movingObject, d);
|
||||
hardwareCollision(movingObject, d);
|
||||
return normalCheck(movingObject, d);
|
||||
} else {
|
||||
// playerCollision(movingObject, d);
|
||||
return normalCheck(movingObject, d);
|
||||
}
|
||||
// switch (d) {
|
||||
// case 'l':
|
||||
// if (MapGrid.getGridCell(movingObject.getGridLocation().x-1, movingObject.getGridLocation().y).isPath() && MapGrid.getGridCell(movingObject.getGridLocation().x-1, movingObject.getGridLocation().y).isTrigger()) {
|
||||
// Logger.write("Collision with trigger of hardware ID: " + MapGrid.getGridCell(movingObject.getGridLocation().x-1, movingObject.getGridLocation().y).getCorrespondingHardwareToTrigger());
|
||||
// }
|
||||
// return MapGrid.getGridCell(movingObject.getGridLocation().x-1, movingObject.getGridLocation().y).isPath();
|
||||
// case 'r':
|
||||
// if (MapGrid.getGridCell(movingObject.getGridLocation().x+1, movingObject.getGridLocation().y).isPath() && MapGrid.getGridCell(movingObject.getGridLocation().x+1, movingObject.getGridLocation().y).isTrigger()) {
|
||||
// Logger.write("Collision with trigger of hardware ID: " + MapGrid.getGridCell(movingObject.getGridLocation().x+1, movingObject.getGridLocation().y).getCorrespondingHardwareToTrigger());
|
||||
// }
|
||||
// return MapGrid.getGridCell(movingObject.getGridLocation().x+1, movingObject.getGridLocation().y).isPath();
|
||||
// case 'd':
|
||||
// if (MapGrid.getGridCell(movingObject.getGridLocation().x, movingObject.getGridLocation().y+1).isPath() && MapGrid.getGridCell(movingObject.getGridLocation().x, movingObject.getGridLocation().y+1).isTrigger()) {
|
||||
// Logger.write("Collision with trigger of hardware ID: " + MapGrid.getGridCell(movingObject.getGridLocation().x, movingObject.getGridLocation().y+1).getCorrespondingHardwareToTrigger());
|
||||
// }
|
||||
// return MapGrid.getGridCell(movingObject.getGridLocation().x, movingObject.getGridLocation().y+1).isPath();
|
||||
// case 'u':
|
||||
// if (MapGrid.getGridCell(movingObject.getGridLocation().x, movingObject.getGridLocation().y-1).isPath() && MapGrid.getGridCell(movingObject.getGridLocation().x, movingObject.getGridLocation().y-1).isTrigger()) {
|
||||
// Logger.write("Collision with trigger of hardware ID: " + MapGrid.getGridCell(movingObject.getGridLocation().x, movingObject.getGridLocation().y-1).getCorrespondingHardwareToTrigger());
|
||||
// }
|
||||
// return MapGrid.getGridCell(movingObject.getGridLocation().x, movingObject.getGridLocation().y-1).isPath();
|
||||
// default:
|
||||
// return true;
|
||||
// }
|
||||
}
|
||||
|
||||
public static boolean checkCollision(Point startPosition, char d, int steps) {
|
||||
@@ -77,20 +49,6 @@ public class CollisionHandler {
|
||||
}
|
||||
return isPath;
|
||||
}
|
||||
|
||||
|
||||
private static void playerCollision(Player movingObject, char d) {
|
||||
// if (movingObject.getGridLocation().x== movingObjects.get(0).getGridLocation().x && movingObject.getGridLocation().y == movingObjects.get(0).getGridLocation().y) {
|
||||
//// System.exit(-1);
|
||||
// }
|
||||
}
|
||||
private static void enemyCollision(Player movingObject, char d ) {
|
||||
// for (int i=1; i<movingObjects.size();i++) {
|
||||
// if (movingObject.getGridLocation().x== movingObjects.get(i).getGridLocation().x && movingObject.getGridLocation().y == movingObjects.get(i).getGridLocation().y) {
|
||||
//// System.exit(-1);
|
||||
// }
|
||||
// }
|
||||
}
|
||||
public static void tick() {
|
||||
for (int i=1; i<movingObjects.size();i++) {
|
||||
if (movingObjects.get(0).getGridLocation().x== movingObjects.get(i).getGridLocation().x && movingObjects.get(0).getGridLocation().y == movingObjects.get(i).getGridLocation().y) {
|
||||
@@ -102,19 +60,19 @@ public class CollisionHandler {
|
||||
switch (d) {
|
||||
case 'l':
|
||||
if (MapGrid.getGridCell(movingObject.getGridLocation().x-1, movingObject.getGridLocation().y).isPath() && MapGrid.getGridCell(movingObject.getGridLocation().x-1, movingObject.getGridLocation().y).isTrigger()) {
|
||||
Logger.write("Collision with trigger of hardware ID: " + MapGrid.getGridCell(movingObject.getGridLocation().x-1, movingObject.getGridLocation().y).getCorrespondingHardwareToTrigger());
|
||||
// Logger.write("Collision with trigger of hardware ID: " + MapGrid.getGridCell(movingObject.getGridLocation().x-1, movingObject.getGridLocation().y).getCorrespondingHardwareToTrigger());
|
||||
}
|
||||
case 'r':
|
||||
if (MapGrid.getGridCell(movingObject.getGridLocation().x+1, movingObject.getGridLocation().y).isPath() && MapGrid.getGridCell(movingObject.getGridLocation().x+1, movingObject.getGridLocation().y).isTrigger()) {
|
||||
Logger.write("Collision with trigger of hardware ID: " + MapGrid.getGridCell(movingObject.getGridLocation().x+1, movingObject.getGridLocation().y).getCorrespondingHardwareToTrigger());
|
||||
// Logger.write("Collision with trigger of hardware ID: " + MapGrid.getGridCell(movingObject.getGridLocation().x+1, movingObject.getGridLocation().y).getCorrespondingHardwareToTrigger());
|
||||
}
|
||||
case 'd':
|
||||
if (MapGrid.getGridCell(movingObject.getGridLocation().x, movingObject.getGridLocation().y+1).isPath() && MapGrid.getGridCell(movingObject.getGridLocation().x, movingObject.getGridLocation().y+1).isTrigger()) {
|
||||
Logger.write("Collision with trigger of hardware ID: " + MapGrid.getGridCell(movingObject.getGridLocation().x, movingObject.getGridLocation().y+1).getCorrespondingHardwareToTrigger());
|
||||
// Logger.write("Collision with trigger of hardware ID: " + MapGrid.getGridCell(movingObject.getGridLocation().x, movingObject.getGridLocation().y+1).getCorrespondingHardwareToTrigger());
|
||||
}
|
||||
case 'u':
|
||||
if (MapGrid.getGridCell(movingObject.getGridLocation().x, movingObject.getGridLocation().y-1).isPath() && MapGrid.getGridCell(movingObject.getGridLocation().x, movingObject.getGridLocation().y-1).isTrigger()) {
|
||||
Logger.write("Collision with trigger of hardware ID: " + MapGrid.getGridCell(movingObject.getGridLocation().x, movingObject.getGridLocation().y-1).getCorrespondingHardwareToTrigger());
|
||||
// Logger.write("Collision with trigger of hardware ID: " + MapGrid.getGridCell(movingObject.getGridLocation().x, movingObject.getGridLocation().y-1).getCorrespondingHardwareToTrigger());
|
||||
}
|
||||
default:
|
||||
|
||||
@@ -123,16 +81,24 @@ public class CollisionHandler {
|
||||
private static boolean normalCheck(Player movingObject, char d) {
|
||||
switch (d) {
|
||||
case 'l':
|
||||
|
||||
if (PowerUpHandler.getPowerUpGridLocation().x == movingObject.getGridLocation().x-1 && PowerUpHandler.getPowerUpGridLocation().y == movingObject.getGridLocation().y) {
|
||||
PowerUpHandler.getPowerUp().trigger(movingObject == (movingObjects.get(0)));
|
||||
}
|
||||
return MapGrid.getGridCell(movingObject.getGridLocation().x-1, movingObject.getGridLocation().y).isPath();
|
||||
case 'r':
|
||||
|
||||
if (PowerUpHandler.getPowerUpGridLocation().x == movingObject.getGridLocation().x+1 && PowerUpHandler.getPowerUpGridLocation().y == movingObject.getGridLocation().y) {
|
||||
PowerUpHandler.getPowerUp().trigger(movingObject == (movingObjects.get(0)));
|
||||
}
|
||||
return MapGrid.getGridCell(movingObject.getGridLocation().x+1, movingObject.getGridLocation().y).isPath();
|
||||
case 'd':
|
||||
|
||||
if (PowerUpHandler.getPowerUpGridLocation().x == movingObject.getGridLocation().x && PowerUpHandler.getPowerUpGridLocation().y == movingObject.getGridLocation().y+1) {
|
||||
PowerUpHandler.getPowerUp().trigger(movingObject == (movingObjects.get(0)));
|
||||
}
|
||||
return MapGrid.getGridCell(movingObject.getGridLocation().x, movingObject.getGridLocation().y+1).isPath();
|
||||
case 'u':
|
||||
|
||||
if (PowerUpHandler.getPowerUpGridLocation().x == movingObject.getGridLocation().x && PowerUpHandler.getPowerUpGridLocation().y == movingObject.getGridLocation().y-1) {
|
||||
PowerUpHandler.getPowerUp().trigger(movingObject == (movingObjects.get(0)));
|
||||
}
|
||||
return MapGrid.getGridCell(movingObject.getGridLocation().x, movingObject.getGridLocation().y-1).isPath();
|
||||
default:
|
||||
return true; // should not happen
|
||||
|
||||
@@ -3,6 +3,7 @@ package de.heatup.objects;
|
||||
import java.awt.Point;
|
||||
import java.util.Random;
|
||||
|
||||
import de.heatup.logging.Logger;
|
||||
import de.heatup.ui.PanelBuilder;
|
||||
import de.heatup.ui.StatusPanelAdder;
|
||||
|
||||
@@ -24,8 +25,7 @@ public class PowerUp extends StaticObject {
|
||||
public PowerUp() {
|
||||
super('b', new Point());
|
||||
Random rand = new Random();
|
||||
this.pType = rand.nextInt(2);
|
||||
StatusPanelAdder.setPUText(""+pType);
|
||||
this.pType = rand.nextInt(PowerUpController.getAvailablePUs());
|
||||
}
|
||||
public void spawnAt(Point spawnPoint) {
|
||||
this.currentGridPosition = spawnPoint;
|
||||
@@ -49,20 +49,36 @@ public class PowerUp extends StaticObject {
|
||||
if (tickCount>=tickRoundMax) {
|
||||
tickCount = 0;
|
||||
}
|
||||
int remainingTicks;
|
||||
if (tickCount > resetTickstamp) {
|
||||
remainingTicks = tickRoundMax - tickCount + resetTickstamp;
|
||||
} else {
|
||||
remainingTicks = resetTickstamp - tickCount;
|
||||
}
|
||||
this.setActiveCountdown(remainingTicks/60);
|
||||
if (this.isTriggered() && tickCount == resetTickstamp) {
|
||||
PowerUpController.deactivate(pType, triggeredByPlayer);
|
||||
PowerUpHandler.removePowerUp();
|
||||
}
|
||||
}
|
||||
public void trigger(boolean byPlayer) {
|
||||
if (!this.isTriggered()) {
|
||||
this.triggered = true;
|
||||
this.triggeredByPlayer = byPlayer;
|
||||
resetTickstamp = tickCount+60*(PowerUpController.getDuration(pType));
|
||||
Logger.write("duration: "+PowerUpController.getDuration(pType));
|
||||
resetTickstamp = PowerUpHandler.checkStamp(resetTickstamp);
|
||||
PowerUpController.activate(pType, byPlayer);
|
||||
|
||||
Logger.write("Triggered - Trigger resetTickstamp: "+resetTickstamp); // das alte objekt wird offensichtlich immer wieder recycled, sollte aber kein problem darstellen.
|
||||
this.kill();
|
||||
}
|
||||
}
|
||||
public void setRemainingTime(int time) {
|
||||
StatusPanelAdder.setPUText(pType+" "+time);
|
||||
if (!this.isTriggered()) {
|
||||
StatusPanelAdder.setPUText("despawn in "+time);
|
||||
}
|
||||
}
|
||||
private void setActiveCountdown(int time) {
|
||||
StatusPanelAdder.setPUText(PowerUpController.getName(pType) + " active for " +time);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,35 +1,115 @@
|
||||
package de.heatup.objects;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import de.heatup.cfg.Config;
|
||||
import de.heatup.ui.Main;
|
||||
import de.heatup.ui.PanelBuilder;
|
||||
|
||||
public class PowerUpController {
|
||||
private static ArrayList<Player> objects;
|
||||
private static int availablePUs = 3;
|
||||
|
||||
public static int getAvailablePUs() {
|
||||
return availablePUs;
|
||||
}
|
||||
/*
|
||||
* isPlayer true -> PowerUp wird für spieler verwendet
|
||||
*
|
||||
*/
|
||||
public static void activate(int powerup, boolean isPlayer) {
|
||||
setInstancedObjects();
|
||||
if (isPlayer) {
|
||||
|
||||
if ( powerup == 1 ) {
|
||||
PanelBuilder.getInstancedObjects().getObjects().get(0).setSpeedMultiplicator(4);
|
||||
objects.get(0).setSpeedMultiplicatorAbsolute(4);
|
||||
}
|
||||
|
||||
if ( powerup == 0 ) {
|
||||
for (int i=1; i<objects.size(); i++) {
|
||||
objects.get(i).setSpeedMultiplicatorAbsolute(0);
|
||||
}
|
||||
}
|
||||
|
||||
if ( powerup == 2 ) {
|
||||
/*
|
||||
* Score um x erhoehen
|
||||
*/
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
if ( powerup == 1 ) {
|
||||
for (int i=1; i<objects.size(); i++) {
|
||||
objects.get(i).setSpeedMultiplicatorAbsolute(4);
|
||||
}
|
||||
}
|
||||
|
||||
if ( powerup == 0 ) {
|
||||
objects.get(0).setSpeedMultiplicatorAbsolute(0);
|
||||
}
|
||||
|
||||
if ( powerup == 2 ) {
|
||||
/*
|
||||
* Score um x reduzieren
|
||||
*/
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void deactivate(int powerup, boolean isPlayer) {
|
||||
setInstancedObjects();
|
||||
if (isPlayer) {
|
||||
|
||||
if ( powerup == 1 ) {
|
||||
PanelBuilder.getInstancedObjects().getObjects().get(0).setSpeedMultiplicator(Config.initialSpeedMultiplicator);
|
||||
objects.get(0).setSpeedMultiplicatorAbsolute(Config.initialSpeedMultiplicator);
|
||||
}
|
||||
|
||||
if (powerup == 0) {
|
||||
for (int i=1; i<objects.size(); i++) {
|
||||
objects.get(i).setSpeedMultiplicatorAbsolute(Config.initialSpeedMultiplicator);
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
if ( powerup == 1 ) {
|
||||
for (int i=1; i<objects.size(); i++) {
|
||||
objects.get(i).setSpeedMultiplicatorAbsolute(Config.initialSpeedMultiplicator);
|
||||
}
|
||||
}
|
||||
|
||||
if (powerup == 0) {
|
||||
objects.get(0).setSpeedMultiplicatorAbsolute(Config.initialSpeedMultiplicator);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
private static void setInstancedObjects() {
|
||||
objects = PanelBuilder.getInstancedObjects().getObjects();
|
||||
}
|
||||
public static int getDuration(int powerup) {
|
||||
if ( powerup == 1 ) {
|
||||
return 10;
|
||||
}
|
||||
if (powerup == 0) {
|
||||
return 5;
|
||||
}
|
||||
if (powerup == 2) {
|
||||
return 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
public static String getName(int powerup) {
|
||||
if (powerup == 0) {
|
||||
return "Freeze";
|
||||
}
|
||||
if (powerup == 1) {
|
||||
return "Speed";
|
||||
}
|
||||
if (powerup == 2) {
|
||||
return "Score";
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -72,10 +72,14 @@ public class PowerUpHandler {
|
||||
resetTickstamp = checkStamp(resetTickstamp);
|
||||
puSpawned = false;
|
||||
}
|
||||
public static PowerUp getPowerUp() {
|
||||
public static Point getPowerUpGridLocation() {
|
||||
if (pu == null) {
|
||||
return new PowerUp();
|
||||
} else
|
||||
return new Point(-1,-1);
|
||||
} else {
|
||||
return pu.getGridLocation();
|
||||
}
|
||||
}
|
||||
public static PowerUp getPowerUp() {
|
||||
return pu;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user