From 1e09c3e02456afd541aaa0763536be1584b7ff70 Mon Sep 17 00:00:00 2001 From: Bilel Bghiel Date: Thu, 11 Jun 2015 14:33:33 +0200 Subject: [PATCH] Coin on hit --- model/drawObjects/CoinAnimation.java | 66 ++++++++++++++++++++++++++++ model/gameState/PlayState.java | 1 + model/objects/InfoPanel.java | 13 +++++- 3 files changed, 79 insertions(+), 1 deletion(-) create mode 100644 model/drawObjects/CoinAnimation.java diff --git a/model/drawObjects/CoinAnimation.java b/model/drawObjects/CoinAnimation.java new file mode 100644 index 0000000..3ab2318 --- /dev/null +++ b/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; + } + +} \ No newline at end of file diff --git a/model/gameState/PlayState.java b/model/gameState/PlayState.java index db5f309..a30c7a8 100644 --- a/model/gameState/PlayState.java +++ b/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; } } diff --git a/model/objects/InfoPanel.java b/model/objects/InfoPanel.java index 624d040..43220d6 100644 --- a/model/objects/InfoPanel.java +++ b/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);