Esempio n. 1
0
        public void AddSolid()
        {
            if (!Dead)
            {
                _floor = BodyFactory.CreateRectangle(_world, ConvertUnits.ToSimUnits(Globals.SmallGridSize.X),
                                                     ConvertUnits.ToSimUnits(Globals.SmallGridSize.Y), 30f);
                _floor.Position = ConvertUnits.ToSimUnits(_position.X + _centerVect.X, _position.Y + _centerVect.Y);
                _floor.IsStatic = true;
                _floor.Restitution = _stats.Restitution;
                _floor.Friction = _stats.Friction;
                //_bullet.LinearDamping = 0.2f;
                //_bullet.AngularDamping = 0.2f;
                _floor.Enabled = false;
                _floor.UserData = "caveblock";

                hull = ShadowHull.CreateRectangle(new Vector2(Globals.SmallGridSize.X, Globals.SmallGridSize.Y));
                hull.Position.X = _position.X + _centerVect.X;
                hull.Position.Y = _position.Y + _centerVect.Y;
                krypton.Hulls.Add(hull);
                hull.Visible = false;

                SSolid = true;
                GoingtobeSolid = false;
            }
        }
Esempio n. 2
0
        public void BufferAddShadowHull(ShadowHull hull)
        {
            // Why do we need all of these again? (hint: we don't)

            var vertexMatrix = Matrix.Identity;
            var normalMatrix = Matrix.Identity;

            // Create the matrices (3X speed boost versus prior version)
            var cos = (float)Math.Cos(hull.Angle);
            var sin = (float)Math.Sin(hull.Angle);

            // vertexMatrix = scale * rotation * translation;
            vertexMatrix.M11 = hull.Scale.X * cos;
            vertexMatrix.M12 = hull.Scale.X * sin;
            vertexMatrix.M21 = hull.Scale.Y * -sin;
            vertexMatrix.M22 = hull.Scale.Y * cos;
            vertexMatrix.M41 = hull.Position.X;
            vertexMatrix.M42 = hull.Position.Y;

            // normalMatrix = scaleInv * rotation;
            normalMatrix.M11 = 1f / hull.Scale.X * cos;
            normalMatrix.M12 = 1f / hull.Scale.X * sin;
            normalMatrix.M21 = 1f / hull.Scale.Y * -sin;
            normalMatrix.M22 = 1f / hull.Scale.Y * cos;

            // Where are we in the buffer?
            var vertexCount = ShadowHullVertices.Count;

            // Add the vertices to the buffer
            for (var i = 0; i < hull.NumPoints; i++)
            {
                // Transform the vertices to screen coordinates
                var point = hull.Points[i];

                ShadowHullVertex hullVertex;

                Vector2.Transform(
                    ref point.Position,
                    ref vertexMatrix,
                    out hullVertex.Position);

                Vector2.TransformNormal(
                    ref point.Normal,
                    ref normalMatrix,
                    out hullVertex.Normal);

                hullVertex.Color = new Color(
                    r: 0,
                    g: 0,
                    b: 0,
                    a: 1 - hull.Opacity);

                ShadowHullVertices.Add(hullVertex);
            }

            foreach (var index in hull.Indicies)
            {
                ShadowHullIndicies.Add(vertexCount + index);
            }
        }
Esempio n. 3
0
        public override void Load(Core.Content.LoadManager content)
        {
            ShadowHull = GenerateShadowHull();

            LightingComponent.Krypton.Hulls.Add(ShadowHull);

            base.Load(content);
        }
