mirror of
https://github.com/jokerx3/HeatUp
synced 2026-07-27 10:19:46 +02:00
PowerUp
This commit is contained in:
@@ -1,33 +1,68 @@
|
|||||||
package de.heatup.objects;
|
package de.heatup.objects;
|
||||||
|
|
||||||
import java.awt.BasicStroke;
|
|
||||||
import java.awt.Graphics;
|
|
||||||
import java.awt.Graphics2D;
|
|
||||||
import java.awt.Point;
|
import java.awt.Point;
|
||||||
import java.awt.RenderingHints;
|
|
||||||
import java.awt.image.BufferedImage;
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
import javax.imageio.ImageIO;
|
import de.heatup.ui.PanelBuilder;
|
||||||
import javax.swing.JComponent;
|
import de.heatup.ui.StatusPanelAdder;
|
||||||
|
|
||||||
import de.heatup.cfg.Config;
|
|
||||||
import de.heatup.logging.Logger;
|
|
||||||
import de.heatup.mapengine.CollisionHandler;
|
|
||||||
|
|
||||||
public class PowerUp extends StaticObject {
|
public class PowerUp extends StaticObject {
|
||||||
|
|
||||||
private int pType;
|
/**
|
||||||
|
* Warum auch immer ist JComponent per default serialisierbar
|
||||||
|
*/
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
public PowerUp(Point location) {
|
private int pType;
|
||||||
super('b', location);
|
private boolean triggered = false;
|
||||||
|
private boolean triggeredByPlayer = false;
|
||||||
|
|
||||||
|
private static int tickCount = 0;
|
||||||
|
private static int tickRoundMax = 10000;
|
||||||
|
private static int resetTickstamp = 0;
|
||||||
|
|
||||||
|
public PowerUp() {
|
||||||
|
super('b', new Point());
|
||||||
Random rand = new Random();
|
Random rand = new Random();
|
||||||
this.pType = rand.nextInt(2);
|
this.pType = rand.nextInt(2);
|
||||||
// TODO Auto-generated constructor stub
|
StatusPanelAdder.setPUText(""+pType);
|
||||||
}
|
}
|
||||||
|
public void spawnAt(Point spawnPoint) {
|
||||||
|
this.currentGridPosition = spawnPoint;
|
||||||
|
super.setAutoBounds(spawnPoint.x*25, spawnPoint.y*25);
|
||||||
|
PanelBuilder.getGamePanel().setComponentZOrder(this, 1);
|
||||||
|
this.repaint();
|
||||||
|
}
|
||||||
|
public Point getGridLocation() {
|
||||||
|
return currentGridPosition;
|
||||||
|
}
|
||||||
|
public void kill() {
|
||||||
|
StatusPanelAdder.setPUText(" ");
|
||||||
|
PanelBuilder.getGamePanel().remove(this);
|
||||||
|
PanelBuilder.getGamePanel().repaint();
|
||||||
|
}
|
||||||
|
public boolean isTriggered() {
|
||||||
|
return triggered;
|
||||||
|
}
|
||||||
|
public void tick() {
|
||||||
|
tickCount++;
|
||||||
|
if (tickCount>=tickRoundMax) {
|
||||||
|
tickCount = 0;
|
||||||
|
}
|
||||||
|
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);
|
||||||
|
|
||||||
|
}
|
||||||
|
public void setRemainingTime(int time) {
|
||||||
|
StatusPanelAdder.setPUText(pType+" "+time);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,81 @@
|
|||||||
package de.heatup.objects;
|
package de.heatup.objects;
|
||||||
|
|
||||||
public class PowerUpHandler {
|
import java.awt.Point;
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
|
import de.heatup.logging.Logger;
|
||||||
|
import de.heatup.mapengine.SpawnAssistant;
|
||||||
|
import de.heatup.ui.PanelBuilder;
|
||||||
|
|
||||||
|
public class PowerUpHandler {
|
||||||
|
private static boolean puSpawned = false;
|
||||||
|
private static boolean firstRound = true;
|
||||||
|
private static int tickCount = 0;
|
||||||
|
private static int tickRoundMax = 10000;
|
||||||
|
private static int resetTickstamp = 0;
|
||||||
|
private static PowerUp pu = null;
|
||||||
|
private static Random rand = new Random();
|
||||||
|
public static void tick() {
|
||||||
|
tickCount++;
|
||||||
|
if (tickCount>=tickRoundMax) {
|
||||||
|
tickCount = 0;
|
||||||
|
}
|
||||||
|
if (puSpawned) {
|
||||||
|
int remainingTicks;
|
||||||
|
if (tickCount > resetTickstamp) {
|
||||||
|
remainingTicks = tickRoundMax - tickCount + resetTickstamp;
|
||||||
|
} else {
|
||||||
|
remainingTicks = resetTickstamp - tickCount;
|
||||||
|
}
|
||||||
|
pu.setRemainingTime(remainingTicks/60);
|
||||||
|
if (pu.isTriggered()) {
|
||||||
|
pu.tick();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!firstRound) {
|
||||||
|
if (tickCount == resetTickstamp && !puSpawned) {
|
||||||
|
createPowerUp();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (tickCount == resetTickstamp && puSpawned) {
|
||||||
|
if (!pu.isTriggered()) {
|
||||||
|
removePowerUp();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
firstRound = false;
|
||||||
|
resetTickstamp = tickCount+60*(rand.nextInt(10)+15);
|
||||||
|
resetTickstamp = checkStamp(resetTickstamp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
protected static int checkStamp(int stamp) {
|
||||||
|
if (stamp > tickRoundMax) {
|
||||||
|
return stamp % tickRoundMax;
|
||||||
|
} else {
|
||||||
|
return stamp;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public static void createPowerUp() {
|
||||||
|
Point sp = SpawnAssistant.getPathLocationOnGrid();
|
||||||
|
pu = new PowerUp();
|
||||||
|
pu.setBounds(25, 25, 25, 25);
|
||||||
|
PanelBuilder.getGamePanel().add(pu);
|
||||||
|
pu.spawnAt(sp);
|
||||||
|
resetTickstamp = tickCount+60*(rand.nextInt(15)+15);
|
||||||
|
resetTickstamp = checkStamp(resetTickstamp);
|
||||||
|
puSpawned = true;
|
||||||
|
}
|
||||||
|
public static void removePowerUp() {
|
||||||
|
pu.kill();
|
||||||
|
pu = null;
|
||||||
|
resetTickstamp = tickCount+60*(rand.nextInt(15)+15);
|
||||||
|
resetTickstamp = checkStamp(resetTickstamp);
|
||||||
|
puSpawned = false;
|
||||||
|
}
|
||||||
|
public static PowerUp getPowerUp() {
|
||||||
|
if (pu == null) {
|
||||||
|
return new PowerUp();
|
||||||
|
} else
|
||||||
|
return pu;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ import de.heatup.objects.ImageLoader;
|
|||||||
import de.heatup.objects.InstancedObjects;
|
import de.heatup.objects.InstancedObjects;
|
||||||
import de.heatup.objects.Opponent;
|
import de.heatup.objects.Opponent;
|
||||||
import de.heatup.objects.Player;
|
import de.heatup.objects.Player;
|
||||||
|
import de.heatup.objects.PowerUpHandler;
|
||||||
import de.heatup.timers.HardwareResetTimers;
|
import de.heatup.timers.HardwareResetTimers;
|
||||||
import de.heatup.ui.actionPanel.ActionControl;
|
import de.heatup.ui.actionPanel.ActionControl;
|
||||||
import de.heatup.ui.actionPanel.ActionWatcher;
|
import de.heatup.ui.actionPanel.ActionWatcher;
|
||||||
@@ -82,6 +83,11 @@ public class PanelBuilder {
|
|||||||
StatusPanelAdder.tick();
|
StatusPanelAdder.tick();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
EventQueue.invokeLater(new Runnable() {
|
||||||
|
@Override public void run() {
|
||||||
|
PowerUpHandler.tick();
|
||||||
|
}
|
||||||
|
});
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
Logger.write("Invalid gameState");
|
Logger.write("Invalid gameState");
|
||||||
@@ -108,6 +114,9 @@ public class PanelBuilder {
|
|||||||
createGame(1); /* wird eigentlich vom menue aufgerufen */
|
createGame(1); /* wird eigentlich vom menue aufgerufen */
|
||||||
|
|
||||||
}
|
}
|
||||||
|
public static JPanel getGamePanel() {
|
||||||
|
return gamePanel;
|
||||||
|
}
|
||||||
private static void createGame(int map) {
|
private static void createGame(int map) {
|
||||||
|
|
||||||
instancedObjects = new InstancedObjects();
|
instancedObjects = new InstancedObjects();
|
||||||
|
|||||||
Reference in New Issue
Block a user