Example #1
0
        public void CalculateAsteroidPosition(GameTime gameTime, Viewport viewport)
        {
            float   asteroidSpeed     = 5f;
            Vector2 targetDestination = new Vector2();

            if (this.type == "RedMeteor")
            {
                targetDestination = new Vector2(viewport.Width / 2, viewport.Height / 2);
                sprite.rotation   = (float)DirectionHelper.FaceObject(sprite.position, targetDestination);
                sprite.position  += DirectionHelper.MoveTowards(sprite.position, targetDestination, asteroidSpeed);
            }
            else if (this.type == "BlueMeteor")
            {
                // Randomly calculate the point the meteor should head
                //Random r = new Random();
                //int randomValue = r.Next(0, 360);
                //var angle = randomValue;
                //int radius = Math.Max(viewport.Width / 2, viewport.Height / 2);
                //radius = radius + 500;
                //targetDestination = new Vector2((float)(Math.Cos(angle) * radius), (float)(Math.Sin(angle) * radius));
                sprite.rotation  = (float)DirectionHelper.FaceObject(sprite.position, this.targetPosition);
                sprite.position += DirectionHelper.MoveTowards(sprite.position, this.targetPosition, asteroidSpeed);
            }
        }