Esempio n. 4
0
        /// <summary>
        /// Creates a circular shadow hull
        /// </summary>
        /// <param name="radius">radius of the circle</param>
        /// <param name="sides">number of sides the circle will be comprised of</param>
        /// <returns>A circular shadow hull</returns>
        public static ShadowHull CreateCircle(float radius, int sides)
        {
            // Validate input
            if (sides < 3)
            {
                throw new ArgumentException("Shadow hull must have at least 3 sides.");
            }

            ShadowHull hull = new ShadowHull();

            hull.MaxRadius = radius;

            // Calculate number of sides
            hull.NumPoints = sides * 2;
            var numTris = hull.NumPoints - 2;

            hull.NumIndicies = numTris * 3;

            hull.Points   = new ShadowHullPoint[hull.NumPoints];
            hull.Indicies = new Int32[hull.NumIndicies];

            var angle       = (float)(-Math.PI * 2) / sides; // XNA Renders Clockwise
            var angleOffset = angle / 2;

            for (int i = 0; i < sides; i++)
            {
                // Create vertices
                var v1 = new ShadowHullPoint();
                var v2 = new ShadowHullPoint();

                // Vertex Position
                v1.Position.X = (float)Math.Cos(angle * i) * radius;
                v1.Position.Y = (float)Math.Sin(angle * i) * radius;

                v2.Position.X = (float)Math.Cos(angle * (i + 1)) * radius;
                v2.Position.Y = (float)Math.Sin(angle * (i + 1)) * radius;

                // Vertex Normal
                v1.Normal.X = (float)Math.Cos(angle * i + angleOffset);
                v1.Normal.Y = (float)Math.Sin(angle * i + angleOffset);

                v2.Normal.X = (float)Math.Cos(angle * i + angleOffset);
                v2.Normal.Y = (float)Math.Sin(angle * i + angleOffset);

                // Copy vertices
                hull.Points[i * 2 + 0] = v1;
                hull.Points[i * 2 + 1] = v2;
            }

            for (int i = 0; i < numTris; i++)
            {
                hull.Indicies[i * 3 + 0] = 0;
                hull.Indicies[i * 3 + 1] = (Int16)(i + 1);
                hull.Indicies[i * 3 + 2] = (Int16)(i + 2);
            }

            return(hull);
        }
Esempio n. 5
0
        public BasicHull(Vector2 position, Vector2 size)
        {
            Vector2 newPosition = new Vector2();
            newPosition.X = position.X - Globals.ScreenWidthCenter + (size.X / 2);
            newPosition.Y = -position.Y + Globals.ScreenHeightCenter - (size.Y / 2);

            ShadowHull pHull = ShadowHull.CreateRectangle(size);
            pHull.Position = newPosition;

            mShadowHull = pHull;
        }
