From 84c226098d4d0003f48a05fd638aec6060c36913 Mon Sep 17 00:00:00 2001 From: toksikk Date: Mon, 22 Dec 2014 14:48:46 +0100 Subject: [PATCH] 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 : 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 --- .../de/heatup/mapengine/CollisionHandler.java | 68 ++++---------- HeatUp/src/de/heatup/objects/PowerUp.java | 34 +++++-- .../de/heatup/objects/PowerUpController.java | 90 +++++++++++++++++-- .../src/de/heatup/objects/PowerUpHandler.java | 12 ++- 4 files changed, 135 insertions(+), 69 deletions(-) diff --git a/HeatUp/src/de/heatup/mapengine/CollisionHandler.java b/HeatUp/src/de/heatup/mapengine/CollisionHandler.java index ac0a85a..1ff5cb3 100644 --- a/HeatUp/src/de/heatup/mapengine/CollisionHandler.java +++ b/HeatUp/src/de/heatup/mapengine/CollisionHandler.java @@ -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 movingObjects = new ArrayList(); @@ -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=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) { - this.triggered = true; - this.triggeredByPlayer = byPlayer; - resetTickstamp = tickCount+60*(PowerUpController.getDuration(pType)); - resetTickstamp = PowerUpHandler.checkStamp(resetTickstamp); - PowerUpController.activate(pType, 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); } } diff --git a/HeatUp/src/de/heatup/objects/PowerUpController.java b/HeatUp/src/de/heatup/objects/PowerUpController.java index 986ac5b..0a21a79 100644 --- a/HeatUp/src/de/heatup/objects/PowerUpController.java +++ b/HeatUp/src/de/heatup/objects/PowerUpController.java @@ -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 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