/// <summary> /// Render the ship. /// </summary> /// <param name="elapsedTime">The amount of elapsed time, in seconds.</param> /// <param name="lineBatch">The LineBatch to render to.</param> public override void Draw(float elapsedTime, LineBatch lineBatch) { if (polygon != null) { if (lineBatch == null) { throw new ArgumentNullException("lineBatch"); } // create the transformation Matrix rotationMatrix = Matrix.CreateRotationZ(rotation); Matrix world = rotationMatrix * Matrix.CreateTranslation(position.X, position.Y, 0f); // transform the polygon polygon.Transform(world); // draw the polygon lineBatch.DrawPolygon(polygon, color); // draw the motion blur if (useMotionBlur && velocity.LengthSquared() > 1024f) { // draw several "blur" polygons behind the real polygon Vector2 backwards = Vector2.Normalize(position - lastPosition); float speed = velocity.Length(); for (int i = 1; i < speed / 16; ++i) { // calculate the "blur" polygon's position Vector2 blurPosition = this.position - backwards * (i * 4); // calculate the transformation for the "blur" polygon Matrix blurWorld = rotationMatrix * Matrix.CreateTranslation(blurPosition.X, blurPosition.Y, 0); // transform the polygon to the "blur" location polygon.Transform(blurWorld); // calculate the alpha of the "blur" location byte alpha = (byte)(160 / (i + 1)); if (alpha < 1) { break; } // draw the "blur" polygon lineBatch.DrawPolygon(polygon, new Color(color.R, color.G, color.B, alpha)); } } } if (chlorine1Polygon != null) { if (lineBatch == null) { throw new ArgumentNullException("lineBatch"); } // create the transformation Matrix rotationMatrix = Matrix.CreateRotationZ(rotation); Matrix world = rotationMatrix * Matrix.CreateTranslation(position.X, position.Y, 0f); // transform the polygon chlorine1Polygon.Transform(world); // draw the polygon lineBatch.DrawPolygon(chlorine1Polygon, Color.Green); // draw the motion blur if (useMotionBlur && velocity.LengthSquared() > 1024f) { // draw several "blur" polygons behind the real polygon Vector2 backwards = Vector2.Normalize(position - lastPosition); float speed = velocity.Length(); for (int i = 1; i < speed / 16; ++i) { // calculate the "blur" polygon's position Vector2 blurPosition = this.position - backwards * (i * 4); // calculate the transformation for the "blur" polygon Matrix blurWorld = rotationMatrix * Matrix.CreateTranslation(blurPosition.X, blurPosition.Y, 0); // transform the polygon to the "blur" location chlorine1Polygon.Transform(blurWorld); // calculate the alpha of the "blur" location byte alpha = (byte)(160 / (i + 1)); if (alpha < 1) { break; } // draw the "blur" polygon lineBatch.DrawPolygon(chlorine1Polygon, new Color(Color.Green.R, Color.Green.G, Color.Green.B, alpha)); } } } if (chlorine2Polygon != null) { if (lineBatch == null) { throw new ArgumentNullException("lineBatch"); } // create the transformation Matrix rotationMatrix = Matrix.CreateRotationZ(rotation); Matrix world = rotationMatrix * Matrix.CreateTranslation(position.X, position.Y, 0f); // transform the polygon chlorine2Polygon.Transform(world); // draw the polygon lineBatch.DrawPolygon(chlorine2Polygon, Color.Green); // draw the motion blur if (useMotionBlur && velocity.LengthSquared() > 1024f) { // draw several "blur" polygons behind the real polygon Vector2 backwards = Vector2.Normalize(position - lastPosition); float speed = velocity.Length(); for (int i = 1; i < speed / 16; ++i) { // calculate the "blur" polygon's position Vector2 blurPosition = this.position - backwards * (i * 4); // calculate the transformation for the "blur" polygon Matrix blurWorld = rotationMatrix * Matrix.CreateTranslation(blurPosition.X, blurPosition.Y, 0); // transform the polygon to the "blur" location chlorine2Polygon.Transform(blurWorld); // calculate the alpha of the "blur" location byte alpha = (byte)(160 / (i + 1)); if (alpha < 1) { break; } // draw the "blur" polygon lineBatch.DrawPolygon(chlorine2Polygon, new Color(Color.Green.R, Color.Green.G, Color.Green.B, alpha)); } } } if (fluorine1Polygon != null) { if (lineBatch == null) { throw new ArgumentNullException("lineBatch"); } // create the transformation Matrix rotationMatrix = Matrix.CreateRotationZ(rotation); Matrix world = rotationMatrix * Matrix.CreateTranslation(position.X, position.Y, 0f); // transform the polygon fluorine1Polygon.Transform(world); // draw the polygon lineBatch.DrawPolygon(fluorine1Polygon, Color.Purple); // draw the motion blur if (useMotionBlur && velocity.LengthSquared() > 1024f) { // draw several "blur" polygons behind the real polygon Vector2 backwards = Vector2.Normalize(position - lastPosition); float speed = velocity.Length(); for (int i = 1; i < speed / 16; ++i) { // calculate the "blur" polygon's position Vector2 blurPosition = this.position - backwards * (i * 4); // calculate the transformation for the "blur" polygon Matrix blurWorld = rotationMatrix * Matrix.CreateTranslation(blurPosition.X, blurPosition.Y, 0); // transform the polygon to the "blur" location fluorine1Polygon.Transform(blurWorld); // calculate the alpha of the "blur" location byte alpha = (byte)(160 / (i + 1)); if (alpha < 1) { break; } // draw the "blur" polygon lineBatch.DrawPolygon(fluorine1Polygon, new Color(Color.Purple.R, Color.Purple.G, Color.Purple.B, alpha)); } } } if (fluorine2Polygon != null) { if (lineBatch == null) { throw new ArgumentNullException("lineBatch"); } // create the transformation Matrix rotationMatrix = Matrix.CreateRotationZ(rotation); Matrix world = rotationMatrix * Matrix.CreateTranslation(position.X, position.Y, 0f); // transform the polygon fluorine2Polygon.Transform(world); // draw the polygon lineBatch.DrawPolygon(fluorine2Polygon, Color.Purple); // draw the motion blur if (useMotionBlur && velocity.LengthSquared() > 1024f) { // draw several "blur" polygons behind the real polygon Vector2 backwards = Vector2.Normalize(position - lastPosition); float speed = velocity.Length(); for (int i = 1; i < speed / 16; ++i) { // calculate the "blur" polygon's position Vector2 blurPosition = this.position - backwards * (i * 4); // calculate the transformation for the "blur" polygon Matrix blurWorld = rotationMatrix * Matrix.CreateTranslation(blurPosition.X, blurPosition.Y, 0); // transform the polygon to the "blur" location fluorine2Polygon.Transform(blurWorld); // calculate the alpha of the "blur" location byte alpha = (byte)(160 / (i + 1)); if (alpha < 1) { break; } // draw the "blur" polygon lineBatch.DrawPolygon(fluorine2Polygon, new Color(Color.Purple.R, Color.Purple.G, Color.Purple.B, alpha)); } } } }
/// <summary> /// Render the power-up. /// </summary> /// <param name="elapsedTime">The amount of elapsed time, in seconds.</param> /// <param name="lineBatch">The LineBatch to render to.</param> public override void Draw(float elapsedTime, LineBatch lineBatch) { // update the scale period scalePeriodElapsed += elapsedTime * timeToScalePeriod; while (scalePeriodElapsed < 0) { scalePeriodElapsed += MathHelper.TwoPi; } while (scalePeriodElapsed > MathHelper.TwoPi) { scalePeriodElapsed -= MathHelper.TwoPi; } // draw the polygons if (polygon != null) { if (lineBatch == null) { throw new ArgumentNullException("lineBatch"); } // calculate the transformation Matrix scaleMatrix = Matrix.CreateScale(0.8f + 0.1f * (float)Math.Cos(scalePeriodElapsed)); Matrix world = scaleMatrix * Matrix.CreateTranslation(position.X, position.Y, 0f); // transform the polygons polygon.Transform(world); innerPolygon.Transform(world); // draw the polygons lineBatch.DrawPolygon(polygon, Color.White); if (innerPolygon != null) { lineBatch.DrawPolygon(innerPolygon, color, true); } // draw the motion blur if (useMotionBlur && velocity.LengthSquared() > 1024f) { // draw several "blur" polygons behind the real polygons Vector2 backwards = Vector2.Normalize(position - lastPosition); float speed = velocity.Length(); for (int i = 1; i < speed / 16; ++i) { // calculate the "blur" position Vector2 blurPosition = this.position - backwards * (i * 4); // calculate the transformation Matrix blurWorld = scaleMatrix * Matrix.CreateTranslation(blurPosition.X, blurPosition.Y, 0); // transform the polygons polygon.Transform(blurWorld); if (innerPolygon != null) { innerPolygon.Transform(blurWorld); } // calculate the alpha of the "blur" polygons polygons byte alpha = (byte)(160 / (i + 1)); if (alpha < 1) { break; } // draw the "blur" polygons lineBatch.DrawPolygon(polygon, new Color(255, 255, 255, alpha)); if (innerPolygon != null) { lineBatch.DrawPolygon(innerPolygon, new Color(color.R, color.G, color.B, alpha), true); } } } } }