Esempio n. 6
0
        /// <summary>
        /// Creates a custom shadow hull based on a series of vertices
        /// </summary>
        /// <param name="points">The points which the shadow hull will be comprised of</param>
        /// <returns>A custom shadow hulll</returns>
        public static ShadowHull CreateConvex(ref Vector2[] points)
        {
            // Validate input
            if (points == null)
            {
                throw new ArgumentNullException("Points cannot be null.");
            }
            if (points.Length < 3)
            {
                throw new ArgumentException("Need at least 3 points to create shadow hull.");
            }

            var numPoints = points.Length;

            ShadowHull hull = new ShadowHull();

            hull.NumPoints = numPoints * 2;
            var numTris = hull.NumPoints - 2;

            hull.NumIndicies = numTris * 3;

            hull.Points   = new ShadowHullPoint[hull.NumPoints];
            hull.Indicies = new Int32[hull.NumIndicies];

            Vector2 pointMin = points[0];
            Vector2 pointMax = points[0];

            for (int i = 0; i < numPoints; i++)
            {
                var p1 = points[(i + 0) % numPoints];
                var p2 = points[(i + 1) % numPoints];

                hull.MaxRadius = Math.Max(hull.MaxRadius, p1.Length());

                var line = p2 - p1;

                var normal = new Vector2(-line.Y, +line.X);

                normal.Normalize();

                hull.Points[i * 2 + 0] = new ShadowHullPoint(p1, normal);
                hull.Points[i * 2 + 1] = new ShadowHullPoint(p2, normal);
            }

            for (Int16 i = 0; i < numTris; i++)
            {
                hull.Indicies[i * 3 + 0] = 0;
                hull.Indicies[i * 3 + 1] = (Int16)(i + 1);
                hull.Indicies[i * 3 + 2] = (Int16)(i + 2);
            }

            return(hull);
        }
        public void BufferAddShadowHull(ShadowHull hull)
        {
            // Why do we need all of these again? (hint: we don't)

            Matrix vertexMatrix = Matrix.Identity;
            Matrix normalMatrix = Matrix.Identity;

            float cos, sin;

            ShadowHullPoint point;
            ShadowHullVertex hullVertex;

            // Create the matrices (3X speed boost versus prior version)
            cos = (float)Math.Cos(hull.Angle);
            sin = (float)Math.Sin(hull.Angle);

            // vertexMatrix = scale * rotation * translation;
            vertexMatrix.M11 = hull.Scale.X * cos;
            vertexMatrix.M12 = hull.Scale.X * sin;
            vertexMatrix.M21 = hull.Scale.Y * -sin;
            vertexMatrix.M22 = hull.Scale.Y * cos;
            vertexMatrix.M41 = hull.Position.X;
            vertexMatrix.M42 = hull.Position.Y;

            // normalMatrix = scaleInv * rotation;
            normalMatrix.M11 = (1f / hull.Scale.X) * cos;
            normalMatrix.M12 = (1f / hull.Scale.X) * sin;
            normalMatrix.M21 = (1f / hull.Scale.Y) * -sin;
            normalMatrix.M22 = (1f / hull.Scale.Y) * cos;

            // Where are we in the buffer?
            var vertexCount = this.mShadowHullVertices.Count;

            // Add the vertices to the buffer
            for (int i = 0; i < hull.NumPoints; i++)
            {

                // Transform the vertices to screen coordinates
                point = hull.Points[i];
                Vector2.Transform(ref point.Position, ref vertexMatrix, out hullVertex.Position);
                Vector2.TransformNormal(ref point.Normal, ref normalMatrix, out hullVertex.Normal);

                hullVertex.Color = Color.Black;

                this.mShadowHullVertices.Add(hullVertex); // could this be sped up... ?
            }

            //// Add the indicies to the buffer
            foreach (int index in hull.Indicies)
            {
                mShadowHullIndicies.Add(vertexCount + index); // what about this? Add range?
            }
        }
        public void BufferAddShadowHull(ShadowHull hull)
        {
            // Why do we need all of these again? (hint: we don't)

            Matrix vertexMatrix = Matrix.Identity;
            Matrix normalMatrix = Matrix.Identity;

            float cos, sin;

            ShadowHullPoint  point;
            ShadowHullVertex hullVertex;

            // Create the matrices (3X speed boost versus prior version)
            cos = (float)Math.Cos(hull.Angle);
            sin = (float)Math.Sin(hull.Angle);

            // vertexMatrix = scale * rotation * translation;
            vertexMatrix.M11 = hull.Scale.X * cos;
            vertexMatrix.M12 = hull.Scale.X * sin;
            vertexMatrix.M21 = hull.Scale.Y * -sin;
            vertexMatrix.M22 = hull.Scale.Y * cos;
            vertexMatrix.M41 = hull.Position.X;
            vertexMatrix.M42 = hull.Position.Y;

            // normalMatrix = scaleInv * rotation;
            normalMatrix.M11 = (1f / hull.Scale.X) * cos;
            normalMatrix.M12 = (1f / hull.Scale.X) * sin;
            normalMatrix.M21 = (1f / hull.Scale.Y) * -sin;
            normalMatrix.M22 = (1f / hull.Scale.Y) * cos;

            // Where are we in the buffer?
            var vertexCount = this.mShadowHullVertices.Count;

            // Add the vertices to the buffer
            for (int i = 0; i < hull.NumPoints; i++)
            {
                // Transform the vertices to screen coordinates
                point = hull.Points[i];
                Vector2.Transform(ref point.Position, ref vertexMatrix, out hullVertex.Position);
                Vector2.TransformNormal(ref point.Normal, ref normalMatrix, out hullVertex.Normal);

                hullVertex.Color = new Color(0, 0, 0, 1 - hull.Opacity);

                this.mShadowHullVertices.Add(hullVertex); // could this be sped up... ?
            }

            //// Add the indicies to the buffer
            foreach (int index in hull.Indicies)
            {
                mShadowHullIndicies.Add(vertexCount + index); // what about this? Add range?
            }
        }
