Esempio n. 1
0
    void FixedUpdate()
    {
        if (gameState.isPaused)
        {
            return;
        }

        if (gameState.timeLeft <= 0)
        {
            EventManager.TriggerEvent("GameOver");
            gameState.isPaused = true;
            return;
        }

        int level = difficulty.GetLevelFromDistance(rb.transform.position.x);

        if (rb.velocity.x < difficulty.GetMaxSpeed(level) * gameState.velocityMultiplier)
        {
            float acceleration = playerConfig.maxAcceleration * GetMass() * gameState.accelerationMultiplier;
            rb.AddForce(new Vector3(acceleration, 0, 0));
        }

        float   step   = playerConfig.lateralSpeed * Time.deltaTime;
        Vector3 target = new Vector3(transform.position.x, transform.position.y, renderConfig.lanePosns[posIdx]);

        transform.position = Vector3.MoveTowards(transform.position, target, step);

        gameState.timeLeft -= Time.deltaTime / gameState.efficiencyMultiplier;
    }
Esempio n. 2
0
    public static void SetNextGasLocation(GameStateScriptableObject gameState, LevelDifficultyScriptableObject difficulty)
    {
        float timeLeft = difficulty.timeBetweenGas;

        while (timeLeft > 0f)
        {
            float timeSpentInLevel = difficulty.cumLevelDists[gameState.gasLevel] - gameState.nextGasLocation;
            gameState.nextGasLocation += Mathf.Min(timeLeft, timeSpentInLevel) * difficulty.GetMaxSpeed(gameState.gasLevel);
            if (timeSpentInLevel < timeLeft)
            {
                gameState.gasLevel += 1;
            }

            timeLeft -= timeSpentInLevel;
        }
    }