diff --git a/HeatUp/src/de/heatup/objects/ImageLoader.java b/HeatUp/src/de/heatup/objects/ImageLoader.java index 8bbbe4f..a717826 100644 --- a/HeatUp/src/de/heatup/objects/ImageLoader.java +++ b/HeatUp/src/de/heatup/objects/ImageLoader.java @@ -25,7 +25,10 @@ public class ImageLoader { break; case Config.wallChar: imageFileName="de/heatup/resources/images/25x25_wall_orange_2.png"; - break; + break; + case 'b': + imageFileName="de/heatup/resources/images/25x25_powerup.png"; + break; case 'u': imageFileName="de/heatup/resources/images/little_green_guy_verysmall.png"; break; diff --git a/HeatUp/src/de/heatup/objects/PowerUp.java b/HeatUp/src/de/heatup/objects/PowerUp.java index b7d770b..d5d8b96 100644 --- a/HeatUp/src/de/heatup/objects/PowerUp.java +++ b/HeatUp/src/de/heatup/objects/PowerUp.java @@ -1,75 +1,68 @@ package de.heatup.objects; -import java.awt.BasicStroke; -import java.awt.Graphics; -import java.awt.Graphics2D; 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 javax.imageio.ImageIO; -import javax.swing.JComponent; +import de.heatup.ui.PanelBuilder; +import de.heatup.ui.StatusPanelAdder; -import de.heatup.cfg.Config; -import de.heatup.logging.Logger; -import de.heatup.mapengine.CollisionHandler; - -public class PowerUp extends JComponent { +public class PowerUp extends StaticObject { + + /** + * Warum auch immer ist JComponent per default serialisierbar + */ private static final long serialVersionUID = 1L; - protected BufferedImage bf1; - protected Graphics2D g2d; - private Point currentGridPosition; - private int type; + private int pType; + 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(); - CollisionHandler.addPowerUpObject(this); - this.type = rand.nextInt(3); + this.pType = rand.nextInt(2); + StatusPanelAdder.setPUText(""+pType); } - - public void setGridLocation(int x, int y) { - currentGridPosition.setLocation(x, y); + 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 paintComponent(Graphics g) { - g2d = (Graphics2D) g; - if (bf1 == null) { - loadBufferedImage(); + 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; } - - g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); - g2d.drawImage(bf1, 0, 0, this); - g2d.setStroke(new BasicStroke(8.0f)); - g2d.finalize(); - } - - public void spawnAt(Point spawnPoint) { - this.currentGridPosition = spawnPoint; - this.setAutoBounds(spawnPoint.x*25, spawnPoint.y*25); - this.repaint(); - } - - protected void loadBufferedImage() { - try { - this.bf1 = ImageIO.read(new File("src/de/heatup/resources/images/powerup.png")); - } catch (IOException e) { - e.printStackTrace(); + if (this.isTriggered() && tickCount == resetTickstamp) { + PowerUpController.deactivate(pType, triggeredByPlayer); + PowerUpHandler.removePowerUp(); } } - - public void setImage(BufferedImage image) { - this.bf1 = image; + 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 setAutoBounds(int x, int y) { - this.setBounds(x, y, this.bf1.getWidth(), this.bf1.getHeight()); + public void setRemainingTime(int time) { + StatusPanelAdder.setPUText(pType+" "+time); } - } diff --git a/HeatUp/src/de/heatup/objects/PowerUpHandler.java b/HeatUp/src/de/heatup/objects/PowerUpHandler.java index 40ccde1..2c9d627 100644 --- a/HeatUp/src/de/heatup/objects/PowerUpHandler.java +++ b/HeatUp/src/de/heatup/objects/PowerUpHandler.java @@ -1,5 +1,81 @@ package de.heatup.objects; +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; + } } diff --git a/HeatUp/src/de/heatup/ui/FontLoader.java b/HeatUp/src/de/heatup/ui/FontLoader.java index 28f8726..f443707 100644 --- a/HeatUp/src/de/heatup/ui/FontLoader.java +++ b/HeatUp/src/de/heatup/ui/FontLoader.java @@ -28,7 +28,7 @@ public class FontLoader { } - public Font getFont(){ + public static Font getFont(){ return ttfBase; } diff --git a/HeatUp/src/de/heatup/ui/PanelBuilder.java b/HeatUp/src/de/heatup/ui/PanelBuilder.java index 97561b8..6007cc2 100644 --- a/HeatUp/src/de/heatup/ui/PanelBuilder.java +++ b/HeatUp/src/de/heatup/ui/PanelBuilder.java @@ -15,6 +15,7 @@ import de.heatup.objects.ImageLoader; import de.heatup.objects.InstancedObjects; import de.heatup.objects.Opponent; import de.heatup.objects.Player; +import de.heatup.objects.PowerUpHandler; import de.heatup.timers.HardwareResetTimers; import de.heatup.ui.actionPanel.ActionControl; import de.heatup.ui.actionPanel.ActionWatcher; @@ -82,6 +83,11 @@ public class PanelBuilder { StatusPanelAdder.tick(); } }); + EventQueue.invokeLater(new Runnable() { + @Override public void run() { + PowerUpHandler.tick(); + } + }); break; default: Logger.write("Invalid gameState"); @@ -108,6 +114,9 @@ public class PanelBuilder { createGame(1); /* wird eigentlich vom menue aufgerufen */ } + public static JPanel getGamePanel() { + return gamePanel; + } private static void createGame(int map) { instancedObjects = new InstancedObjects(); diff --git a/HeatUp/src/de/heatup/ui/StatusPanelAdder.java b/HeatUp/src/de/heatup/ui/StatusPanelAdder.java index e74aebd..6f67288 100644 --- a/HeatUp/src/de/heatup/ui/StatusPanelAdder.java +++ b/HeatUp/src/de/heatup/ui/StatusPanelAdder.java @@ -29,20 +29,24 @@ public class StatusPanelAdder{ private static double tempPlus=0.0; private static double tempMinus=0.0; private static double barSpeed=0.01; + private static float red; + private static float green; + private static float blue; private static boolean ende=false; private static JLabel labelTempC= new JLabel("§"); private static JLabel labelTemp= new JLabel("temperature"); private static JProgressBar tempBar; private static JLabel labelScore= new JLabel("score"); - private static JLabel scoreLabel= new JLabel("new Score Label"); + private static JLabel scoreLabel= new JLabel(" "); private static JLabel labelPowerUp = new JLabel("PowerUp"); - private static JLabel powerUpLabel = new JLabel(/*new ImageIcon("path_to_image.png")*/"powerUpLabel"); + private static JLabel powerUpLabel = new JLabel(" "); private static JLabel labelTime=new JLabel("Time"); private static JLabel timeLabel = new JLabel("0"); private static Font emulogicheading; private static Font emulogictext; private static Font ttfBase; private static FontLoader fl=new FontLoader(); + private static Color tempBarColor= new Color(0,0,255); @@ -73,6 +77,9 @@ public class StatusPanelAdder{ newPanel.setLayout(new FlowLayout(FlowLayout.CENTER, hgap,5)); panel=newPanel; } + public static void setPUText(String s){ + powerUpLabel.setText(s); + } /** * erhöht die Anzahl Manipulationen */ @@ -96,7 +103,7 @@ public class StatusPanelAdder{ timeLabel.setText(Timer.getMinuteS() + ":" + Timer.getSecondsS()); /** - * Temperaturbearbeitung + * Temperaturaktualisierung */ labelTempC.setText(tempBar.getValue() + "°C"); temping=0; @@ -115,6 +122,14 @@ public class StatusPanelAdder{ tempPlus=-1; } } + red=((float)(((tempBar.getValue())-30)/80.0)); + blue=(1-red); + tempBarColor=new Color(red, green,blue, (float)0.525); + tempBar.setForeground(tempBarColor); + + + + if (temping!=0){ Logger.write("Temperatur: " + tempBar.getValue()); @@ -138,7 +153,7 @@ public class StatusPanelAdder{ * fügt dem der Klasse übergebenen Panel Objekte hinzu & formatiert diese */ public static void createPanel(){ - ttfBase=fl.getFont(); + ttfBase=FontLoader.getFont(); emulogicheading = ttfBase.deriveFont(Font.PLAIN, 16); emulogictext= ttfBase.deriveFont(Font.PLAIN, 12); diff --git a/HeatUp/src/de/heatup/ui/actionPanel/ActionControl.java b/HeatUp/src/de/heatup/ui/actionPanel/ActionControl.java index e0018a1..a344ef5 100644 --- a/HeatUp/src/de/heatup/ui/actionPanel/ActionControl.java +++ b/HeatUp/src/de/heatup/ui/actionPanel/ActionControl.java @@ -7,6 +7,7 @@ import java.awt.Font; import javax.swing.*; import de.heatup.mapengine.MapGrid; +import de.heatup.ui.FontLoader; import de.heatup.ui.Main; public class ActionControl{ @@ -22,15 +23,25 @@ public class ActionControl{ private static JLabel bigActionLabel; private static int tmpCount=0; private static boolean keyA=true; + private static Font ttfBase=FontLoader.getFont(); + private static Font emulogicaction; + private static Font emulogicbigaction; public static void setPanel(JPanel newPanel){ + emulogicaction = ttfBase.deriveFont(Font.PLAIN, 12); + emulogicbigaction= ttfBase.deriveFont(Font.LAYOUT_RIGHT_TO_LEFT, 25); + panel = newPanel; + panel.setBackground(Color.BLACK); actionLabel = new JLabel(); bigActionLabel = new JLabel(); bar = new JProgressBar(); - actionLabel.setFont(new Font("Arial", Font.CENTER_BASELINE, 16)); + //actionLabel.setFont(new Font("Arial", Font.CENTER_BASELINE, 16)); + actionLabel.setFont(emulogicaction); actionLabel.setHorizontalAlignment(JLabel.CENTER); - bigActionLabel.setFont(new Font("Arial", Font.LAYOUT_RIGHT_TO_LEFT,40)); + actionLabel.setForeground(Color.YELLOW); + //bigActionLabel.setFont(new Font("Arial", Font.LAYOUT_RIGHT_TO_LEFT,40)); + bigActionLabel.setFont(emulogicbigaction); bigActionLabel.setForeground(Color.RED); bigActionLabel.setHorizontalAlignment(JLabel.CENTER); bigActionLabel.setVisible(false); @@ -46,7 +57,7 @@ public class ActionControl{ if(rd==1){ option=1; setSmash(new Smashing().getKey()); - String str= "Bitte die Taste "+getSmash()+" so schnell wie moeglich druecken"; + String str= "Bitte die Taste --"+getSmash()+"-- so schnell wie moeglich druecken"; actionLabel.setText(str); setProgressBar(0); beforTime=System.nanoTime();