CoinAnimation.java 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. package model.drawObjects;
  2. import java.awt.*;
  3. import java.awt.geom.Ellipse2D;
  4. import java.awt.geom.Point2D;
  5. /**
  6. * Created by Bilel on 4-6-2015.
  7. */
  8. public class CoinAnimation extends DrawObject {
  9. private Ellipse2D coinShape;
  10. private Point2D.Double coinSetPoint;
  11. // Hoevaak de timer gelopen heeft
  12. private static int timerLoops = 0;
  13. public CoinAnimation(int startX, int startY) {
  14. coinSetPoint = new Point2D.Double(startX, startY);
  15. coinShape = new Ellipse2D.Double(startX, startY, 20, 20);
  16. }
  17. // Start
  18. public void start() {
  19. timerLoops = 1;
  20. }
  21. public void draw(Graphics2D g2) {
  22. g2.setColor(new Color(255, 255, 0, (255 - timerLoops * 5))); // GEEL
  23. g2.draw(coinShape); // MUNTJE TEKENEN
  24. g2.fill(coinShape);
  25. update(timerLoops); // UPDATE
  26. }
  27. // Wordt na elke paint aangeroepen
  28. public void update(float factor) {
  29. if (areWeDoneYet()) {
  30. System.out.println("Call initCoin(int startX, startY) first!");
  31. return;
  32. }
  33. // Coin omlaag verschuiven doordat Y * loops omlaag gaat
  34. coinShape.setFrame(coinSetPoint.getX(), coinSetPoint.getY() + 10 * timerLoops,
  35. coinShape.getWidth(), coinShape.getHeight());
  36. timerLoops++;
  37. }
  38. // Zijn we al begonnen/klaar?
  39. public boolean areWeDoneYet() {
  40. if (timerLoops > 50 || timerLoops == 0) {
  41. timerLoops = 0;
  42. return true;
  43. }
  44. return false;
  45. }
  46. public boolean isLastLoop() {
  47. if (timerLoops == 49)
  48. return true;
  49. return false;
  50. }
  51. }