Ejemplo n.º 1
0
        /// <summary>
        /// Draws the given polygon.
        /// </summary>
        /// <param name="polygon">The polygon to render.</param>
        /// <param name="color">The color to use when drawing the polygon.</param>
        /// <param name="dashed">If true, the polygon will be "dashed".</param>
        public void DrawPolygon(VectorPolygon polygon, Color color, bool dashed)
        {
            if (polygon == null)
            {
                throw new ArgumentNullException("polygon");
            }
            int step = (dashed == true) ? 2 : 1;

            for (int i = 0; i < polygon.TransformedPoints.Length; i += step)
            {
                if (currentIndex >= vertices.Length - 2)
                {
                    End();
                    Begin();
                }
                vertices[currentIndex].Position.X =
                    polygon.TransformedPoints[i % polygon.TransformedPoints.Length].X;
                vertices[currentIndex].Position.Y =
                    polygon.TransformedPoints[i % polygon.TransformedPoints.Length].Y;
                vertices[currentIndex++].Color    = color;
                vertices[currentIndex].Position.X =
                    polygon.TransformedPoints[(i + 1) %
                                              polygon.TransformedPoints.Length].X;
                vertices[currentIndex].Position.Y =
                    polygon.TransformedPoints[(i + 1) %
                                              polygon.TransformedPoints.Length].Y;
                vertices[currentIndex++].Color = color;
                lineCount++;
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Draws the given polygon, in defined segments.
        /// </summary>
        /// <param name="aPolygon">The polygon to render.</param>
        /// <param name="aColor">The color to use when drawing the polygon.</param>
        /// <param name="aDashed">If true, the polygon will be "dashed".</param>
        /// <param name="aStartSeg">Start of segment drawing.</param>
        /// <param name="aEndSeg">End of segment drawing.</param>
        public void DrawPolygonSegments(VectorPolygon aPolygon, Color aColor, bool aDashed, int aStartSeg, int aEndSeg)
        {
            if (aPolygon == null || aEndSeg > aPolygon.TransformedPoints.Length)
            {
                throw new ArgumentNullException("polygon");
            }
            int step = (aDashed == true) ? 2 : 1;

            for (int i = aStartSeg; i < aEndSeg; i += step)
            {
                if (currentIndex >= vertices.Length - 2)
                {
                    End();
                    Begin();
                }
                vertices[currentIndex].Position.X =
                    aPolygon.TransformedPoints[i % aPolygon.TransformedPoints.Length].X;
                vertices[currentIndex].Position.Y =
                    aPolygon.TransformedPoints[i % aPolygon.TransformedPoints.Length].Y;
                vertices[currentIndex++].Color    = aColor;
                vertices[currentIndex].Position.X =
                    aPolygon.TransformedPoints[(i + 1) %
                                               aPolygon.TransformedPoints.Length].X;
                vertices[currentIndex].Position.Y =
                    aPolygon.TransformedPoints[(i + 1) %
                                               aPolygon.TransformedPoints.Length].Y;
                vertices[currentIndex++].Color = aColor;
                lineCount++;
            }
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Constructs a new power-up.
 /// </summary>
 /// <param name="world">The world that this power-up belongs to.</param>
 public PowerUp(World world)
     : base(world)
 {
     this.mass = 500f;
     this.polygon = VectorPolygon.CreateCircle(Vector2.Zero, 16f, 16);
     this.innerPolygon = VectorPolygon.CreateCircle(Vector2.Zero, 10f, 16);
 }
Ejemplo n.º 4
0
 internal void Initialize()
 {
     mass          = 32f;
     playing       = false;
     radius        = 20f;
     shieldPolygon = VectorPolygon.CreateCircle(Vector2.Zero, 20f, 16);
 }
Ejemplo n.º 5
0
        /// <summary>
        /// Construct a new ship, for the given player.
        /// </summary>
        /// <param name="world">The world that this ship belongs to.</param>
        /// <param name="playerIndex">
        /// The Gamepad player index that controls this ship.
        /// </param>
        public Ship(World world, PlayerIndex playerIndex)
            : base(world)
        {
            this.playerIndex = playerIndex;

            this.radius        = 20f;
            this.mass          = 32f;
            this.color         = shipColorsByPlayerIndex[(int)this.playerIndex];
            this.polygon       = VectorPolygon.CreatePlayer();
            this.shieldPolygon = VectorPolygon.CreateCircle(Vector2.Zero, 20f, 16);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Create a polygon shaped like an asteroid.
        /// </summary>
        /// <param name="radius">The radius of the asteroid.</param>
        /// <returns>A new VectorPolygon object in the shape of an asteroid.</returns>
        public static VectorPolygon CreateAsteroid(float radius)
        {
            VectorPolygon polygon = CreateCircle(Vector2.Zero, radius, 12);

            for (int i = 0; i < polygon.Points.Length; ++i)
            {
                Vector2 normal = Vector2.Normalize(polygon.Points[i]);
                polygon.Points[i] += normal * ((radius * 0.2f) *
                                               (float)random.NextDouble() - (radius * 0.1f));
            }

            return(polygon);
        }
Ejemplo n.º 7
0
 /// <summary>
 /// Constructs a new rocket projectile.
 /// </summary>
 /// <param name="world">The world that this projectile belongs to.</param>
 /// <param name="owner">The ship that fired this projectile, if any.</param>
 /// <param name="direction">The initial direction for this projectile.</param>
 public RocketProjectile(World world, Ship owner, Vector2 direction)
     : base(world, owner, direction)
 {
     this.radius          = 8f;
     this.life            = 80f;
     this.mass            = 3f;
     this.speed           = 520f;
     this.duration        = 4f;
     this.damageAmount    = 100f;
     this.damageOwner     = false;
     this.damageRadius    = 128f;
     this.explodes        = true;
     this.explosionColors = new Color[]
     { Color.Orange, Color.Gray, Color.Gray, Color.Silver };
     this.polygon = VectorPolygon.CreateRocket();
     this.color   = Color.Orange;
 }
Ejemplo n.º 8
0
 /// <summary>
 /// Constructs a new mine projectile.
 /// </summary>
 /// <param name="world">The world that this projectile belongs to.</param>
 /// <param name="owner">The ship that fired this projectile, if any.</param>
 /// <param name="direction">The initial direction for this projectile.</param>
 public MineProjectile(World world, Ship owner, Vector2 direction)
     : base(world, owner, direction)
 {
     this.radius          = 16f;
     this.life            = 15f;
     this.speed           = 64f;
     this.duration        = 15f;
     this.mass            = 5f;
     this.damageAmount    = 200f;
     this.damageOwner     = true;
     this.damageRadius    = 80f;
     this.explodes        = true;
     this.explosionColors = new Color[]
     { Color.Red, Color.Maroon, Color.White, Color.Silver };
     this.polygon = VectorPolygon.CreateMine();
     this.color   = Color.Red;
 }
Ejemplo n.º 9
0
 /// <summary>
 /// Construct a new asteroid.
 /// </summary>
 /// <param name="world">The world that this asteroid belongs to.</param>
 /// <param name="radius">The size of the asteroid.</param>
 public Asteroid(World world, float radius)
     : base(world)
 {
     // all asteroids are gray
     this.color = Color.Gray;
     // create the polygon
     this.polygon = VectorPolygon.CreateAsteroid(radius);
     // the asteroid polygon might not be as big as the original radius,
     // so find out how big it really is
     for (int i = 0; i < this.polygon.Points.Length; i++)
     {
         float length = this.polygon.Points[i].Length();
         if (length > this.radius)
         {
             this.radius = length;
         }
     }
     // calculate the mass
     this.mass = radius * massRadiusRatio;
 }
Ejemplo n.º 10
0
 /// <summary>
 /// Draws the given polygon.
 /// </summary>
 /// <param name="polygon">The polygon to render.</param>
 /// <param name="color">The color to use when drawing the polygon.</param>
 public void DrawPolygon(VectorPolygon polygon, Color color)
 {
     DrawPolygon(polygon, color, false);
 }
Ejemplo n.º 11
0
        /// <summary>
        /// Construct a new ship, for the given player.
        /// </summary>
        /// <param name="world">The world that this ship belongs to.</param>
        /// <param name="playerIndex">
        /// The Gamepad player index that controls this ship.
        /// </param>
        public Ship(World world, PlayerIndex playerIndex)
            : base(world)
        {
            this.playerIndex = playerIndex;

            this.radius = 20f;
            this.mass = 32f;
            this.color = shipColorsByPlayerIndex[(int)this.playerIndex];
            this.polygon = VectorPolygon.CreatePlayer();
            this.shieldPolygon = VectorPolygon.CreateCircle(Vector2.Zero, 20f, 16);
        }
Ejemplo n.º 12
0
 /// <summary>
 /// Constructs a new power-up.
 /// </summary>
 /// <param name="world">The world that this power-up belongs to.</param>
 public PowerUp(World world) : base(world)
 {
     this.mass         = 500f;
     this.polygon      = VectorPolygon.CreateCircle(Vector2.Zero, 16f, 16);
     this.innerPolygon = VectorPolygon.CreateCircle(Vector2.Zero, 10f, 16);
 }
Ejemplo n.º 13
0
 /// <summary>
 /// Draws the given polygon, in defined segments.
 /// </summary>
 /// <param name="aPolygon">The polygon to render.</param>
 /// <param name="aColor">The color to use when drawing the polygon.</param>
 /// <param name="aDashed">If true, the polygon will be "dashed".</param>
 /// <param name="aStartSeg">Start of segment drawing.</param>
 /// <param name="aEndSeg">End of segment drawing.</param>
 public void DrawPolygonSegments(VectorPolygon aPolygon, Color aColor, bool aDashed, int aStartSeg, int aEndSeg)
 {
     if (aPolygon == null || aEndSeg > aPolygon.TransformedPoints.Length)
     {
         throw new ArgumentNullException("polygon");
     }
     int step = (aDashed == true) ? 2 : 1;
     for (int i = aStartSeg; i < aEndSeg; i += step)
     {
         if (currentIndex >= vertices.Length - 2)
         {
             End();
             Begin();
         }
         vertices[currentIndex].Position.X =
             aPolygon.TransformedPoints[i % aPolygon.TransformedPoints.Length].X;
         vertices[currentIndex].Position.Y =
             aPolygon.TransformedPoints[i % aPolygon.TransformedPoints.Length].Y;
         vertices[currentIndex++].Color = aColor;
         vertices[currentIndex].Position.X =
             aPolygon.TransformedPoints[(i + 1) %
                 aPolygon.TransformedPoints.Length].X;
         vertices[currentIndex].Position.Y =
             aPolygon.TransformedPoints[(i + 1) %
                 aPolygon.TransformedPoints.Length].Y;
         vertices[currentIndex++].Color = aColor;
         lineCount++;
     }
 }
Ejemplo n.º 14
0
 /// <summary>
 /// Draws the given polygon.
 /// </summary>
 /// <param name="polygon">The polygon to render.</param>
 /// <param name="color">The color to use when drawing the polygon.</param>
 /// <param name="dashed">If true, the polygon will be "dashed".</param>
 public void DrawPolygon(VectorPolygon polygon, Color color, bool dashed)
 {
     if (polygon == null)
     {
         throw new ArgumentNullException("polygon");
     }
     int step = (dashed == true) ? 2 : 1;
     for (int i = 0; i < polygon.TransformedPoints.Length; i += step)
     {
         if (currentIndex >= vertices.Length - 2)
         {
             End();
             Begin();
         }
         vertices[currentIndex].Position.X =
             polygon.TransformedPoints[i % polygon.TransformedPoints.Length].X;
         vertices[currentIndex].Position.Y =
             polygon.TransformedPoints[i % polygon.TransformedPoints.Length].Y;
         vertices[currentIndex++].Color = color;
         vertices[currentIndex].Position.X =
             polygon.TransformedPoints[(i + 1) %
                 polygon.TransformedPoints.Length].X;
         vertices[currentIndex].Position.Y =
             polygon.TransformedPoints[(i + 1) %
                 polygon.TransformedPoints.Length].Y;
         vertices[currentIndex++].Color = color;
         lineCount++;
     }
 }
Ejemplo n.º 15
0
 /// <summary>
 /// Draws the given polygon.
 /// </summary>
 /// <param name="polygon">The polygon to render.</param>
 /// <param name="color">The color to use when drawing the polygon.</param>
 public void DrawPolygon(VectorPolygon polygon, Color color)
 {
     DrawPolygon(polygon, color, false);
 }