Example #1
0
 public static Vector3 AIGetNewPosition(Butterfly b, int tier, Vector3 tetherPoint)
 {
     switch (tier)
     {
         case 0:
             goto default;
         case 1:
             return Wander(b, new Vector2(tetherPoint.X, tetherPoint.Y), 0.025f);
         case 2:
             return Wander(b, new Vector2(tetherPoint.X, tetherPoint.Y), 0.03f);
         case 3:
             return Wander(b, new Vector2(tetherPoint.X, tetherPoint.Y), 0.035f);
         case 4:
             return Wander(b, new Vector2(tetherPoint.X, tetherPoint.Y), .040f);
         case 5:
             return Wander(b, new Vector2(tetherPoint.X, tetherPoint.Y), .045f);
         case 6:
             return Wander(b, new Vector2(tetherPoint.X, tetherPoint.Y), .050f);
         case 7:
             return Wander(b, new Vector2(tetherPoint.X, tetherPoint.Y), .55f);
         case 8:
             return Wander(b, new Vector2(tetherPoint.X, tetherPoint.Y), .60f);
         case 9:
             return Wander(b, new Vector2(tetherPoint.X, tetherPoint.Y), .225f);
         default:
             return Wander(b, new Vector2(b.getPosition().X, b.getPosition().Y), 0f);
     }
 }
        /// <summary>
        /// Creates a texture of the specified color.
        /// </summary>
        /// <param name="graphicsDevice">The graphics device to use.</param>
        /// <param name="width">The width of the texture.</param>
        /// <param name="height">The height of the texture.</param>
        /// <param name="color">The color to set the texture to.</param>
        /// <returns>The newly created texture.</returns>
        public static Texture2D Create(GraphicsDevice graphicsDevice, int width, int height, Butterfly.ButterflyColors color)
        {
            // create the rectangle texture without colors
                Texture2D texture = new Texture2D(
                    graphicsDevice,
                    width,
                    height,
                    false,
                    SurfaceFormat.Color);

                // Create a color array for the pixels
                Color[] colors = new Color[width * height];
                for (int i = 0; i < colors.Length; i++)
                {
                    switch (color)
                    {
                        case Butterfly.ButterflyColors.Black:
                            colors[i] = Color.Black;
                            break;
                        case Butterfly.ButterflyColors.Blue:
                            colors[i] = Color.Blue;
                            break;
                        case Butterfly.ButterflyColors.Brown:
                            colors[i] = Color.SaddleBrown;
                            break;
                        case Butterfly.ButterflyColors.Green:
                            colors[i] = Color.LawnGreen;
                            break;
                        case Butterfly.ButterflyColors.Orange:
                            colors[i] = Color.DarkOrange;
                            break;
                        case Butterfly.ButterflyColors.Pink:
                            colors[i] = Color.Orchid;
                            break;
                        case Butterfly.ButterflyColors.Purple:
                            colors[i] = Color.Purple;
                            break;
                        case Butterfly.ButterflyColors.Red:
                            colors[i] = Color.Red;
                            break;
                        case Butterfly.ButterflyColors.White:
                            colors[i] = Color.GhostWhite;
                            break;
                        case Butterfly.ButterflyColors.Yellow:
                            colors[i] = Color.Yellow;
                            break;
                    }
                }

                // Set the color data for the texture
                texture.SetData(colors);

                return texture;
        }
Example #3
0
        /// <summary>
        /// This code heavily influenced by http://xbox.create.msdn.com/en-US/education/catalog/sample/chase_evade
        /// </summary>
        /// <param name="b"> the butterfly I wish to operate on</param>
        /// <param name="tether">that butterfly's tether point</param>
        /// <param name="speed">the speed at which we can move the butterfly</param>
        /// <returns></returns>
        private static Vector3 Wander(Butterfly b, Vector2 tether, float speed)
        {
            float wanderX = b.WanderDirection.X;
            float wanderY = b.WanderDirection.Y;

            Vector3 ButterflyPosition = b.getPosition();

            wanderX += MathHelper.Lerp(-.25f, .25f, (float)rand.NextDouble());
            wanderY += MathHelper.Lerp(-.25f, .25f, (float)rand.NextDouble());

            Vector2 wanderDirection = new Vector2(wanderX, wanderY);

            if (wanderDirection != Vector2.Zero)
            {
                wanderDirection.Normalize();
            }

            b.WanderDirection = wanderDirection;

            float distanceFromTether = Vector2.Distance(new Vector2(b.getPosition().X, b.getPosition().Y), tether);
            float maxDistanceFromTether = 1f;

            float normalizedDistance = distanceFromTether / maxDistanceFromTether;

            float turnBackToTetherSpeed = normalizedDistance;

            float angle = getRotationAngle(new Vector2(ButterflyPosition.X, ButterflyPosition.Y), tether, wanderDirection, turnBackToTetherSpeed * .15f);

            wanderDirection = Vector2.Transform(wanderDirection, Matrix.CreateRotationZ(angle));

            Vector3 displacement = new Vector3(wanderDirection, 0);

            Vector3 updateVect = ButterflyPosition + (displacement * speed);

            Vector3 clampedVect = Vector3.Clamp(updateVect, new Vector3(-6, -6, 0), new Vector3(6,5,0));

            if(updateVect.Length() != clampedVect.Length()) // we may be at an edge, lets flip ourselves 90 degrees
            {
                b.WanderDirection = b.WanderDirection * -1;
            }

            return clampedVect;
        }
 /// <summary>
 /// Creates a 1x1 pixel texture of the specified color.
 /// </summary>
 /// <param name="graphicsDevice">The graphics device to use.</param>
 /// <param name="color">The color to set the texture to.</param>
 /// <returns>The newly created texture.</returns>
 public static Texture2D Create(GraphicsDevice graphicsDevice, Butterfly.ButterflyColors color)
 {
     return Create(graphicsDevice, 1, 1, color);
 }
 void WrongChoice(Butterfly b)
 {
     soundBank.PlayCue("73581__benboncan__sad-trombone");
     spriteQueue.Add(new Tuple<Vector3,int>(b.getPosition(), 1));
     queueTimers.Add(30);
     scoreStrings.Add("x 0");
     b.Hide();
     mistakeCount++;
 }
 void RightChoice(Butterfly b)
 {
     spriteQueue.Add(new Tuple<Vector3, int>(b.getPosition(), 0));
     queueTimers.Add(30);
     soundBank.PlayCue("145459__soughtaftersounds__menu-click-sparkle");
     int score = playerProfile.Score;
     score += Math.Max(1, tier);
     playerProfile.Score = score;
     scoreStrings.Add(String.Format("x {0}", Math.Max(1, tier)));
     b.Hide();
 }