CoinAnimation.java 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. package model.drawObjects;
  2. import javax.imageio.ImageIO;
  3. import java.awt.*;
  4. import java.awt.geom.Ellipse2D;
  5. import java.awt.geom.Point2D;
  6. import java.awt.geom.Rectangle2D;
  7. import java.awt.image.BufferedImage;
  8. import java.io.File;
  9. import java.io.IOException;
  10. /**
  11. * Created by Bilel on 4-6-2015.
  12. */
  13. public class CoinAnimation extends DrawObject {
  14. private Ellipse2D coinShape;
  15. private Point2D.Double coinSetPoint;
  16. // Hoevaak de timer gelopen heeft
  17. private static int timerLoops = 0;
  18. public CoinAnimation(int startX, int startY) {
  19. coinSetPoint = new Point2D.Double(startX, startY);
  20. coinShape = new Ellipse2D.Double(startX, startY, 20, 20);
  21. }
  22. public void start() {
  23. timerLoops = 1;
  24. }
  25. public void draw(Graphics2D g2) {
  26. g2.setColor(new Color(255, 255, 0, (255 - timerLoops * 5))); // GEEL
  27. g2.draw(coinShape); // MUNTJE TEKENEN
  28. g2.fill(coinShape);
  29. update(timerLoops); // UPDATE
  30. }
  31. // Wordt na elke paint aangeroepen
  32. public void update(float factor) {
  33. if (areWeDoneYet()) {
  34. System.out.println("Call initCoin(int startX, startY) first!");
  35. return;
  36. }
  37. // Frame steeds aanpassen aan locatie van coin (Zodat hele coin wel te zien blijft)
  38. coinShape.setFrame(coinSetPoint.getX(), coinSetPoint.getY() + 10 * timerLoops,
  39. coinShape.getWidth(), coinShape.getHeight());
  40. timerLoops++;
  41. }
  42. public boolean areWeDoneYet() {
  43. System.out.println(timerLoops);
  44. if (timerLoops > 50 || timerLoops == 0) {
  45. timerLoops = 0;
  46. return true;
  47. }
  48. return false;
  49. }
  50. }