Esempio n. 9
0
        /// <summary>
        /// Creates a custom shadow hull based on a series of vertices
        /// </summary>
        /// <param name="points">The points which the shadow hull will be comprised of</param>
        /// <returns>A custom shadow hulll</returns>
        public static ShadowHull CreateConvex(ref Vector2[] points)
        {
            // Validate input
            if (points == null)
            {
                throw new ArgumentNullException(nameof(points));
            }
            if (points.Length < 3)
            {
                throw new ArgumentOutOfRangeException(nameof(points), "Need at least 3 points to create shadow hull.");
            }

            var numPoints = points.Length;

            var hull = new ShadowHull();

            hull.NumPoints = numPoints * 2;
            var numTris = hull.NumPoints - 2;

            hull.NumIndicies = numTris * 3;

            hull.Points   = new ShadowHullPoint[hull.NumPoints];
            hull.Indicies = new int[hull.NumIndicies];

            for (var i = 0; i < numPoints; i++)
            {
                var p1 = points[(i + 0) % numPoints];
                var p2 = points[(i + 1) % numPoints];

                hull.MaxRadius = Math.Max(hull.MaxRadius, p1.Length());

                var line = p2 - p1;

                var normal = new Vector2(-line.Y, +line.X);

                normal.Normalize();

                hull.Points[i * 2 + 0] = new ShadowHullPoint(p1, normal);
                hull.Points[i * 2 + 1] = new ShadowHullPoint(p2, normal);
            }

            for (var i = 0; i < numTris; i++)
            {
                hull.Indicies[i * 3 + 0] = 0;
                hull.Indicies[i * 3 + 1] = i + 1;
                hull.Indicies[i * 3 + 2] = i + 2;
            }

            return(hull);
        }
Esempio n. 10
0
        /// <summary> Creates a circular shadow hull </summary>
        /// <param name="radius">radius of the circle</param>
        /// <param name="sides">number of sides the circle will be comprised of</param>
        /// <returns>A circular shadow hull</returns>
        public static ShadowHull CreateCircle(float radius, int sides)
        {
            // Validate input
            if (sides < 3) { throw new ArgumentException("Shadow hull must have at least 3 sides."); }

            var hull = new ShadowHull { MaxRadius = radius, NumPoints = sides * 2 };

            // Calculate number of sides
            var numTris = hull.NumPoints - 2;
            hull.NumIndicies = numTris * 3;

            hull.Points = new ShadowHullPoint[hull.NumPoints];
            hull.Indicies = new Int32[hull.NumIndicies];

            var angle = (float)(-Math.PI * 2) / sides; // XNA Renders Clockwise
            var angleOffset = angle / 2;

            for (int i = 0; i < sides; i++) {
                // Create vertices
                var v1 = new ShadowHullPoint();
                var v2 = new ShadowHullPoint();

                // Vertex Position
                v1.Position.X = (float)Math.Cos(angle * i) * radius;
                v1.Position.Y = (float)Math.Sin(angle * i) * radius;

                v2.Position.X = (float)Math.Cos(angle * (i + 1)) * radius;
                v2.Position.Y = (float)Math.Sin(angle * (i + 1)) * radius;

                // Vertex Normal
                v1.Normal.X = (float)Math.Cos(angle * i + angleOffset);
                v1.Normal.Y = (float)Math.Sin(angle * i + angleOffset);

                v2.Normal.X = (float)Math.Cos(angle * i + angleOffset);
                v2.Normal.Y = (float)Math.Sin(angle * i + angleOffset);

                // Copy vertices
                hull.Points[i * 2 + 0] = v1;
                hull.Points[i * 2 + 1] = v2;
            }

            for (int i = 0; i < numTris; i++) {
                hull.Indicies[i * 3 + 0] = 0;
                hull.Indicies[i * 3 + 1] = i + 1;
                hull.Indicies[i * 3 + 2] = i + 2;
            }

            return hull;
        }
