From a12ee8537faef783dc914f7e1f886982b93427fc Mon Sep 17 00:00:00 2001 From: toksikk Date: Thu, 18 Dec 2014 15:11:00 +0100 Subject: [PATCH 1/5] fuuuu --- HeatUp/src/de/heatup/objects/ImageLoader.java | 5 +- HeatUp/src/de/heatup/objects/PowerUp.java | 56 +++---------------- 2 files changed, 11 insertions(+), 50 deletions(-) diff --git a/HeatUp/src/de/heatup/objects/ImageLoader.java b/HeatUp/src/de/heatup/objects/ImageLoader.java index 06b0ab2..2559d8b 100644 --- a/HeatUp/src/de/heatup/objects/ImageLoader.java +++ b/HeatUp/src/de/heatup/objects/ImageLoader.java @@ -28,7 +28,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..05ed187 100644 --- a/HeatUp/src/de/heatup/objects/PowerUp.java +++ b/HeatUp/src/de/heatup/objects/PowerUp.java @@ -17,59 +17,17 @@ import de.heatup.cfg.Config; import de.heatup.logging.Logger; import de.heatup.mapengine.CollisionHandler; -public class PowerUp extends JComponent { - private static final long serialVersionUID = 1L; - protected BufferedImage bf1; - protected Graphics2D g2d; - private Point currentGridPosition; - private int type; +public class PowerUp extends StaticObject { - public PowerUp() { + private int pType; + + public PowerUp(Point location) { + super('b', location); Random rand = new Random(); - CollisionHandler.addPowerUpObject(this); - this.type = rand.nextInt(3); + this.pType = rand.nextInt(2); + // TODO Auto-generated constructor stub } - public void setGridLocation(int x, int y) { - currentGridPosition.setLocation(x, y); - } - public Point getGridLocation() { - return currentGridPosition; - } - - public void paintComponent(Graphics g) { - g2d = (Graphics2D) g; - if (bf1 == null) { - loadBufferedImage(); - } - - 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(); - } - } - - public void setImage(BufferedImage image) { - this.bf1 = image; - } - - public void setAutoBounds(int x, int y) { - this.setBounds(x, y, this.bf1.getWidth(), this.bf1.getHeight()); - } - } From 34e16ada5d04d16629f6121b1c90cb6774f545df Mon Sep 17 00:00:00 2001 From: feschi55 Date: Thu, 18 Dec 2014 17:11:08 +0100 Subject: [PATCH 2/5] =?UTF-8?q?Schriftarten=20implementiert=20in=20ActionP?= =?UTF-8?q?anel,=20powerUp=20Methode=20hinzugef=C3=BCgt,?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- HeatUp/src/de/heatup/ui/FontLoader.java | 2 +- HeatUp/src/de/heatup/ui/StatusPanelAdder.java | 22 ++++++++++++++++--- .../heatup/ui/actionPanel/ActionControl.java | 15 +++++++++++-- 3 files changed, 33 insertions(+), 6 deletions(-) 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/StatusPanelAdder.java b/HeatUp/src/de/heatup/ui/StatusPanelAdder.java index e74aebd..bc9c240 100644 --- a/HeatUp/src/de/heatup/ui/StatusPanelAdder.java +++ b/HeatUp/src/de/heatup/ui/StatusPanelAdder.java @@ -29,12 +29,15 @@ 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 labelTime=new JLabel("Time"); @@ -43,6 +46,7 @@ public class StatusPanelAdder{ 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,15 @@ public class StatusPanelAdder{ tempPlus=-1; } } + red=((float)(((tempBar.getValue())-30)/80.0)); + blue=(1-red); + Logger.write("Color number" + red); + tempBarColor=new Color(red, green,blue, (float)0.65); + tempBar.setForeground(tempBarColor); + + + + if (temping!=0){ Logger.write("Temperatur: " + tempBar.getValue()); @@ -138,7 +154,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..57e41ae 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); From 366aa1e1c19ec5e10c54239c2af26be836934166 Mon Sep 17 00:00:00 2001 From: feschi55 Date: Thu, 18 Dec 2014 17:13:32 +0100 Subject: [PATCH 3/5] Logger aus StatusPanelAdder entfernt --- HeatUp/src/de/heatup/ui/StatusPanelAdder.java | 1 - 1 file changed, 1 deletion(-) diff --git a/HeatUp/src/de/heatup/ui/StatusPanelAdder.java b/HeatUp/src/de/heatup/ui/StatusPanelAdder.java index bc9c240..309ec37 100644 --- a/HeatUp/src/de/heatup/ui/StatusPanelAdder.java +++ b/HeatUp/src/de/heatup/ui/StatusPanelAdder.java @@ -124,7 +124,6 @@ public class StatusPanelAdder{ } red=((float)(((tempBar.getValue())-30)/80.0)); blue=(1-red); - Logger.write("Color number" + red); tempBarColor=new Color(red, green,blue, (float)0.65); tempBar.setForeground(tempBarColor); From 51d72e0ca0c5a43770ff6e0c19b0e31e83e0437f Mon Sep 17 00:00:00 2001 From: feschi55 Date: Thu, 18 Dec 2014 17:25:00 +0100 Subject: [PATCH 4/5] Farben :) und Fonts :) --- HeatUp/src/de/heatup/ui/StatusPanelAdder.java | 6 +++--- HeatUp/src/de/heatup/ui/actionPanel/ActionControl.java | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/HeatUp/src/de/heatup/ui/StatusPanelAdder.java b/HeatUp/src/de/heatup/ui/StatusPanelAdder.java index 309ec37..6f67288 100644 --- a/HeatUp/src/de/heatup/ui/StatusPanelAdder.java +++ b/HeatUp/src/de/heatup/ui/StatusPanelAdder.java @@ -37,9 +37,9 @@ public class StatusPanelAdder{ private static JLabel labelTemp= new JLabel("temperature"); private static JProgressBar tempBar; private static JLabel labelScore= new JLabel("score"); - private static JLabel scoreLabel= new JLabel(); + 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; @@ -124,7 +124,7 @@ public class StatusPanelAdder{ } red=((float)(((tempBar.getValue())-30)/80.0)); blue=(1-red); - tempBarColor=new Color(red, green,blue, (float)0.65); + tempBarColor=new Color(red, green,blue, (float)0.525); tempBar.setForeground(tempBarColor); diff --git a/HeatUp/src/de/heatup/ui/actionPanel/ActionControl.java b/HeatUp/src/de/heatup/ui/actionPanel/ActionControl.java index 57e41ae..a344ef5 100644 --- a/HeatUp/src/de/heatup/ui/actionPanel/ActionControl.java +++ b/HeatUp/src/de/heatup/ui/actionPanel/ActionControl.java @@ -57,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(); From 21f6ea7f99e169c82335e209d699ab831b33abbb Mon Sep 17 00:00:00 2001 From: toksikk Date: Fri, 19 Dec 2014 11:43:41 +0100 Subject: [PATCH 5/5] PowerUp --- HeatUp/src/de/heatup/objects/PowerUp.java | 73 ++++++++++++----- .../src/de/heatup/objects/PowerUpHandler.java | 78 ++++++++++++++++++- HeatUp/src/de/heatup/ui/PanelBuilder.java | 9 +++ 3 files changed, 140 insertions(+), 20 deletions(-) diff --git a/HeatUp/src/de/heatup/objects/PowerUp.java b/HeatUp/src/de/heatup/objects/PowerUp.java index 05ed187..d5d8b96 100644 --- a/HeatUp/src/de/heatup/objects/PowerUp.java +++ b/HeatUp/src/de/heatup/objects/PowerUp.java @@ -1,33 +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.cfg.Config; -import de.heatup.logging.Logger; -import de.heatup.mapengine.CollisionHandler; +import de.heatup.ui.PanelBuilder; +import de.heatup.ui.StatusPanelAdder; public class PowerUp extends StaticObject { + /** + * Warum auch immer ist JComponent per default serialisierbar + */ + private static final long serialVersionUID = 1L; + 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(Point location) { - super('b', location); + public PowerUp() { + super('b', new Point()); Random rand = new Random(); 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); } - - - } 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/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();