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:
toksikk
2014-12-22 14:48:46 +01:00
parent 0cde2135af
commit 84c226098d
4 changed files with 135 additions and 69 deletions
@@ -4,9 +4,9 @@ import java.awt.Point;
import java.util.ArrayList; import java.util.ArrayList;
import de.heatup.logging.Logger; import de.heatup.logging.Logger;
import de.heatup.objects.Opponent;
import de.heatup.objects.Player; import de.heatup.objects.Player;
import de.heatup.objects.PowerUp; import de.heatup.objects.PowerUp;
import de.heatup.objects.PowerUpHandler;
public class CollisionHandler { public class CollisionHandler {
private static ArrayList<Player> movingObjects = new ArrayList<Player>(); private static ArrayList<Player> movingObjects = new ArrayList<Player>();
@@ -19,39 +19,11 @@ public class CollisionHandler {
*/ */
public static boolean checkCollision(Player movingObject, char d) { public static boolean checkCollision(Player movingObject, char d) {
if (movingObject == (movingObjects.get(0))) { if (movingObject == (movingObjects.get(0))) {
// return normalCheck(movingObject, d);
// if (movingObject.equals(movingObjects.get(0))) {
// enemyCollision(movingObject, d);
hardwareCollision(movingObject, d); hardwareCollision(movingObject, d);
return normalCheck(movingObject, d); return normalCheck(movingObject, d);
} else { } else {
// playerCollision(movingObject, d);
return normalCheck(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) { public static boolean checkCollision(Point startPosition, char d, int steps) {
@@ -77,20 +49,6 @@ public class CollisionHandler {
} }
return isPath; 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() { public static void tick() {
for (int i=1; i<movingObjects.size();i++) { 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) { 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) { switch (d) {
case 'l': case 'l':
if (MapGrid.getGridCell(movingObject.getGridLocation().x-1, movingObject.getGridLocation().y).isPath() && MapGrid.getGridCell(movingObject.getGridLocation().x-1, movingObject.getGridLocation().y).isTrigger()) { 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': case 'r':
if (MapGrid.getGridCell(movingObject.getGridLocation().x+1, movingObject.getGridLocation().y).isPath() && MapGrid.getGridCell(movingObject.getGridLocation().x+1, movingObject.getGridLocation().y).isTrigger()) { 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': case 'd':
if (MapGrid.getGridCell(movingObject.getGridLocation().x, movingObject.getGridLocation().y+1).isPath() && MapGrid.getGridCell(movingObject.getGridLocation().x, movingObject.getGridLocation().y+1).isTrigger()) { 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': case 'u':
if (MapGrid.getGridCell(movingObject.getGridLocation().x, movingObject.getGridLocation().y-1).isPath() && MapGrid.getGridCell(movingObject.getGridLocation().x, movingObject.getGridLocation().y-1).isTrigger()) { 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: default:
@@ -123,16 +81,24 @@ public class CollisionHandler {
private static boolean normalCheck(Player movingObject, char d) { private static boolean normalCheck(Player movingObject, char d) {
switch (d) { switch (d) {
case 'l': 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(); return MapGrid.getGridCell(movingObject.getGridLocation().x-1, movingObject.getGridLocation().y).isPath();
case 'r': 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(); return MapGrid.getGridCell(movingObject.getGridLocation().x+1, movingObject.getGridLocation().y).isPath();
case 'd': 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(); return MapGrid.getGridCell(movingObject.getGridLocation().x, movingObject.getGridLocation().y+1).isPath();
case 'u': 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(); return MapGrid.getGridCell(movingObject.getGridLocation().x, movingObject.getGridLocation().y-1).isPath();
default: default:
return true; // should not happen return true; // should not happen
+20 -4
View File
@@ -3,6 +3,7 @@ package de.heatup.objects;
import java.awt.Point; import java.awt.Point;
import java.util.Random; import java.util.Random;
import de.heatup.logging.Logger;
import de.heatup.ui.PanelBuilder; import de.heatup.ui.PanelBuilder;
import de.heatup.ui.StatusPanelAdder; import de.heatup.ui.StatusPanelAdder;
@@ -24,8 +25,7 @@ public class PowerUp extends StaticObject {
public PowerUp() { public PowerUp() {
super('b', new Point()); super('b', new Point());
Random rand = new Random(); Random rand = new Random();
this.pType = rand.nextInt(2); this.pType = rand.nextInt(PowerUpController.getAvailablePUs());
StatusPanelAdder.setPUText(""+pType);
} }
public void spawnAt(Point spawnPoint) { public void spawnAt(Point spawnPoint) {
this.currentGridPosition = spawnPoint; this.currentGridPosition = spawnPoint;
@@ -49,20 +49,36 @@ public class PowerUp extends StaticObject {
if (tickCount>=tickRoundMax) { if (tickCount>=tickRoundMax) {
tickCount = 0; tickCount = 0;
} }
int remainingTicks;
if (tickCount > resetTickstamp) {
remainingTicks = tickRoundMax - tickCount + resetTickstamp;
} else {
remainingTicks = resetTickstamp - tickCount;
}
this.setActiveCountdown(remainingTicks/60);
if (this.isTriggered() && tickCount == resetTickstamp) { if (this.isTriggered() && tickCount == resetTickstamp) {
PowerUpController.deactivate(pType, triggeredByPlayer); PowerUpController.deactivate(pType, triggeredByPlayer);
PowerUpHandler.removePowerUp(); PowerUpHandler.removePowerUp();
} }
} }
public void trigger(boolean byPlayer) { public void trigger(boolean byPlayer) {
if (!this.isTriggered()) {
this.triggered = true; this.triggered = true;
this.triggeredByPlayer = byPlayer; this.triggeredByPlayer = byPlayer;
resetTickstamp = tickCount+60*(PowerUpController.getDuration(pType)); resetTickstamp = tickCount+60*(PowerUpController.getDuration(pType));
Logger.write("duration: "+PowerUpController.getDuration(pType));
resetTickstamp = PowerUpHandler.checkStamp(resetTickstamp); resetTickstamp = PowerUpHandler.checkStamp(resetTickstamp);
PowerUpController.activate(pType, byPlayer); 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) { 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; package de.heatup.objects;
import java.util.ArrayList;
import de.heatup.cfg.Config; import de.heatup.cfg.Config;
import de.heatup.ui.Main; import de.heatup.ui.Main;
import de.heatup.ui.PanelBuilder; import de.heatup.ui.PanelBuilder;
public class PowerUpController { 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 * isPlayer true -> PowerUp wird für spieler verwendet
* *
*/ */
public static void activate(int powerup, boolean isPlayer) { public static void activate(int powerup, boolean isPlayer) {
setInstancedObjects();
if (isPlayer) { if (isPlayer) {
if ( powerup == 1 ) { 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) { public static void deactivate(int powerup, boolean isPlayer) {
setInstancedObjects();
if (isPlayer) { if (isPlayer) {
if ( powerup == 1 ) { 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) { public static int getDuration(int powerup) {
if ( powerup == 1 ) { if ( powerup == 1 ) {
return 10; return 10;
} }
if (powerup == 0) {
return 5;
}
if (powerup == 2) {
return 0; 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); resetTickstamp = checkStamp(resetTickstamp);
puSpawned = false; puSpawned = false;
} }
public static PowerUp getPowerUp() { public static Point getPowerUpGridLocation() {
if (pu == null) { if (pu == null) {
return new PowerUp(); return new Point(-1,-1);
} else } else {
return pu.getGridLocation();
}
}
public static PowerUp getPowerUp() {
return pu; return pu;
} }
} }