DiPoint.java 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. package com.darkdimension.ritle_run;
  2. import android.content.res.Resources;
  3. import android.graphics.Bitmap;
  4. import android.graphics.BitmapFactory;
  5. import android.graphics.Canvas;
  6. import android.graphics.Paint;
  7. public class DiPoint
  8. {
  9. //Graphics
  10. protected static Bitmap[] image;
  11. public static boolean firstChar = true;
  12. //Load Graphics
  13. public static void loadGraphics(Resources resources, int...imageId)
  14. {
  15. //Load graphics
  16. image = new Bitmap[imageId.length];
  17. for (int iii = 0; iii < imageId.length; iii++)
  18. image[iii] = BitmapFactory.decodeResource(resources, imageId[iii]);
  19. }
  20. public static boolean isLoaded() {return image != null;}
  21. public static void changeCharacter(Resources resources)
  22. {
  23. if (firstChar)
  24. {
  25. firstChar = false;
  26. //Run Animation
  27. image[28] = BitmapFactory.decodeResource(resources, R.drawable.diment_run_0);
  28. image[29] = BitmapFactory.decodeResource(resources, R.drawable.diment_run_1);
  29. image[30] = BitmapFactory.decodeResource(resources, R.drawable.diment_run_2);
  30. image[31] = BitmapFactory.decodeResource(resources, R.drawable.diment_run_3);
  31. image[32] = BitmapFactory.decodeResource(resources, R.drawable.diment_run_4);
  32. image[33] = BitmapFactory.decodeResource(resources, R.drawable.diment_run_5);
  33. image[34] = BitmapFactory.decodeResource(resources, R.drawable.diment_run_6);
  34. image[35] = BitmapFactory.decodeResource(resources, R.drawable.diment_run_7);
  35. //Fall - Jump
  36. image[36] = BitmapFactory.decodeResource(resources, R.drawable.diment_fall);
  37. image[37] = BitmapFactory.decodeResource(resources, R.drawable.diment_jump);
  38. //Air Jump Platform
  39. image[40] = BitmapFactory.decodeResource(resources, R.drawable.air_jump_diment);
  40. }
  41. else
  42. {
  43. firstChar = true;
  44. //Run Animation
  45. image[28] = BitmapFactory.decodeResource(resources, R.drawable.darek_run_0);
  46. image[29] = BitmapFactory.decodeResource(resources, R.drawable.darek_run_1);
  47. image[30] = BitmapFactory.decodeResource(resources, R.drawable.darek_run_2);
  48. image[31] = BitmapFactory.decodeResource(resources, R.drawable.darek_run_3);
  49. image[32] = BitmapFactory.decodeResource(resources, R.drawable.darek_run_4);
  50. image[33] = BitmapFactory.decodeResource(resources, R.drawable.darek_run_5);
  51. image[34] = BitmapFactory.decodeResource(resources, R.drawable.darek_run_6);
  52. image[35] = BitmapFactory.decodeResource(resources, R.drawable.darek_run_7);
  53. //Fall - Jump
  54. image[36] = BitmapFactory.decodeResource(resources, R.drawable.darek_fall);
  55. image[37] = BitmapFactory.decodeResource(resources, R.drawable.darek_jump);
  56. //Air Jump Platform
  57. image[40] = BitmapFactory.decodeResource(resources, R.drawable.air_jump_darek);
  58. }
  59. }
  60. //Point
  61. protected int frame;
  62. protected int x = 0, y = 0;
  63. public DiPoint(int gFrame) {frame = gFrame;}
  64. //Touch
  65. public boolean isTouched(int touchX, int touchY)
  66. {
  67. //If touch
  68. if (touchX > x && touchX < x +image[frame].getWidth ()
  69. && touchY > y && touchY < y +image[frame].getHeight())
  70. return true;
  71. //Not touched
  72. return false;
  73. }
  74. //Draw
  75. public void draw(Canvas canvas) {
  76. canvas.drawBitmap(image[frame], x, y, null);}
  77. public void draw(Canvas canvas, Paint paint) {
  78. canvas.drawBitmap(image[frame], x, y, paint);}
  79. public void draw(Canvas canvas, int offsetX, int offsetY) {
  80. canvas.drawBitmap(image[frame], x +offsetX, y +offsetY, null);}
  81. public void draw(Canvas canvas, int offsetX, int offsetY, Paint paint) {
  82. canvas.drawBitmap(image[frame], x +offsetX, y +offsetY, paint);}
  83. //Actions
  84. public void changeX(int amount) {x += amount;}
  85. //public void changeY(int amount) {y += amount;}
  86. //Setters
  87. public void setFrame (int amount) {frame = amount;}
  88. public void setLeft (int amount) {x = amount;}
  89. public void setTop (int amount) {y = amount;}
  90. public void setRight (int amount) {x = amount -image[frame].getWidth ();}
  91. public void setBottom(int amount) {y = amount -image[frame].getHeight();}
  92. public void setCenterX(int amount) {x = amount -image[frame].getWidth ()/2;}
  93. public void setCenterY(int amount) {y = amount -image[frame].getHeight()/2;}
  94. //Getters
  95. public int getFrame() {return frame;}
  96. public int getLeft () {return x;}
  97. public int getTop () {return y;}
  98. public int getRight () {return x +image[frame].getWidth ();}
  99. public int getBottom() {return y +image[frame].getHeight();}
  100. public int getCenterX() {return x +image[frame].getWidth ()/2;}
  101. public int getCenterY() {return y +image[frame].getHeight()/2;}
  102. public int getWidth () {return image[frame].getWidth ();}
  103. public int getHeight() {return image[frame].getHeight();}
  104. public static int getWidth (int graphic) {return image[graphic].getWidth ();}
  105. public static int getHeight(int graphic) {return image[graphic].getHeight();}
  106. public int[] getSquare()
  107. {
  108. int[] returner = new int[4];
  109. returner[0] = x;
  110. returner[1] = y;
  111. returner[2] = x +image[frame].getWidth();
  112. returner[3] = y +image[frame].getHeight();
  113. return returner;
  114. }
  115. public int[] getSquare(int offsetX, int offsetY)
  116. {
  117. int[] returner = new int[4];
  118. returner[0] = x +offsetX;
  119. returner[1] = y +offsetY;
  120. returner[2] = x +image[frame].getWidth () +offsetX;
  121. returner[3] = y +image[frame].getHeight() +offsetY;
  122. return returner;
  123. }
  124. }