Update() приватный Метод

private Update ( ) : void
Результат void
Пример #1
0
 private void Update()
 {
     if (!checkpointManager.isAtLastCheckpoint && checkpointManager.isNearNextCheckpoint)
     {
         checkpointManager.Update();
         if (checkpointManager.isAtLastCheckpoint)
         {
             gameController.OnFinishLineEnter("player");
         }
     }
 }
Пример #2
0
    private void Update()
    {
        if (!checkpointManager.isAtLastCheckpoint && checkpointManager.isNearNextCheckpoint)
        {
            checkpointManager.Update();
            if (checkpointManager.isAtLastCheckpoint)
            {
                gameController.OnFinishLineEnter("player");
            }
        }

        if (carAI.action == Action.Forward || carAI.action == Action.ForwardLeft || carAI.action == Action.ForwardRight)
        {
            physics.Accelerate();
        }
        if (carAI.action == Action.Reverse)
        {
            physics.Reverse();
        }
        if (carAI.action == Action.Forward || carAI.action != Action.Forward || carAI.action != Action.None)
        {
            physics.ResetForce();
        }
        if (carAI.action == Action.Left || carAI.action == Action.ForwardLeft)
        {
            physics.SteeringWheelPos = 5.0f;
        }
        else if (carAI.action == Action.Right || carAI.action == Action.ForwardRight)
        {
            physics.SteeringWheelPos = -5.0f;
        }
        else
        {
            physics.SteeringWheelPos = 0;
        }
    }
Пример #3
0
        public void OnUpdate(float deltaT)
        {
            if (!IsRunning)
            {
                return;
            }

            // Update our raycasts to account for the movement in the last frame
            Raycasts = GetRaycasts();
            var(rayDistances, collisions) = CollisionHelper.GetRaycastCollisions(Raycasts, map);

            this.Collisions = collisions;

            Controller.OnUpdate(deltaT);

            // Get the next action to take
            var output = Controller.GetOutput(rayDistances, Position, Heading, checkpointManager.CurrentWaypoint.Centroid);

            // Update the speed
            speed += output.Acceleration * Configuration.AccelerationCoefficient * deltaT;
            speed -= speed * Configuration.DragCoefficient;

            // Apply the max speed
            speed = Math.Min(speed, Configuration.MaximumForwardSpeed);
            speed = Math.Max(speed, Configuration.MaximumReverseSpeed);

            // Apply the desired rotation
            var turningForce = -output.LeftTurnForce + output.RightTurnForce;

            // Is this correct? 'Maximum' makes it sound like it should be capped.
            Heading += Configuration.MaximumRotationRate * deltaT * turningForce;

            // Update position
            var previousPosition = new Vector2f(Position.X, Position.Y);

            Position.X += (float)Math.Cos(Heading + 1.5708) * speed * deltaT;
            Position.Y += (float)Math.Sin(Heading + 1.5708) * speed * deltaT;

            checkpointManager.Update(Position);

            body.Position = Position;
            body.Rotation = Heading;

            IsRunning = !CheckMapCollision();

            // Kill any cars that have stopped moving, their state will never change,
            // and they will be stuck in this position forever.
            if (TimeAlive > 5)
            {
                ////IsRunning &= speed > 0;
            }

            // If we are not running, skip the fitness update.
            if (IsRunning)
            {
                this.UpdateFitness(deltaT, previousPosition, Position);
            }
            else
            {
                Controller.KillCar();
            }

            this.TotalDistance += previousPosition.Magnitude(Position);
        }