Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Return the center point between two points of color, indicating where the desire object is.
- * Returns (-1,-1) if the point is not found.
- *
- * @param col1
- * - The color value of a point on object.
- * @param col2
- * - The color value of a point on object.
- * @param p
- * - the distance x and y between the two points of color.
- * @return
- */
- private Point findItemTwoPoint(Color col1, Color col2, Point p, int tolerance){
- Point out = new Point(0,0);
- List<Point> test1 = ImageUtil.getPointsWithColor(Game.getImage(), col1,.05);
- List<Point> test2 = ImageUtil.getPointsWithColor(Game.getImage(), col2,.05);
- boolean breakable = false;
- boolean pointFound = false;
- for(int i = 0;i < test1.size();i++){
- for(int j = 0;j < test2.size();j++){
- if(Math.abs(test1.get(i).x - test2.get(j).x - p.x) < tolerance){
- if(Math.abs(test1.get(i).y - test2.get(j).y - p.y) < tolerance){
- out = new Point((int)((test1.get(i).x + test2.get(j).x)/2),
- (int)((test1.get(i).y + test2.get(j).y)/2));
- pointFound = true;
- breakable = true;
- break;
- }
- }
- }
- if(breakable)break;
- }
- if(pointFound)return out;
- else return new Point(-1,-1);
- }
- /**
- * This works with bounds
- * Return the center point between two points of color, indicating where the desire object is.
- * Returns (-1,-1) if the point is not found.
- *
- *
- * @param col1
- * - The color value of a point on object.
- * @param col2
- * - The color value of a point on object.
- * @param p
- * - the distance x and y between the two points of color.
- * @param TL
- * - The top left bound
- * @param BR
- * - The bottom right bound
- * @return
- */
- private Point findItemTwoPoint(Color col1, Color col2, Point p, int tolerance, Point TL, Point BR){
- Point out = new Point(0,0);
- List<Point> test1 = ImageUtil.getPointsWithColor(Game.getImage(), new Rectangle(TL.x,TL.y,BR.x-TL.x,BR.y-TL.y), col1,.05);
- List<Point> test2 = ImageUtil.getPointsWithColor(Game.getImage(), new Rectangle(TL.x,TL.y,BR.x-TL.x,BR.y-TL.y), col2,.05);
- boolean breakable = false;
- boolean pointFound = false;
- for(int i = 0;i < test1.size();i++){
- for(int j = 0;j < test2.size();j++){
- if(Math.abs(test1.get(i).x - test2.get(j).x - p.x) < tolerance){
- if(Math.abs(test1.get(i).y - test2.get(j).y - p.y) < tolerance){
- out = new Point((int)((test1.get(i).x + test2.get(j).x)/2),
- (int)((test1.get(i).y + test2.get(j).y)/2));
- pointFound = true;
- breakable = true;
- break;
- }
- }
- }
- if(breakable)break;
- }
- if(pointFound)return out;
- else return new Point(-1,-1);
- }
- /**
- * Return the center point of a triangle, indicating where the desire object is.
- * Returns (-1,-1) if the point is not found.
- *
- * @param col1
- * - The color of the first point
- * @param col2
- * - The color of the second point
- * @param col3
- * - The color of the third point
- * @param p1
- * - The distance between point 1 and point 2
- * @param p2
- * - The distance between point 1 and point 3
- * @param tolerance
- * - The distance tolerance in pixels
- *
- * @return Point the point
- */
- private Point findItemThreePoint(Color col1, Color col2, Color col3, Point p1, Point p2, int tolerance){
- Point out = new Point();
- Point pt2 = new Point();
- Point pt1 = findItemTwoPoint(col1,col2, p1, tolerance);
- if(!pt1.equals(new Point (-1,-1))){
- pt2 = findItemTwoPoint(col1,col3, p2, tolerance);
- if(!pt2.equals(new Point (-1,-1))){
- out = new Point((int)((pt1.x + pt2.x)/2),
- (int)((pt1.y + pt2.y)/2));
- }else return new Point (-1,-1);
- }else return new Point (-1,-1);
- return out;
- }
- /**
- * This works with bounds
- * Return the center point of a triangle, indicating where the desire object is.
- * Returns (-1,-1) if the point is not found.
- *
- * @param col1
- * - The color of the first point
- * @param col2
- * - The color of the second point
- * @param col3
- * - The color of the third point
- * @param p1
- * - The distance between point 1 and point 2
- * @param p2
- * - The distance between point 1 and point 3
- * @param tolerance
- * - The distance tolerance in pixels
- * @param TL
- * - The top left corner of the bounds
- * @param BR
- * - The bottom right corner of the bounds
- *
- * @return Point the point
- */
- private Point findItemThreePoint(Color col1, Color col2, Color col3, Point p1, Point p2, int tolerance, Point TL, Point BR){
- Point out = new Point();
- Point pt2 = new Point();
- Point pt1 = findItemTwoPoint(col1,col2, p1, tolerance, TL, BR);
- if(!pt1.equals(new Point (-1,-1))){
- pt2 = findItemTwoPoint(col1,col3, p2, tolerance,TL, BR);
- if(!pt2.equals(new Point (-1,-1))){
- out = new Point((int)((pt1.x + pt2.x)/2),
- (int)((pt1.y + pt2.y)/2));
- }else return new Point (-1,-1);
- }else return new Point (-1,-1);
- return out;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement