Ground.java 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. package com.darkdimension.ritle_run;
  2. import android.graphics.Canvas;
  3. import android.graphics.Paint;
  4. public class Ground extends DiPoint
  5. {
  6. //Ground Width
  7. private int width = 1;
  8. private boolean selfDestruct = false;
  9. private int selfDestructTimer = -1;
  10. public Ground()
  11. {
  12. //Super Constructor
  13. super(15);
  14. }
  15. public boolean update()
  16. {
  17. //If it's being destroyed
  18. if (selfDestructTimer > -1)
  19. {
  20. //Advance animation and check if it's destroyed
  21. if (++selfDestructTimer >= (12 *width)/2)
  22. {
  23. //Make ground off-screen
  24. setBottom(GameSurface.height *2);
  25. //Reset SelfDestruct
  26. selfDestruct = false;
  27. selfDestructTimer = -1;
  28. //Return Destructed
  29. return true;
  30. }
  31. }
  32. return false;
  33. }
  34. public void draw(Canvas canvas, int offsetX, int offsetY, Paint paint)
  35. {
  36. int drawFrame, drawX;
  37. for (int iii = 0; iii < width; iii++)
  38. {
  39. if (selfDestructTimer < (12 *width)/2/2)
  40. drawFrame = frame;
  41. else
  42. drawFrame = 18;
  43. //First Column
  44. if (iii == 0) drawX = 0; else
  45. //Last Column
  46. if (iii == width -1) drawX = 2;
  47. //Between
  48. else drawX = 1;
  49. //First Column
  50. canvas.drawBitmap(image[drawFrame +drawX], x +(iii *image[frame].getWidth()) +offsetX, y +offsetY, paint);
  51. }
  52. }
  53. //Setters
  54. public void setWidth(int amount) {width = amount;}
  55. public void setRight (int amount) {x = amount -(width *image[frame].getWidth());}
  56. public void setCenterX(int amount) {x = amount -(width *image[frame].getWidth())/2;}
  57. public void setSelfDestruct(boolean status) {selfDestruct = status;}
  58. public void selfDestruct()
  59. {
  60. if (selfDestruct)
  61. selfDestructTimer = 0;
  62. }
  63. //Getters
  64. public int getRight () {return x +(image[frame].getWidth () *width);}
  65. public int getCenterX() {return x +(image[frame].getWidth () *width)/2;}
  66. public int getWidth () {return width *image[frame].getWidth ();}
  67. public int getBlockWidth() {return width;}
  68. public int getGroundLevel() {return y +image[frame].getHeight()/4;}
  69. public boolean isSelfDestruct() {return selfDestruct;}
  70. }