Bilel Bghiel il y a 10 ans
Parent
commit
1e09c3e024

+ 66 - 0
model/drawObjects/CoinAnimation.java

@@ -0,0 +1,66 @@
+package model.drawObjects;
+import javax.imageio.ImageIO;
+import java.awt.*;
+import java.awt.geom.Ellipse2D;
+import java.awt.geom.Point2D;
+import java.awt.geom.Rectangle2D;
+import java.awt.image.BufferedImage;
+import java.io.File;
+import java.io.IOException;
+
+/**
+ * Created by Bilel on 4-6-2015.
+ */
+public class CoinAnimation extends DrawObject {
+
+    private Ellipse2D       coinShape;
+    private Point2D.Double  coinSetPoint;
+
+    // Hoevaak de timer gelopen heeft
+    private static int timerLoops = 0;
+
+    public CoinAnimation(int startX, int startY) {
+        coinSetPoint    = new Point2D.Double(startX, startY);
+        coinShape       = new Ellipse2D.Double(startX, startY, 20, 20);
+    }
+
+    public void start() {
+        timerLoops      = 1;
+    }
+
+    public void draw(Graphics2D g2) {
+
+        g2.setColor(new Color(255, 255, 0, (255 - timerLoops * 5)));    // GEEL
+        g2.draw(coinShape);                                             // MUNTJE TEKENEN
+        g2.fill(coinShape);
+        update(timerLoops);                                             // UPDATE
+
+    }
+
+    // Wordt na elke paint aangeroepen
+    public void update(float factor) {
+
+        if (areWeDoneYet()) {
+            System.out.println("Call initCoin(int startX, startY) first!");
+            return;
+        }
+
+        // Frame steeds aanpassen aan locatie van coin (Zodat hele coin wel te zien blijft)
+        coinShape.setFrame(coinSetPoint.getX(), coinSetPoint.getY() + 10 * timerLoops,
+                coinShape.getWidth(), coinShape.getHeight());
+
+        timerLoops++;
+
+    }
+
+    public boolean areWeDoneYet() {
+        System.out.println(timerLoops);
+        if (timerLoops > 50 || timerLoops == 0) {
+            timerLoops = 0;
+            return true;
+        }
+
+        return false;
+    }
+
+}

+ 1 - 0
model/gameState/PlayState.java

@@ -162,6 +162,7 @@ public class PlayState extends GameState {
 					lifePoints = Math.min(lifePoints+10, 100);
 					enemysInPath.remove();
 					notHit = false;
+					infoPanel.throwACoin();
 					break;
 				}
 			}

+ 12 - 1
model/objects/InfoPanel.java

@@ -10,6 +10,7 @@ import java.awt.Transparency;
 import java.awt.image.VolatileImage;
 
 import model.SongHandler;
+import model.drawObjects.CoinAnimation;
 import model.gameState.PlayState;
 
 public class InfoPanel {
@@ -19,11 +20,14 @@ public class InfoPanel {
 	private VolatileImage infoPanel;
 	private SongHandler sh;
 	private String time;
+
+	private CoinAnimation coinAnimation = new CoinAnimation(150, 200);
 	
 	public InfoPanel(int x, int y, SongHandler sh){
 		this.x = x;
 		this.y = y;
 		this.sh = sh;
+
 		updateIPanel();
 		generateInfoPanel();
 	}
@@ -77,12 +81,19 @@ public class InfoPanel {
 			g2.drawString(sh.getCurrentSong().getAuthor(), 25, 230);
 			g2.drawString(time, 25, 260);
 		}
-		
+
+		if (!coinAnimation.areWeDoneYet())
+			coinAnimation.draw(g2);
+
 		g2.setColor(Color.YELLOW);		
 		g2.fillRect(25, 1000 - 7 * PlayState.comboScore, 200, 0 + 7 * PlayState.comboScore);
 		g2.dispose();
 		infoPanel.createGraphics();
 	}
+
+	public void throwACoin() {
+		coinAnimation.start();
+	}
 	
 	public void draw(Graphics2D g2){
 		g2.drawImage(infoPanel, 0, 0, 256,1024,null);