/// <summary> /// Update the AI in circling mode /// </summary> /// <param name="lev">Current level</param> /// <param name="wo">WorldObject that owns the AI</param> private void UpdateFlybyCircling(Level lev, WorldObject wo) { // Cache some parameters Player p = lev.Player; float deltaPlayerX = p.WorldX - wo.WorldX; float deltaPlayerY = p.WorldY - wo.WorldY; // If far enough from player then switch to attack mode if (Math.Abs(deltaPlayerX) >= MaxX) { wo.VelocityY = 0.0F; flybyState = FlybyState.Attacking; return; } // Move into circling position if (wo.VelocityX > 0.0F) { ApplyPositiveAccelerationX(wo); } else { ApplyNegativeAccelerationX(wo); } if (deltaPlayerY < circleY) { ApplyNegativeAccelerationY(wo); } else { wo.WorldY = lev.Player.WorldY - circleY; wo.VelocityY = 0.0F; } }
/// <summary> /// Update the AI in attacking mode. /// </summary> /// <param name="lev">Current level</param> /// <param name="wo">WorldObject that owns AI</param> private void UpdateFlybyAttacking(Level lev, WorldObject wo) { // If shots are fired then prepare for next attack // by chaning the mode to circling if (attackLaunched) { wo.Walk(); flybyState = FlybyState.Circling; attackLaunched = false; return; } // Distance to any incoming shots float shotDistX = 0.0F; float shotDistY = 0.0F; // Check if evasion is required if (CheckDuck(wo, lev, ref shotDistX, ref shotDistY)) { flybyState = FlybyState.Circling; wo.VelocityY = 0.0F; return; } // Cache some parameters Player p = lev.Player; float deltaPlayerX = p.WorldX - wo.WorldX; float deltaPlayerY = p.WorldY - wo.WorldY; // Check if conditions are right for attacking if (Math.Abs(deltaPlayerX) <= MinX) { wo.VelocityY = 0.0F; wo.Attack(); attackLaunched = true; return; } // Move into attack position if (deltaPlayerX > 0.0F) { ApplyPositiveAccelerationX(wo); } else { ApplyNegativeAccelerationX(wo); } if (deltaPlayerY > attackY) { ApplyPositiveAccelerationY(wo); } else { wo.WorldY = lev.Player.WorldY - attackY; wo.VelocityY = 0.0F; } }
/// <summary> /// When resetting a level, this AI type needs to reset some /// extra data as well. /// </summary> public override void Reset() { base.Reset(); flybyState = FlybyState.Attacking; attackLaunched = false; }