예제 #1
0
        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);
        }
예제 #2
0
        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
        }