Esempio n. 11
0
        /// <summary>
        /// Creates a rectangular shadow hull
        /// </summary>
        /// <param name="size">The dimensions of the rectangle</param>
        /// <returns>A rectangular shadow hull</returns>
        public static ShadowHull CreateRectangle(Vector2 size)
        {
            ShadowHull hull = new ShadowHull();

            size *= 0.5f;

            hull.MaxRadius = (float)Math.Sqrt(size.X * size.X + size.Y * size.Y);

            hull.NumPoints = 4 * 2;
            var numTris = hull.NumPoints - 2;

            hull.NumIndicies = numTris * 3;

            hull.Points   = new ShadowHullPoint[hull.NumPoints];
            hull.Indicies = new Int32[hull.NumIndicies];

            // Vertex position
            var posTR = new Vector2(+size.X, +size.Y);
            var posBR = new Vector2(+size.X, -size.Y);
            var posBL = new Vector2(-size.X, -size.Y);
            var posTL = new Vector2(-size.X, +size.Y);

            // Right
            hull.Points[0] = new ShadowHullPoint(posTR, Vector2.UnitX);
            hull.Points[1] = new ShadowHullPoint(posBR, Vector2.UnitX);

            // Bottom
            hull.Points[2] = new ShadowHullPoint(posBR, -Vector2.UnitY);
            hull.Points[3] = new ShadowHullPoint(posBL, -Vector2.UnitY);

            // Left
            hull.Points[4] = new ShadowHullPoint(posBL, -Vector2.UnitX);
            hull.Points[5] = new ShadowHullPoint(posTL, -Vector2.UnitX);

            // Top
            hull.Points[6] = new ShadowHullPoint(posTL, Vector2.UnitY);
            hull.Points[7] = new ShadowHullPoint(posTR, Vector2.UnitY);

            // Create tris
            for (int i = 0; i < numTris; i++)
            {
                hull.Indicies[i * 3 + 0] = 0;
                hull.Indicies[i * 3 + 1] = i + 1;
                hull.Indicies[i * 3 + 2] = i + 2;
            }

            return(hull);
        }
Esempio n. 12
0
        /// <summary>
        /// Creates a rectangular shadow hull
        /// </summary>
        /// <param name="size">The dimensions of the rectangle</param>
        /// <returns>A rectangular shadow hull</returns>
        public static ShadowHull CreateRectangle(Vector2 size)
        {
            ShadowHull hull = new ShadowHull();

            size *= 0.5f;

            hull.MaxRadius = (float)Math.Sqrt(size.X * size.X + size.Y * size.Y);

            hull.NumPoints = 4 * 2;
            var numTris = hull.NumPoints - 2;
            hull.NumIndicies = numTris * 3;

            hull.Points = new ShadowHullPoint[hull.NumPoints];
            hull.Indicies = new Int32[hull.NumIndicies];

            // Vertex position
            var posTR = new Vector2(+size.X, +size.Y);
            var posBR = new Vector2(+size.X, -size.Y);
            var posBL = new Vector2(-size.X, -size.Y);
            var posTL = new Vector2(-size.X, +size.Y);

            // Right
            hull.Points[0] = new ShadowHullPoint(posTR, Vector2.UnitX);
            hull.Points[1] = new ShadowHullPoint(posBR, Vector2.UnitX);
                                                              
            // Bottom                                         
            hull.Points[2] = new ShadowHullPoint(posBR, -Vector2.UnitY);
            hull.Points[3] = new ShadowHullPoint(posBL, -Vector2.UnitY);
                                                              
            // Left                                           
            hull.Points[4] = new ShadowHullPoint(posBL, -Vector2.UnitX);
            hull.Points[5] = new ShadowHullPoint(posTL, -Vector2.UnitX);

            // Top
            hull.Points[6] = new ShadowHullPoint(posTL, Vector2.UnitY);
            hull.Points[7] = new ShadowHullPoint(posTR, Vector2.UnitY);

            // Create tris
            for (int i = 0; i < numTris; i++)
            {
                hull.Indicies[i * 3 + 0] = 0;
                hull.Indicies[i * 3 + 1] = i + 1;
                hull.Indicies[i * 3 + 2] = i + 2;
            }

            return hull;
        }
Esempio n. 13
0
        public void LoadContent()
        {
            int blockface = MyRandom.Random.Next(0, 13);
            txtrect = new Rectangle(0 + (25 * blockface), 0, (int)Globals.SmallGridSize.X, (int)Globals.SmallGridSize.Y);
            int rot = MyRandom.Random.Next(0, 3);
            txtrot = Math.Atan(90 * rot);
            _centerVect = Globals.SmallGridSize / 2;

            _floor = BodyFactory.CreateRectangle(_world, ConvertUnits.ToSimUnits(Globals.SmallGridSize.X), ConvertUnits.ToSimUnits(Globals.SmallGridSize.Y), 30f);
            _floor.Position = ConvertUnits.ToSimUnits(_position.X + _centerVect.X, _position.Y + _centerVect.Y);
            _floor.IsStatic = false;
            _floor.Restitution = 0.2f;
            _floor.Friction = 0.2f;
            _floor.LinearDamping = 0.2f;
            _floor.AngularDamping = 0.2f;

            _blocktxture = Game.Content.Load<Texture2D>(".\\WallGraphics\\blocks");

            hull = ShadowHull.CreateRectangle(new Vector2(Globals.SmallGridSize.X, Globals.SmallGridSize.Y));
            hull.Position.X = _position.X + _centerVect.X;
            hull.Position.Y = _position.Y + _centerVect.Y;
            krypton.Hulls.Add(hull);
        }
