Example #1
0
    private void SwitchToNextNonEmptyAmmo(PlanetViewController planet)
    {
        if (planet.GetCurrentAmmo() > 0)
        {
            return;
        }
        var rocketTypeInt = (int)planet.GetCurrentRocketSettings().rocketType;

        for (var i = 0; i < Enum.GetValues(typeof(RocketType)).Length; i++)
        {
            rocketTypeInt++;
            if (rocketTypeInt >= Enum.GetValues(typeof(RocketType)).Length)
            {
                rocketTypeInt = 0;
            }

            planet.SetRocketType((RocketType)rocketTypeInt);
            if (planet.GetCurrentAmmo() <= 0)
            {
                continue;
            }

            break;
        }
    }
Example #2
0
    /// <summary>
    /// Calculates approximately trajectory for rockets
    /// </summary>
    /// <param name="sun"></param>
    /// <param name="planetController"></param>
    /// <returns></returns>
    private Vector3[] CalculateForecastTrajectory(CelestialObject sun, PlanetViewController planetController)
    {
        _trajectoryPoints[0] = planetController.GetMuzzle().position;
        _trajectoryPoints[1] = planetController.GetMuzzle().position + planetController.transform.up;
        var time = 0f;
        var expectedDeltaTime = 0.016f;

        for (int i = 2; i < TRAJECTORY_POINT_COUNT; i++)
        {
            var dir                   = (_trajectoryPoints[i - 1] - _trajectoryPoints[i - 2]).normalized;
            var sunPosition           = sun.transform.position;
            var gravityPowerMagnitude =
                sun.GetGravityModifier() / Mathf.Pow(Vector3.Distance(sunPosition, _trajectoryPoints[i - 1]), 2);
            time += expectedDeltaTime;
            var speed = PlanetViewController.ROCKET_START_VELOCITY +
                        planetController.GetCurrentRocketSettings().acceleration *time;
            var gravityPower = (sunPosition - _trajectoryPoints[i - 1]).normalized * gravityPowerMagnitude;

            var delta = (dir * (speed) + gravityPower) * expectedDeltaTime;
            _trajectoryPoints[i] = _trajectoryPoints[i - 1] + delta;
        }

        return(_trajectoryPoints);
    }