Example #1
0
        /// <summary>
        /// Draws the outline of a shape. Drawing filled shapes is (currently?) only possible for AABB's. See DrawFilledRect.
        /// </summary>
        public static void DrawShapeOutline(Shape shape, Color color, int depth = 0)
        {
            //add the start point at the end of the array so it will draw the last line
            Point[] shapePoints = shape.GetPoints();
            Point[] points = new Point[shapePoints.Length + 1];
            shapePoints.CopyTo(points, 0);
            points[points.Length - 1] = points[0];

            DrawJobs.Add(new LineDrawJob(depth, shape.GetEnclosingRectangle(), points, color));
        }
Example #2
0
        /// <summary>
        /// A teensy quadtree baby.
        /// </summary>
        private QuadTree(byte level, Rectangle bounds, List<PhysicalObject> objects)
        {
            byte level1 = level;
            Rectangle bounds1 = bounds;
            _center = bounds.Position + bounds.Size / 2f;
            Point childSize = bounds.Size / 2f;

            if (objects.Count > MaxObjects)
            {
                //decide in what childtree an object would fit and add it there
                List<PhysicalObject> childObjects0 = new List<PhysicalObject>();
                List<PhysicalObject> childObjects1 = new List<PhysicalObject>();
                List<PhysicalObject> childObjects2 = new List<PhysicalObject>();
                List<PhysicalObject> childObjects3 = new List<PhysicalObject>();

                foreach (PhysicalObject obj in objects)
                {
                    bool[] fits = FitObject(obj);
                    if (!fits[4])
                    {
                        if (fits[0])
                            childObjects0.Add(obj);
                        else if (fits[1])
                            childObjects1.Add(obj);
                        else if (fits[2])
                            childObjects2.Add(obj);
                        else
                            childObjects3.Add(obj);
                    }
                    else
                        _objects.Add(obj);
                }

                //create subtrees and add everything that fits inside of em
                _children[0] = new QuadTree((byte)(level1 + 1), new Rectangle(bounds1.Position, childSize), childObjects0);
                _children[1] = new QuadTree((byte)(level1 + 1), new Rectangle(new Point(_center.X, bounds1.Position.Y), childSize), childObjects1);
                _children[2] = new QuadTree((byte)(level1 + 1), new Rectangle(new Point(bounds1.Position.X, _center.Y), childSize), childObjects2);
                _children[3] = new QuadTree((byte)(level1 + 1), new Rectangle(_center, childSize), childObjects3);
            }
            else
                _objects = objects;
        }
Example #3
0
        public Spritemap(string id, string filename)
            : this(id)
        {
            ManagedSprites = new List<ManagedSprite>();

            BinaryReader reader = Resources.GetStream(filename);

            if (new string(reader.ReadChars(4)) != "HESm")
                throw new ProtocolMismatchException("The file's magic number is not 'HESm' (HatlessEngine Spritemap)");

            if (reader.ReadUInt16() != ProtocolVersion)
                throw new ProtocolMismatchException("The file's protocol version is not equal to the required one (" + ProtocolVersion + ")");

            ushort spriteCount = reader.ReadUInt16();

            for(ushort i = 0; i < spriteCount; i++)
            {
                string targetSprite = reader.ReadString();
                Point position = new Point(reader.ReadSingle(), reader.ReadSingle());
                Point size = new Point(reader.ReadSingle(), reader.ReadSingle());
                Point origin = new Point(reader.ReadSingle(), reader.ReadSingle());
                float rotation = reader.ReadSingle();
                string animationId = reader.ReadString();
                int startIndex = reader.ReadInt32();
                float animationSpeed = reader.ReadSingle();
                sbyte depth = reader.ReadSByte();

                ManagedSprite mSprite = new ManagedSprite(targetSprite, position, animationId, startIndex, animationSpeed, depth)
                {
                    Size = size,
                    Origin = origin,
                    Rotation = rotation
                };

                ManagedSprites.Add(mSprite);
            }

            reader.Close();
        }
Example #4
0
 //left to do: maximizing/minimizing
 /// <summary>
 /// Handles all window related SDL.SDL_events.
 /// </summary>
 internal static void WindowEvent(SDL.SDL_Event e)
 {
     switch (e.window.windowEvent)
     {
         case SDL.SDL_WindowEventID.SDL_WINDOWEVENT_SIZE_CHANGED:
             _size = new Point(e.window.data1, e.window.data2);
             break;
     }
 }
Example #5
0
 public static void SetSize(Point size)
 {
     SDL.SDL_SetWindowSize(Game.WindowHandle, (int)size.X, (int)size.Y);
 }
Example #6
0
 public static void SetResizeLimits(Point minSize, Point maxSize)
 {
     SDL.SDL_SetWindowMinimumSize(Game.WindowHandle, (int)minSize.X, (int)minSize.Y);
     SDL.SDL_SetWindowMaximumSize(Game.WindowHandle, (int)maxSize.X, (int)maxSize.Y);
 }
Example #7
0
 public static void SetPosition(Point pos)
 {
     SDL.SDL_SetWindowPosition(Game.WindowHandle, (int)pos.X, (int)pos.Y);
 }
Example #8
0
 public static void Draw(Sprite sprite, Point pos, int frameIndex = 0, float rotation = 0f, int depth = 0)
 {
     sprite.Draw(pos, frameIndex, rotation, depth);
 }
Example #9
0
 public static void Draw(string str, Font font, Point pos, Color color, CombinedAlignment alignment = CombinedAlignment.TopLeft, int depth = 0)
 {
     font.Draw(str, pos, color, alignment, depth);
 }
Example #10
0
 public static void Draw(Point point, Color color, int depth = 0)
 {
     DrawJobs.Add(new LineDrawJob(depth, new Rectangle(point, Point.Zero), new Point[] { point, point }, color));
 }