Exemplo n.º 1
0
 private static void Ai_Idle(Frog frog, double elapsed)
 {
     if (frog.IsOnGround())
     {
         frog.Velocity.X = 0;
         if (frog.Timer.IsTimeYet(elapsed, JUMP_DELAY_TIME))
         {
             frog.Velocity.Y = -10;
             frog.Direction = (new List<Directions>() { Directions.Left, Directions.Right }[Rand.Next(2)]);
         }
     }
     else
     {
         frog.Velocity.X = (MAX_SPEED / 2) * frog.Direction.GetLateralDirectionSign();
     }
 }
Exemplo n.º 2
0
        private static void Ai_Attack(Frog frog)
        {
            Vector2 closingVelocity = new Vector2(frog.Target.Velocity.X - frog.Velocity.X, 0);
            Vector2 closingRange = new Vector2(frog.Target.Position.X - frog.Position.X, 0);
            Vector2 closingTime = new Vector2(Math.Abs(closingRange.X) / Math.Abs(closingVelocity.X), 0);
            Vector2 frogFuturePosition = frog.Target.Position + (frog.Target.Velocity * closingTime);
            float angle = frog.GetAngle(frog.Position, frogFuturePosition);

            if (frog.IsOnGround())
            {
                frog.Velocity.Y = -10;
            }
            else
            {
                frog.Velocity.X = (float)Math.Cos(angle) * MAX_SPEED / 1.5f;
            }
        }