Esempio n. 14
0
        public void Initialize(Texture2D sprite, ProjectileType type, Player plr, Body b, Texture2D shadow)
        {
            B = b;

            alreadyCollidedOnceOrMore = false;

            shade = shadow;

            foreach (var item in Game1.projectiles) {
                B.IgnoreCollisionWith(item.B);
            }

            B.OnCollision += new OnCollisionEventHandler(B_OnCollision);

            uint[] d = new uint[shade.Width * shade.Height];

            shade.GetData(d);

            Vertices v = PolygonTools.CreatePolygon(d, shade.Width, true);

            Vector2[] a = v.ToArray();

            h = ShadowHull.CreateConvex(ref a);

            if (plr.direction == 1)
                dir = 1;

            lock (Game1.projectileLock)
            Game1.lightingEngine.Hulls.Add(h);

            //  B.ApplyLinearImpulse(new Vector2(50, -10));
            if (plr.direction == 1) {
                B.Position = new Vector2(-plr.Position.X, plr.Position.Y + 1);
                B.ApplyTorque(-250f);
                B.LinearVelocity = new Vector2(-65, 7);
            } else {
                B.Position = new Vector2(-plr.Position.X, plr.Position.Y + 1);
                B.ApplyTorque(250f);
                B.LinearVelocity = new Vector2(65, 7);
            }

            Active = true;

            position = ConvertUnits.ToDisplayUnits(-plr.Position);
            texture = sprite;

            Type = type;

            Pelaaja = plr;

            hitBox.Width = 17;
            hitBox.Height = 17;
            hitBox.X = (int)position.X;
            hitBox.Y = (int)position.Y;
        }
Esempio n. 15
0
        /// <summary>
        /// Creates a custom shadow hull based on a series of vertices
        /// </summary>
        /// <param name="points">The points which the shadow hull will be comprised of</param>
        /// <returns>A custom shadow hulll</returns>
        public static ShadowHull CreateConvex(ref Vector2[] points)
        {
            // Validate input
            if (points == null) { throw new ArgumentNullException("Points cannot be null."); }
            if (points.Length < 3) { throw new ArgumentException("Need at least 3 points to create shadow hull."); }

            var numPoints = points.Length;

            ShadowHull hull = new ShadowHull();

            hull.NumPoints = numPoints * 2;
            var numTris = hull.NumPoints - 2;
            hull.NumIndicies = numTris * 3;

            hull.Points = new ShadowHullPoint[hull.NumPoints];
            hull.Indicies = new Int32[hull.NumIndicies];

            Vector2 pointMin = points[0];
            Vector2 pointMax = points[0];

            for (int i = 0; i < numPoints; i++)
            {
                var p1 = points[(i + 0) % numPoints];
                var p2 = points[(i + 1) % numPoints];

                hull.MaxRadius = Math.Max(hull.MaxRadius, p1.Length());

                var line = p2 - p1;

                var normal = new Vector2(-line.Y, +line.X);

                normal.Normalize();

                hull.Points[i * 2 + 0] = new ShadowHullPoint(p1, normal);
                hull.Points[i * 2 + 1] = new ShadowHullPoint(p2, normal);
            }

            for (Int32 i = 0; i < numTris; i++)
            {
                hull.Indicies[i * 3 + 0] = 0;
                hull.Indicies[i * 3 + 1] = (Int32)(i + 1);
                hull.Indicies[i * 3 + 2] = (Int32)(i + 2);
            }

            return hull;
        }
Esempio n. 16
0
        public PolygonHull(Vector2 position, List<Vector2> points)
        {
            Vector2[] pointsArray = points.ToArray();

            for (int i = 0; i < pointsArray.Length; i++)
            {
                pointsArray[i] = worldToShadow(pointsArray[i]);
            }

            //Array.Reverse(pointsArray);
            ShadowHull pHull = ShadowHull.CreateConvex(ref pointsArray);

            Vector2 newPosition = new Vector2();
            newPosition.X = position.X - Globals.ScreenWidthCenter;
            newPosition.Y = -position.Y + Globals.ScreenHeightCenter;

            pHull.Position = newPosition;

            mShadowHull = pHull;
        }
