public boolean checkContainsPolygon( RectangularShape myShape, float[][] arrPointer, int numberPointer, float pX, float pY) { float myShapeX = myShape.getX(); float myShapeY = myShape.getY(); float arrPoiterTemp[][] = new float[2][numberPointer + 1]; for (int j = 0; j <= 1; j++) { for (int i = 0; i < numberPointer; i++) { if (j == 0) { arrPoiterTemp[j][i] = arrPointer[j][i] + myShapeX; } if (j == 1) { arrPoiterTemp[j][i] = arrPointer[j][i] + myShapeY; } } } boolean c = false; int i, j = 0; for (i = 0, j = numberPointer - 1; i < numberPointer; j = i++) { if (((arrPoiterTemp[1][i] > pY) != (arrPoiterTemp[1][j] > pY)) && (pX < (arrPoiterTemp[0][j] - arrPoiterTemp[0][i]) * (pY - arrPoiterTemp[1][i]) / (arrPoiterTemp[1][j] - arrPoiterTemp[1][i]) + arrPoiterTemp[0][i])) c = !c; } return c; }
/** * Method check Touch Point Contains A Rectangle * * @myShap: A Sprite Or AnimatedSprite on Scene * @x1: Axis coordinates 1 as compared to myShape * @x2: Axis coordinates 2 as compared to myShape * @y1: Axis coordinates 2 as compared to myShape * @y2: Axis coordinates 2 as compared to myShape * @pX, pY: Point Touch */ public boolean checkContains( RectangularShape myShape, int x1, int y1, int x2, int y2, int pX, int pY) { boolean c = false; if (myShape != null) { int myShapeX = (int) myShape.getX(); int myShapeY = (int) myShape.getY(); int polyX[] = new int[] {myShapeX + x1, myShapeX + x1, myShapeX + x2, myShapeX + x2}; int polyY[] = new int[] {myShapeY + y1, myShapeY + y2, myShapeY + y2, myShapeY + y1}; int i, j = 0; for (i = 0, j = 3; i < 4; j = i++) { if (((polyY[i] > pY) != (polyY[j] > pY)) && (pX < (polyX[j] - polyX[i]) * (pY - polyY[i]) / (polyY[j] - polyY[i]) + polyX[i])) c = !c; } } return c; }