Ejemplo n.º 1
0
        /// <summary>
        ///     Initializes a new Player class.
        /// </summary>
        /// <param name="texture">The Texture.</param>
        /// <param name="texture2">The ErasedTexture.</param>
        public Player(Texture2D texture, Texture2D texture2)
        {
            _erased = texture2;
            Bounds = new Polygon(new Vector2(1, 6), new Vector2(5, 4), new Vector2(11, 0), new Vector2(22, 0), new Vector2(28, 6),
                new Vector2(28, 11), new Vector2(31, 15), new Vector2(28, 21), new Vector2(19, 21), new Vector2(18, 23),
                new Vector2(9, 23), new Vector2(0, 13), new Vector2(1, 7));
            _pen = new Pen(Color.White, 1);
            _spriteSheet = new AnimatedSpriteSheet(texture) {AutoUpdate = true};
            _spriteSheet.Add(new Keyframe(new Rectangle(0, 0, 32, 24), 100));
            _spriteSheet.Add(new Keyframe(new Rectangle(32, 0, 32, 24), 100));
            _spriteSheet.Add(new Keyframe(new Rectangle(64, 0, 32, 24), 100));
            _spriteSheet.Add(new Keyframe(new Rectangle(96, 0, 32, 24), 100));
            _spriteSheet.Add(new Keyframe(new Rectangle(128, 0, 32, 24), 100));
            _spriteSheet.Add(new Keyframe(new Rectangle(160, 0, 32, 24), 100));
            _spriteSheet.Add(new Keyframe(new Rectangle(192, 0, 32, 24), 100));

            _spriteSheet.Add(new Keyframe(new Rectangle(224, 0, 32, 24), 100));
            _spriteSheet.Add(new Keyframe(new Rectangle(256, 0, 32, 24), 100));
            _spriteSheet.Add(new Keyframe(new Rectangle(288, 0, 32, 24), 100));
            _spriteSheet.Add(new Keyframe(new Rectangle(320, 0, 32, 24), 100));
            _spriteSheet.Add(new Keyframe(new Rectangle(352, 0, 32, 24), 100));

            Position = new Vector2(300, 230);
            Velocity = new Vector2(0, 0);
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Initializes a new Ellipse class.
 /// </summary>
 /// <param name="radiusX">The X-Radius.</param>
 /// <param name="radiusY">The Y-Radius.</param>
 /// <param name="Position">The position.</param>
 public Ellipse(float radiusX, float radiusY, Vector2 Position)
     : this()
 {
     RadiusX = radiusX;
     RadiusY = radiusY;
     _position = Position;
     _polygon = new Polygon();
     UpdateEllipse();
 }
Ejemplo n.º 3
0
 /// <summary>
 /// Fills a Polygon.
 /// </summary>
 /// <param name="color">The Color.</param>
 /// <param name="polygon">The Polygon.</param>
 public void FillPolygon(Color color, Polygon polygon)
 {
     throw new NotSupportedException("FillPolygon is not supported by DirectX9.");
 }
Ejemplo n.º 4
0
        /// <summary>
        /// Draws a Polygon.
        /// </summary>
        /// <param name="pen">The Pen.</param>
        /// <param name="polygon">The Polygon.</param>
        public void DrawPolygon(Pen pen, Polygon polygon)
        {
            var dxPen = pen.Instance as DirectXPen;
            if (dxPen == null) throw new ArgumentException("DirectX9 expects a DirectXPen as resource.");

            var line = new Line(_direct3D9Device) {Antialias = true, Width = dxPen.Width};
            line.Begin();
            line.Draw(DirectXHelper.ConvertToVertex(polygon.Points), DirectXHelper.ConvertColor(dxPen.Color));
            line.End();
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Fills a Polygon.
        /// </summary>
        /// <param name="color">The Color.</param>
        /// <param name="polygon">The Polygon.</param>
        public void FillPolygon(Color color, Polygon polygon)
        {
            var geometry = new PathGeometry(DirectXHelper.Direct2DFactory);
            using (GeometrySink sink = geometry.Open())
            {
                sink.BeginFigure(DirectXHelper.ConvertVector(polygon.Points[0]), FigureBegin.Filled);

                for (int i = 1; i < polygon.Points.Length; i++)
                    sink.AddLine(DirectXHelper.ConvertVector(polygon.Points[i]));

                sink.EndFigure(FigureEnd.Closed);
                sink.Close();

                _renderTarget.FillGeometry(geometry,
                    new SolidColorBrush(DirectXHelper.RenderTarget, DirectXHelper.ConvertColor(color)));
            }

            geometry.Dispose();
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Draws a Polygon.
        /// </summary>
        /// <param name="pen">The Pen.</param>
        /// <param name="polygon">The Polygon.</param>
        public void DrawPolygon(Pen pen, Polygon polygon)
        {
            var dxPen = pen.Instance as DirectXPen;
            if (dxPen == null) throw new ArgumentException("DirectX10 expects a DirectXPen as resource.");

            var geometry = new PathGeometry(DirectXHelper.Direct2DFactory);
            using (GeometrySink sink = geometry.Open())
            {
                sink.BeginFigure(DirectXHelper.ConvertVector(polygon.Points[0]), FigureBegin.Hollow);

                for (int i = 1; i < polygon.Points.Length; i++)
                    sink.AddLine(DirectXHelper.ConvertVector(polygon.Points[i]));

                sink.EndFigure(FigureEnd.Closed);
                sink.Close();

                _renderTarget.DrawGeometry(geometry, dxPen.GetPen(), dxPen.Width);
            }

            geometry.Dispose();
        }
Ejemplo n.º 7
0
 /// <summary>
 /// Updates the Ellipse if something changed.
 /// </summary>
 private void UpdateEllipse()
 {
     var points = new List<Vector2>();
     for (int i = 1; i <= 360; i++)
     {
         points.Add(new Vector2(RadiusX*MathHelper.Cos(i*(float) MathHelper.PiOverOneEighty) + _position.X,
             RadiusY*MathHelper.Sin(i*(float) MathHelper.PiOverOneEighty) + _position.Y));
     }
     _polygon = new Polygon(points.ToArray());
 }
Ejemplo n.º 8
0
        /// <summary>
        ///     A value indicating whether the Polygon has a seperating axis.
        /// </summary>
        /// <param name="other">The other Polygon.</param>
        /// <param name="minOverlap">The MinimumOverlap.</param>
        /// <param name="axis">The Axis.</param>
        /// <returns>True of seperating axis.</returns>
        private bool HasSeparatingAxisTo(Polygon other, ref float minOverlap, ref Vector2 axis)
        {
            int prev = Points.Length - 1;
            for (int i = 0; i < Points.Length; i++)
            {
                Vector2 edge = Points[i] - Points[prev];

                var v = new Vector2(edge.X, edge.Y);
                v = v.CrossProduct();
                v.Normalize();

                float aMin, aMax, bMin, bMax;
                ProjectTo(v, out aMin, out aMax);
                other.ProjectTo(v, out bMin, out bMax);

                if ((aMax < bMin) || (bMax < aMin))
                    return true;

                float overlapping = aMax < bMax ? aMax - bMin : bMax - aMin;
                if (overlapping < minOverlap)
                {
                    minOverlap = overlapping;
                    axis = v;
                }

                prev = i;
            }

            return false;
        }
Ejemplo n.º 9
0
 /// <summary>
 ///     Checks if this Polygon intersects with another Polygon.
 /// </summary>
 /// <param name="other">The other Polygon.</param>
 /// <returns>True if intersecting.</returns>
 public bool Intersects(Polygon other)
 {
     Vector2 mtv;
     return Intersects(other, out mtv);
 }
Ejemplo n.º 10
0
        /// <summary>
        ///     Checks if this Polygon intersects with another Polygon.
        /// </summary>
        /// <param name="other">The other Polygon.</param>
        /// <param name="minimumTranslationVector">
        ///     Returns a vector with which the Polygon has to be translated at minimum to not
        ///     collide with the second Polygon.
        /// </param>
        /// <returns>True of intersecting.</returns>
        public bool Intersects(Polygon other, out Vector2 minimumTranslationVector)
        {
            if (!IsValid || !other.IsValid)
                throw new InvalidOperationException();

            minimumTranslationVector = default(Vector2);
            float minOverlap = float.MaxValue;

            if (HasSeparatingAxisTo(other, ref minOverlap, ref minimumTranslationVector))
                return false;

            if (other.HasSeparatingAxisTo(this, ref minOverlap, ref minimumTranslationVector))
                return false;

            Vector2 d = Center - other.Center;
            if (Vector2.Dot(d, minimumTranslationVector) > 0)
                minimumTranslationVector = -minimumTranslationVector;
            minimumTranslationVector *= minOverlap;

            return true;
        }
Ejemplo n.º 11
0
 /// <summary>
 /// A value indicating whether the Polygon intersects with the PolygonContainer.
 /// </summary>
 /// <param name="polygon">The Polygon.</param>
 /// <returns>True if intersecting.</returns>
 public bool Intersects(Polygon polygon)
 {
     return _innerPolygons.Any(selectedPolygon => selectedPolygon.Value.Intersects(polygon));
 }
Ejemplo n.º 12
0
 /// <summary>
 /// Adds a new Polygon.
 /// </summary>
 /// <param name="index">The Index.</param>
 /// <param name="polygon">The Polygon.</param>
 public void Add(int index, Polygon polygon)
 {
     _innerPolygons.Add(index, polygon);
 }
Ejemplo n.º 13
0
        /// <summary>
        /// A value indicating whether the Polygon intersects with the PolygonContainer.
        /// </summary>
        /// <param name="polygon">The Polygon.</param>
        /// <param name="indices">The Indices which are intersects.</param>
        /// <returns>True if intersecting.</returns>
        public bool IntersectsWith(Polygon polygon, out int[] indices)
        {
            bool flag = false;
            var indicesList = new List<int>();

            foreach (
                KeyValuePair<int, Polygon> selectedPolygon in
                    _innerPolygons.Where(selectedPolygon => selectedPolygon.Value.Intersects(polygon)))
            {
                indicesList.Add(selectedPolygon.Key);
                flag = true;
            }

            indices = indicesList.ToArray();
            return flag;
        }