Advertisement
TheBat

shit

Mar 30th, 2012
34
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.04 KB | None | 0 0
  1. /**
  2. * Return the center point between two points of color, indicating where the desire object is.
  3. * Returns (-1,-1) if the point is not found.
  4. *
  5. * @param col1
  6. * - The color value of a point on object.
  7. * @param col2
  8. * - The color value of a point on object.
  9. * @param p
  10. * - the distance x and y between the two points of color.
  11. * @return
  12. */
  13. private Point findItemTwoPoint(Color col1, Color col2, Point p, int tolerance){
  14. Point out = new Point(0,0);
  15. List<Point> test1 = ImageUtil.getPointsWithColor(Game.getImage(), col1,.05);
  16. List<Point> test2 = ImageUtil.getPointsWithColor(Game.getImage(), col2,.05);
  17. boolean breakable = false;
  18. boolean pointFound = false;
  19. for(int i = 0;i < test1.size();i++){
  20. for(int j = 0;j < test2.size();j++){
  21. if(Math.abs(test1.get(i).x - test2.get(j).x - p.x) < tolerance){
  22. if(Math.abs(test1.get(i).y - test2.get(j).y - p.y) < tolerance){
  23. out = new Point((int)((test1.get(i).x + test2.get(j).x)/2),
  24. (int)((test1.get(i).y + test2.get(j).y)/2));
  25. pointFound = true;
  26. breakable = true;
  27. break;
  28.  
  29. }
  30. }
  31. }
  32. if(breakable)break;
  33. }
  34. if(pointFound)return out;
  35. else return new Point(-1,-1);
  36. }
  37.  
  38. /**
  39. * This works with bounds
  40. * Return the center point between two points of color, indicating where the desire object is.
  41. * Returns (-1,-1) if the point is not found.
  42. *
  43. *
  44. * @param col1
  45. * - The color value of a point on object.
  46. * @param col2
  47. * - The color value of a point on object.
  48. * @param p
  49. * - the distance x and y between the two points of color.
  50. * @param TL
  51. * - The top left bound
  52. * @param BR
  53. * - The bottom right bound
  54. * @return
  55. */
  56. private Point findItemTwoPoint(Color col1, Color col2, Point p, int tolerance, Point TL, Point BR){
  57. Point out = new Point(0,0);
  58. List<Point> test1 = ImageUtil.getPointsWithColor(Game.getImage(), new Rectangle(TL.x,TL.y,BR.x-TL.x,BR.y-TL.y), col1,.05);
  59. List<Point> test2 = ImageUtil.getPointsWithColor(Game.getImage(), new Rectangle(TL.x,TL.y,BR.x-TL.x,BR.y-TL.y), col2,.05);
  60. boolean breakable = false;
  61. boolean pointFound = false;
  62. for(int i = 0;i < test1.size();i++){
  63. for(int j = 0;j < test2.size();j++){
  64. if(Math.abs(test1.get(i).x - test2.get(j).x - p.x) < tolerance){
  65. if(Math.abs(test1.get(i).y - test2.get(j).y - p.y) < tolerance){
  66. out = new Point((int)((test1.get(i).x + test2.get(j).x)/2),
  67. (int)((test1.get(i).y + test2.get(j).y)/2));
  68. pointFound = true;
  69. breakable = true;
  70. break;
  71. }
  72. }
  73. }
  74. if(breakable)break;
  75. }
  76. if(pointFound)return out;
  77. else return new Point(-1,-1);
  78. }
  79.  
  80. /**
  81. * Return the center point of a triangle, indicating where the desire object is.
  82. * Returns (-1,-1) if the point is not found.
  83. *
  84. * @param col1
  85. * - The color of the first point
  86. * @param col2
  87. * - The color of the second point
  88. * @param col3
  89. * - The color of the third point
  90. * @param p1
  91. * - The distance between point 1 and point 2
  92. * @param p2
  93. * - The distance between point 1 and point 3
  94. * @param tolerance
  95. * - The distance tolerance in pixels
  96. *
  97. * @return Point the point
  98. */
  99. private Point findItemThreePoint(Color col1, Color col2, Color col3, Point p1, Point p2, int tolerance){
  100. Point out = new Point();
  101. Point pt2 = new Point();
  102. Point pt1 = findItemTwoPoint(col1,col2, p1, tolerance);
  103. if(!pt1.equals(new Point (-1,-1))){
  104. pt2 = findItemTwoPoint(col1,col3, p2, tolerance);
  105. if(!pt2.equals(new Point (-1,-1))){
  106. out = new Point((int)((pt1.x + pt2.x)/2),
  107. (int)((pt1.y + pt2.y)/2));
  108. }else return new Point (-1,-1);
  109. }else return new Point (-1,-1);
  110. return out;
  111. }
  112.  
  113. /**
  114. * This works with bounds
  115. * Return the center point of a triangle, indicating where the desire object is.
  116. * Returns (-1,-1) if the point is not found.
  117. *
  118. * @param col1
  119. * - The color of the first point
  120. * @param col2
  121. * - The color of the second point
  122. * @param col3
  123. * - The color of the third point
  124. * @param p1
  125. * - The distance between point 1 and point 2
  126. * @param p2
  127. * - The distance between point 1 and point 3
  128. * @param tolerance
  129. * - The distance tolerance in pixels
  130. * @param TL
  131. * - The top left corner of the bounds
  132. * @param BR
  133. * - The bottom right corner of the bounds
  134. *
  135. * @return Point the point
  136. */
  137. private Point findItemThreePoint(Color col1, Color col2, Color col3, Point p1, Point p2, int tolerance, Point TL, Point BR){
  138. Point out = new Point();
  139. Point pt2 = new Point();
  140. Point pt1 = findItemTwoPoint(col1,col2, p1, tolerance, TL, BR);
  141. if(!pt1.equals(new Point (-1,-1))){
  142. pt2 = findItemTwoPoint(col1,col3, p2, tolerance,TL, BR);
  143. if(!pt2.equals(new Point (-1,-1))){
  144. out = new Point((int)((pt1.x + pt2.x)/2),
  145. (int)((pt1.y + pt2.y)/2));
  146. }else return new Point (-1,-1);
  147. }else return new Point (-1,-1);
  148. return out;
  149. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement