public override void Update(GameTime gameTime) { var elapsedTime = (float)gameTime.ElapsedGameTime.TotalSeconds; //Falls der Gegner noch in Bewegung ist, und auch noch Wegpunkte vor sich if ((creepState == CreepState.Running) && (WayPoints != null) && (WayPoints.Count > 0)) { //Falls er einen Wegpunkt erreicht hat if (AtDestination) { //Nächsten Wegpunkte zum aktuellen machen WayPoints.Dequeue(); //Und die Gridposition richtig setzen GridPosition.X = (float)Math.Round(GridPosition.X, 0, MidpointRounding.AwayFromZero); GridPosition.Y = (float)Math.Round(GridPosition.Y, 0, MidpointRounding.AwayFromZero); //Auch die Punkte müssen neu berechnet werden, da ein Creep kurz vor Ende seiner Reise mehr Punkte gibt Points = (int)Math.Round(InitialHealth * maxMoveSpeed / (WayPoints.Count + 1), MidpointRounding.AwayFromZero) + 1; } else { //Blablabla, einfach die aktuelle Geschwindikeit errechnen float previousMoveSpeed = moveSpeed; float desiredMoveSpeed = FindMaxMoveSpeed(WayPoints.Peek()); moveSpeed = MathHelper.Clamp(desiredMoveSpeed, previousMoveSpeed - MaxMoveSpeedDelta * elapsedTime, previousMoveSpeed + MaxMoveSpeedDelta * elapsedTime); //Hier wird der Creep noch in die richtige Richtung gedreht var facingDirection = (float)Math.Atan2(direction.Y, direction.X); facingDirection = TurnToFace(GridPosition, WayPoints.Peek(), facingDirection, MaxAngularVelocity * elapsedTime); direction = new Vector2((float)Math.Cos(facingDirection), (float)Math.Sin(facingDirection)); Rotation = (float)Math.Atan2(direction.Y, direction.X); //Und die Position aktualisiert GridPosition = GridPosition + (direction * moveSpeed * elapsedTime); } //Jetzt noch die "richtige" Position ausrechnen, also die, die zum Zeichnen benötigt wird Position = new Vector2( GridPosition.X * GameScreen.LevelManager.GridSize.X + GameScreen.LevelManager.GridSize.X / 2, GridPosition.Y * GameScreen.LevelManager.GridSize.Y + GameScreen.LevelManager.GridSize.Y / 2); } //SInd wir am Ende des levels? if (TargetReached) { creepState = CreepState.Out; GameScreen.CreepOut(this); } //Das CustomUpdate für die Türme... if (CustomUpdate != null) { CustomUpdate(this, gameTime); } HealthPosition = new Vector2(Position.X - HealthSize.X / 2, Position.Y - Size.Y); base.Update(gameTime); }