Esempio n. 17
0
 /// <summary>
 /// Remove ShadowHull
 /// </summary>
 public void RemoveHull()
 {
     LightingEngine LE = ((LightingEngine)Renderer.GetRenderEffect("LightingEngine"));
     LE.RemoveHull(Hull);
     this._Hull = null;
 }
Esempio n. 18
0
 /// <summary>
 /// Set ShadowHull of Tile
 /// </summary>
 /// <param name="Size">Size</param>
 /// <param name="Pos">Position</param>
 public void SetRectHull(Vector2 Size, Vector2 Pos)
 {
     ShadowHull H = ShadowHull.CreateRectangle(Size);
     H.Position = Pos;
     LightingEngine LE = ((LightingEngine)Renderer.GetRenderEffect("LightingEngine"));
     if (Hull != null)
     {
         LE.RemoveHull(Hull);
     }
     LE.AddHull(H);
     this._Hull = H;
 }
Esempio n. 19
0
 public void RemoveHull(ShadowHull Hull)
 {
     Krypton.Hulls.Remove(Hull);
 }
Esempio n. 20
0
 public void AddHull(ShadowHull Hull)
 {
     Krypton.Hulls.Add(Hull);
 }
Esempio n. 21
0
        public void Initialize(Texture2D texture, Texture2D healthbar, Vector2 position, int maxFrames, ContentManager cont, GraphicsDeviceManager graphics, World World, Texture2D Shade)
        {
            _world = World;

            shadow = Shade;

            bPlayer = BodyFactory.CreateRectangle(World, ConvertUnits.ToSimUnits(43), ConvertUnits.ToSimUnits(50), 1f);
            //    BodyFactory.CreateRectangle()
            bPlayer.BodyType = BodyType.Dynamic;
            bPlayer.Friction = 0.0f;
            bPlayer.Restitution = 0.0f;

            Joint rotationJoint = JointFactory.CreateFixedAngleJoint(World, bPlayer);

            bPlayer.OnCollision += new OnCollisionEventHandler(bPlayer_OnCollision);
            bPlayer.OnSeparation += new OnSeparationEventHandler(bPlayer_OnSeparation);

            cm = cont;

            PlayerSprite = texture;
            shurikenPicture = cm.Load<Texture2D>("shuriken");

            currentAnim.amountOfFrames = maxFrames;
            currentAnim.currentFrame = new Point(0, 0);
            currentAnim.frameSize = new Point(63, 63);
            currentAnim.sheetSize = new Point(9, 0);
            currentAnim.animInterval = 95.0f;

            swingHitBox = new Rectangle((int)position.X, (int)position.Y, (int)currentAnim.frameSize.X, (int)currentAnim.frameSize.Y / 2);

            playerTextureData = new Color[texture.Width * texture.Height];
            texture.GetData(playerTextureData);

            amountOfFrames = maxFrames;

            idleAnim = texture;

            currentAnimation = PlayerSprite;

            Position = position;

            hitBox.X = (int)position.X;
            hitBox.Y = (int)position.Y;

            hitBox.Width = texture.Width;
            hitBox.Height = texture.Height;

            HPBar = healthbar;

            uint[] d = new uint[shadow.Width * shadow.Height];

            shadow.GetData(d);

            Vertices v = PolygonTools.CreatePolygon(d, shadow.Width);

            List<Vertices> _list = FarseerPhysics.Common.Decomposition.EarclipDecomposer.ConvexPartition(v);

            Vector2[] q = v.ToArray();

            h = ShadowHull.CreateConvex(ref q);

            h.Position = Position;
            lock (Game1.projectileLock)
                Game1.lightingEngine.Hulls.Add(h);
        }
