public bool PrimitivesTouches(TexturedPrimitive otherPrim) /// nao é preciso { Vector2 v = mPosition - otherPrim.mPosition; float dist = v.Length(); return(dist < ((mSize.X / 2f) + (otherPrim.mSize.X / 2f))); }
public bool PixelTouches(TexturedPrimitive otherPrim, out Vector2 collidePoint) { bool touches = PrimitivesTouches(otherPrim); collidePoint = mPosition; if (touches) { bool pixelTouch = false; Vector2 myXDir = ShowVector.RotateVectorByAngle(Vector2.UnitX, RotateAngleInRadian); Vector2 myYDir = ShowVector.RotateVectorByAngle(Vector2.UnitY, RotateAngleInRadian); Vector2 otherXDir = ShowVector.RotateVectorByAngle(Vector2.UnitX, otherPrim.RotateAngleInRadian); Vector2 otherYDir = ShowVector.RotateVectorByAngle(Vector2.UnitY, otherPrim.RotateAngleInRadian); int i = 0; while ((!pixelTouch) && (i < SpriteImageWidth)) { int j = 0; while ((!pixelTouch) && (j < SpriteImageHeight)) { collidePoint = IndexToCameraPosition(i, j, myXDir, myYDir); Color myColor = GetColor(i, j); if (myColor.A > 0) { Vector2 otherIndex = otherPrim.CameraPositionToIndex(collidePoint, otherXDir, otherYDir); int xMin = (int)otherIndex.X; int yMin = (int)otherIndex.Y; if ((xMin >= 0) && (xMin < otherPrim.SpriteImageWidth) && (yMin >= 0) && (yMin < otherPrim.SpriteImageHeight)) { pixelTouch = (otherPrim.GetColor(xMin, yMin).A > 0); } } j++; } i++; } touches = pixelTouch; } return(touches); }
static public CameraWindowCollisionStatus CollidedWithCameraWindow(TexturedPrimitive prim) { Vector2 min = CameraWindowLowerLeftPosition; Vector2 max = CameraWindowUpperRightPosition; if (prim.MaxBound.Y > max.Y) { return(CameraWindowCollisionStatus.CollideTop); } if (prim.MinBound.X < min.X) { return(CameraWindowCollisionStatus.CollideLeft); } if (prim.MaxBound.X > max.X) { return(CameraWindowCollisionStatus.CollideRight); } if (prim.MinBound.Y < min.Y) { return(CameraWindowCollisionStatus.CollideBottom); } return(CameraWindowCollisionStatus.InsideWindow); }