public bool isRectOnFloor(Bounds bounds, Direction facing, Entity e = null) { Rectangle rect = bounds.Rect; rect.Y += 1; bool onFloor = false; Vector2 bottom = new Vector2((int)(rect.Center.X / SPRITE_SIZE), (int)(rect.Bottom / SPRITE_SIZE)); for (int y = (int)bottom.Y; y < bottom.Y + 1; y++) { for (int x = (int)bottom.X - 1; x < bottom.X + 1; x++) { // Console.Write(" On floor:"); BoundingRect objRect = getRect(x, y); if (e != null && objRect.isBasePriority(rect)) { objRect.onStand(e); } int top = objRect.getTop(bounds, facing); if (!onFloor && rect.Bottom >= top && objRect.collides(rect)) { if (e != null) { objRect.onStand(e); } onFloor = true; } } } return(onFloor); }
public int checkBoundsYDown(Bounds bounds, Direction facing) { Rectangle rect = bounds.Rect; Vector2 pos = new Vector2((int)Math.Round(rect.Center.X / (float)SPRITE_SIZE), (int)Math.Round(rect.Center.Y / (float)SPRITE_SIZE)); int topmost = rect.Bottom; for (int x = (int)pos.X - 1; x < pos.X + 1; x++) { // Console.Write(" Y-Down: "); BoundingRect objRect = getRect(x, (int)pos.Y); int top = objRect.getTop(bounds, facing); if (objRect.isBasePriority(rect)) { topmost = top; break; } else if (top < topmost && objRect.collides(rect)) { topmost = top; } } return(topmost - rect.Height); // Move back to the top left corner }
public int checkBoundsYUp(Bounds bounds, Direction facing) { Rectangle rect = bounds.Rect; Vector2 pos = new Vector2((int)(rect.Center.X / SPRITE_SIZE), (int)(rect.Top / SPRITE_SIZE)); int bottommost = rect.Top; for (int x = (int)pos.X - 1; x < pos.X + 1; x++) { // Console.Write(" Y-Up: "); BoundingRect objRect = getRect(x, (int)pos.Y); int bottom = objRect.getBottom(bounds, facing); if (bottom > bottommost && objRect.collides(rect)) { bottommost = bottom; } } return(bottommost); }
public int checkBoundsXLeft(Bounds bounds, Direction facing) { Rectangle rect = bounds.Rect; Vector2 pos = new Vector2(rect.Left / SPRITE_SIZE, (int)Math.Round((float)rect.Bottom / SPRITE_SIZE)); int rightmost = rect.Left; for (int x = (int)pos.X + 1; x >= pos.X; x--) { for (int y = (int)pos.Y - 1; y <= pos.Y + 1; y++) { BoundingRect objRect = getRect(x, y); int right = objRect.getRight(bounds, facing); if (right > rightmost && objRect.collides(rect)) { rightmost = right; } } } return(rightmost); }
public int checkBoundsXRight(Bounds bounds, Direction facing) { Rectangle rect = bounds.Rect; Vector2 pos = new Vector2(rect.Right / SPRITE_SIZE, (int)Math.Round((float)rect.Bottom / SPRITE_SIZE)); int leftmost = rect.Right; for (int x = (int)pos.X; x >= pos.X - 1; x--) { for (int y = (int)pos.Y - 1; y <= pos.Y + 1; y++) { BoundingRect objRect = getRect(x, y); int left = objRect.getLeft(bounds, facing); if (left < leftmost && objRect.collides(rect)) { leftmost = left; } } } return(leftmost - rect.Width); // Move back to the top left corner }