DiAnimation.java 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. package com.darkdimension.ritle_run;
  2. public class DiAnimation
  3. {
  4. //Counter for frames
  5. private int[] counter = new int[2];
  6. private boolean positive = false;
  7. public DiAnimation(int frameTime)
  8. {
  9. //Count Frames
  10. counter[0] = frameTime;
  11. counter[1] = 0;
  12. }
  13. public boolean update()
  14. {
  15. //Positive Animation
  16. if (positive && counter[1] < counter[0])
  17. {
  18. //Advance Animation
  19. counter[1]++;
  20. //Return that animation is updated
  21. return true;
  22. }
  23. else
  24. //Negative Animation
  25. if (!positive && counter[1] > 0)
  26. {
  27. //Advance Animation
  28. counter[1]--;
  29. //Return that animation is updated
  30. return true;
  31. }
  32. //Return that animation is not updated
  33. return false;
  34. }
  35. //Commands
  36. public void startFromBeginning() {counter[1] = 0 ; positive = true ;}
  37. public void startFromEnd () {counter[1] = counter[0]; positive = false;}
  38. public void start() {positive = !positive;}
  39. public void start(int frameTime)
  40. {
  41. //Count Frames
  42. counter[0] = frameTime;
  43. counter[1] = 0;
  44. //Start Animation
  45. positive = true;
  46. }
  47. //Isers
  48. public boolean isPositive() {return positive;}
  49. public boolean isAtStart() {return counter[1] == 0 && !positive;}
  50. public boolean isAtEnd() {return counter[1] == counter[0] && positive;}
  51. public boolean isRunning()
  52. {
  53. return
  54. counter[1] > 0 && !positive
  55. || counter[1] < counter[0] && positive;
  56. }
  57. //Getters
  58. public int getCounter() {return counter[1];}
  59. public int getMax() {return counter[0];}
  60. public int getDistance(int amount)
  61. {
  62. return amount *counter[1] /counter[0];
  63. }
  64. //Setters
  65. public void setMax (int amount) {counter[0] = amount;}
  66. public void setCounter(int amount) {counter[1] = amount;}
  67. }