Beispiel #1
0
    void ProcessShipLaunch()
    {
        if (_queuedToLaunch.Count == 0)
        {
            return;
        }

        if (Population == 0)
        {
            _queuedToLaunch.Clear();
            return;
        }

        // Increment the timer
        _launchTimer += Time.DeltaTime;

        // When the timer is activated, launch ship (one for each different target)
        if (_launchTimer > Random.Range(0.05f, 0.15f))
        {
            // Get target
            foreach (var target in _queuedToLaunch.Distinct().ToList())
            {
                if (LaunchShipHandler != null)
                {
                    Population--;
                    UpdatePopulationText();
                    LaunchShipHandler(this, target);
                }
                _queuedToLaunch.Remove(target);
            }

            // Reset timer
            _launchTimer = 0;
        }
    }
Beispiel #2
0
    protected override void Update()
    {
        if (IsNeutral)
        {
            return;
        }

        _decisionTimer += Time.DeltaTime;

        // Make a decision every 8-15 seconds
        if (_decisionTimer > Random.Range(8, 20))
        {
            // Decide between offensive and defensive strategies
            if (Random.Value >= 0.4f)
            {
                // Do an offensive maneuver between 1-2 times at once
                for (int i = 0; i < Random.Range(1, 3); i++)
                {
                    OffensiveStrategy();
                }
            }
            else
            {
                // Do a defensive maneuver between 1-3 times at once
                for (int i = 0; i < Random.Range(1, 4); i++)
                {
                    DefensiveStrategy();
                }
            }

            _decisionTimer = 0;
        }
    }
Beispiel #3
0
    private void LaunchShip(Planet source, Planet target)
    {
        var ship = Instantiate <Ship>("Ship", source.Transform.Position + new Vector2(Random.Range(0, 10f), Random.Range(0, 10f)));
        var sr   = ship.AddComponent <SpriteRenderer>();
        var rb   = ship.AddComponent <Rigidbody>();
        var a    = ship.AddComponent <Animator>();
        var fsm  = ship.AddComponent <FSM>();
        var v    = ship.AddComponent <Vehicle>();
        var seek = ship.AddComponent <Seek>();

        sr.Sprite = ShipSprite;
        sr.Layer  = 0.55f;
        sr.Color  = source.Owner.TeamColor;
        a.AddAnimation("explosion", ShipExplosionAnimation);
        a.Looping = false;
        v.Behaviours.Add(seek);

        ship.GameController = this;
        ship.Owner          = source.Owner;
        ship.Source         = source;
        ship.Target         = target;

        Ships.Add(ship);
    }