Esempio n. 22
0
        public void Draw(SpriteBatch spriteBatch)
        {
            //spriteBatch.Draw(PlayerSprite, Position, Color.White);

            byte alpha = 0xff;

            // 0x80 = 128, 0xFF = 255

            if (stealth) alpha = 0x80;

            //		DrawPlayerHitbox(spriteBatch);
            //	DrawSwingHitbox(spriteBatch);

            SpriteEffects s = SpriteEffects.None;
            if (direction == 1) s = SpriteEffects.FlipHorizontally;

            if (direction == 1 && mCurrentState == State.Attacking && currentAnim.state == State.Attacking)
            {

                spriteBatch.Draw(currentAnimation, new Vector2(ConvertUnits.ToDisplayUnits(-Position.X) - currentAnim.frameSize.X, ConvertUnits.ToDisplayUnits(-Position.Y) - 32), new Rectangle(
                    currentAnim.frameSize.X * currentAnim.currentFrame.X,
                    currentAnim.frameSize.Y * currentAnim.currentFrame.Y,
                    currentAnim.frameSize.X,
                    currentAnim.frameSize.Y),
                    new Color(255, 255, 255, alpha), 0, new Vector2(0, 0), 1,
                    s, 0);
            }
            else if (direction == 0 && mCurrentState == State.Attacking && currentAnim.state == State.Attacking)
            {

                spriteBatch.Draw(currentAnimation, new Vector2(ConvertUnits.ToDisplayUnits(-Position.X), ConvertUnits.ToDisplayUnits(-Position.Y) - 32), new Rectangle(
                    currentAnim.frameSize.X * currentAnim.currentFrame.X,
                    currentAnim.frameSize.Y * currentAnim.currentFrame.Y,
                    currentAnim.frameSize.X,
                    currentAnim.frameSize.Y),
                    new Color(255, 255, 255, alpha), 0, new Vector2(0, 0), 1,
                    s, 0);

            }
            else if (direction == 1 && mCurrentState == State.Hanging)
            {

                spriteBatch.Draw(currentAnimation, new Vector2(ConvertUnits.ToDisplayUnits(-Position.X) - 40, ConvertUnits.ToDisplayUnits(-Position.Y) - 32), new Rectangle(
                    currentAnim.frameSize.X * currentAnim.currentFrame.X,
                    currentAnim.frameSize.Y * currentAnim.currentFrame.Y,
                    currentAnim.frameSize.X,
                    currentAnim.frameSize.Y),
                    new Color(255, 255, 255, alpha), 0, new Vector2(0, 0), 1,
                    s, 0);

            }
            else if (direction == 0 && mCurrentState == State.Hanging)
            {

                spriteBatch.Draw(currentAnimation, new Vector2(ConvertUnits.ToDisplayUnits(-Position.X) - 22, ConvertUnits.ToDisplayUnits(-Position.Y) - 32), new Rectangle(
                    currentAnim.frameSize.X * currentAnim.currentFrame.X,
                    currentAnim.frameSize.Y * currentAnim.currentFrame.Y,
                    currentAnim.frameSize.X,
                    currentAnim.frameSize.Y),
                    new Color(255, 255, 255, alpha), 0, new Vector2(0, 0), 1,
                    s, 0);

            }
            else if (mCurrentState == State.WallJumping)
            {

                spriteBatch.Draw(currentAnimation, new Vector2(ConvertUnits.ToDisplayUnits(-Position.X), ConvertUnits.ToDisplayUnits(-Position.Y)), new Rectangle(
                    currentAnim.frameSize.X * currentAnim.currentFrame.X,
                    currentAnim.frameSize.Y * currentAnim.currentFrame.Y,
                    currentAnim.frameSize.X,
                    currentAnim.frameSize.Y),
                    new Color(255, 255, 255, alpha), angle, new Vector2(currentAnim.frameSize.X / 2, currentAnim.frameSize.Y / 2), 1,
                    s, 0);
            }
            else
            {

                int h = 0;

                if (direction == 0)
                    h = 10;

                spriteBatch.Draw(currentAnimation, new Vector2(ConvertUnits.ToDisplayUnits(-Position.X) - currentAnim.frameSize.X / 2 - h, ConvertUnits.ToDisplayUnits(-Position.Y) - 32), new Rectangle(
                  currentAnim.frameSize.X * currentAnim.currentFrame.X,
                  currentAnim.frameSize.Y * currentAnim.currentFrame.Y,
                  currentAnim.frameSize.X,
                  currentAnim.frameSize.Y),
                  new Color(255, 255, 255, alpha), 0, new Vector2(0, 0), 1,
                  s, 0);

            }
        }