public void Update(Ship ship) { float ChaseThreshold = ChaseDistance; float CaughtThreshold = CaughtDistance; float distanceFromShip = Vector2.Distance(Position, ship.GetPosition()); if (Orientation < TurnToFace(Position, ship.GetPosition(), Orientation, TurnSpeed) && Orientation > TurnToFace(Position, ship.GetPosition(), Orientation, TurnSpeed)) { state = State.Shooting; fakeTime++; } if(state == State.Shooting && fakeTime == 10) { Shoot(); fakeTime = 0; } if (distanceFromShip > EvadeDistance + Hysteresis) { state = State.Wander; } else if (distanceFromShip < EvadeDistance - Hysteresis) { state = State.Evading; } if (state == State.Evading) { Vector2 seekPosition = 2.5f * Position - ship.GetPosition(); Orientation = TurnToFace(Position, seekPosition, Orientation, TurnSpeed); currentSpeed = MathHelper.Min(currentSpeed++, MaxSpeed); } if (state == State.Chasing) { ChaseThreshold += Hysteresis / 2; CaughtThreshold -= Hysteresis / 2; } else { Wander(Position, ref WanderDirection, ref Orientation, TurnSpeed); currentSpeed = .35f * MaxSpeed; } for (int i = 0; i < bullets.Count; i++) bullets[i].Update(); for (int i = 0; i < bullets.Count; i++) { if (bullets[i].Outside()) bullets.RemoveAt(i); } Rectangle shiprec = new Rectangle((int)ship.GetPosition().X - 190, (int)ship.GetPosition().Y - 190, ship.shipRing.Width, ship.shipRing.Height); for (int i = 0; i < bullets.Count; i++) { if (shiprec.Intersects(new Rectangle((int)bullets[i].Position.X, (int)bullets[i].Position.Y, bullets[i].texture.Width, bullets[i].texture.Height))) { bullets.RemoveAt(i); ship.Hurt(); } } heading = new Vector2((float)Math.Cos(Orientation), (float)Math.Sin(Orientation)); Position += heading * currentSpeed; }