示例#1
0
 /// <summary>
 /// Creates an asteroid
 /// </summary>
 /// <param name="size">Size of the asteroid</param>
 /// <param name="verts">Vertices defining the shape of the asteroid</param>
 /// <param name="indices">Indices defining the shape of the asteroid</param>
 /// <param name="pos">Initial position of the asteroid</param>
 /// <param name="rot">Initial rotation of the asteroid (in radians)</param>
 /// <param name="dir">Initial direction of the asteroid</param>
 /// <param name="linSpeed">Linear speed of the asteroid</param>
 /// <param name="scale">Scale to apply to the vertices</param>
 public Asteroid(AsteroidSize size, Shape s,
     Vector2 pos, float rot, Vector2 dir, float linSpeed, float scale)
     : base(s, rot, dir, scale)
 {
     Position = pos;
     Size = size;
     LinSpeed = linSpeed;
 }
示例#2
0
        public override bool Intersects(Shape s)
        {
            foreach (Triangle t in Triangles)
            {
                if (t.Intersects(s)) return true;
            }

            return false;
        }
示例#3
0
        public void Draw(Shape s)
        {
            effect.World = s.World;

            foreach (EffectPass pass in effect.CurrentTechnique.Passes)
            {
                pass.Apply();
                gDevice.DrawUserIndexedPrimitives<VertexPositionColor>(PrimitiveType.LineList,
                    s.Vertices, 0, s.Vertices.Length, s.Indices, 0, s.Indices.Length / 2);
            }
        }
示例#4
0
        /// <summary>
        /// Constructs the base of an entity
        /// </summary>
        /// <param name="body">Shape defining the body of the entity</param>
        /// <param name="rot">The initial rotation of the entity</param>
        /// <param name="dir">Initial direction of the entity</param>
        /// <param name="scale">Scale of the entity</param>
        public Entity(Shape body, float rot, Vector2 dir, float scale)
        {
            Body = body;
            Position = Body.Position;
            Rotation = rot;
            LinSpeed = 0f;
            Scale = scale;
            Direction = dir;

            EffectiveHeight = 15f;
            EffectiveWidth = 15f;
        }
示例#5
0
        /// <summary>
        /// Constructs the base of an entity
        /// </summary>
        /// <param name="body">Shape defining the body of the entity</param>
        /// <param name="rot">The initial rotation of the entity</param>
        protected Entity(Shape body, float rot)
        {
            Body = body;
            Position = Body.Position;
            Rotation = rot;
            LinSpeed = 0f;
            Scale = 1f;

            // Find the initial direction, based on the rotation
            Direction = new Vector2((float)Math.Cos(rot), (float)Math.Sin(rot));

            // Initial values
            EffectiveHeight = 15f;
            EffectiveWidth = 15f;
        }
示例#6
0
        public virtual bool Intersects(Shape s)
        {
            if (s is ConcaveShape)
                return (s as ConcaveShape).Intersects(this);

            if (s == this)
                return true;

            int i = 0;
            // Using this shape...
            for (i = 0; i < this.TransformedVertices.Length; i++)
            {
                // The next index should be i + 1
                // However, if we're on the last cycle, we have looped around.
                // The next index is the one we started with (0)
                int nextIndex = i + 1;
                if (i == this.TransformedVertices.Length - 1)
                    nextIndex = 0;

                Vector2 side = this.TransformedVertices[nextIndex] - this.TransformedVertices[i];

                // Find the axis perpendicular to the current side.
                // This is what we'll use to test the separation.
                Vector2 axis = new Vector2(side.Y, -side.X);

                Projection p1 = this.Project(axis);
                Projection p2 = s.Project(axis);

                if (!p1.Overlaps(p2))
                    return false;
            }

            // Next shape...
            for (i = 0; i < s.TransformedVertices.Length; i++)
            {
                // The next index should be i + 1
                // However, if we're on the last cycle, we have looped around.
                // The next index is the one we started with (0)
                int nextIndex = i + 1;
                if (i == s.TransformedVertices.Length - 1)
                    nextIndex = 0;

                Vector2 side = s.TransformedVertices[nextIndex] - s.TransformedVertices[i];

                // Find the axis perpendicular to the current side.
                // This is what we'll use to test the separation.
                Vector2 axis = new Vector2(side.Y, -side.X);

                Projection p1 = this.Project(axis);
                Projection p2 = s.Project(axis);

                if (!p1.Overlaps(p2))
                    return false;
            }

            return true;
        }