Пример #1
0
 private void Start()
 {
     artileryCommander = GetComponent <ArtileryCommander>();
     damageable        = GetComponent <Damageable>();
     shieldCommander   = GetComponent <ShieldCommander>();
 }
Пример #2
0
        private void Update()
        {
            if (target != null)
            {
                Debug.DrawLine(transform.position, target.transform.position, Color.green);
            }
            Debug.DrawRay(transform.position, artileryCommander.aimDirection * 10, Color.red);
            if (targetDirection != null)
            {
                Debug.DrawRay(transform.position, targetDirection.Value * 10, Color.blue);
            }


            if (damageable.isDead)
            {
                return;
            }

            if (target != null && target.isDead)
            {
                target = null;
                state  = AIState.EnemySearch;
            }

            AimIfNeeded();

            switch (state)
            {
            case AIState.EnemySearch:
                var planets = GameManager.i.GetAlivePlanets();
                if (planets.Length == 0)
                {
                    return;
                }
                Planet nearestPlanet = null;
                foreach (var planet in planets)
                {
                    if (planet.gameObject.name == this.gameObject.name)
                    {
                        continue;
                    }
                    var distance = Vector3.Distance(transform.position, planet.transform.position);
                    if (nearestPlanet == null)
                    {
                        nearestPlanet = planet;
                    }
                    else
                    {
                        var distanceToNearestPlanet = Vector3.Distance(transform.position, nearestPlanet.transform.position);
                        if (distance < distanceToNearestPlanet)
                        {
                            nearestPlanet = planet;
                        }
                    }
                }
                target = nearestPlanet.GetComponent <Damageable>();
                state  = AIState.Aiming;
                break;

            case AIState.Aiming:
                if (aimed)     // aimed
                {
                    state = AIState.HoldingFire;
                }
                break;

            case AIState.HoldingFire:
                if (!artileryCommander.isHoldingFire)
                {
                    artileryCommander.HoldFire();
                }
                else
                {
                    if (artileryCommander.currentProgressPercent <= .1f)
                    {
                        return;
                    }
                    else
                    {
                        artileryCommander.ReleaseFire();
                        state = AIState.OnCoolDown;
                    }
                }
                break;

            case AIState.OnCoolDown:

                if (artileryCommander.isOnCooldown)
                {
                    return;
                }
                else
                {
                    state = AIState.EnemySearch;
                }

                break;
            }
        }
Пример #3
0
        private void LoadGameState()
        {
            GameState state = SaveManager.i.gameData.state;

            this.score            = state.score;
            this.kills            = state.kills;
            this.playerName       = state.playerName;
            this.playerWeaponName = state.playerWeaponName;
            this.planetsCount     = state.numberOfPlanets;

            foreach (var savedPlanet in state.planets)
            {
                Color planetColor = new Color {
                    r = savedPlanet.colorR,
                    g = savedPlanet.colorG,
                    b = savedPlanet.colorB
                };

                GameObject planet = sphereGenerator.CreatePlanet(planetColor, savedPlanet.size);
                planet.name = savedPlanet.name;

                Planet planetComp = planet.AddComponent <Planet>();
                planetComp.Configure(planet.name, planetColor, savedPlanet.size, savedPlanet.density, savedPlanet.orbitSpeed, savedPlanet.mass);
                planet.transform.position = new Vector3(savedPlanet.pos[0], savedPlanet.pos[1], savedPlanet.pos[2]);

                ArtileryCommander commander = planet.GetComponent <ArtileryCommander>();
                commander.SetWeapon(savedPlanet.weaponName);
                uiProgressBar.SubscribeOnArtileryCommander(commander);

                Damageable damageable = planet.GetComponent <Damageable>();
                float      maxHealth  = savedPlanet.size * savedPlanet.mass;
                damageable.SetHealth(maxHealth, savedPlanet.health);
                if (savedPlanet.health == 0)
                {
                    damageable.isDead = true;
                    planet.SetActive(false);
                }
                uiHealthBar.SubscribeOnDamageable(damageable);

                planets.Add(planet);
            }

            List <UIPointerTarget> pointerTargets = new List <UIPointerTarget>();

            for (int index = 0; index < planets.Count; index++)
            {
                var planet = planets[index];
                if (planet.name == playerName)
                {
                    playerPlanetIndex = index;
                    planet.AddComponent <PlayerPlanet>();
                    cameraController.SetTarget(planet.transform, false);
                    planet.AddComponent <ShieldCommander>();
                    uIPointer.SetPlayer(planet.transform);
                }
                else
                {
                    planet.AddComponent <AIPlanet>();
                    pointerTargets.Add(new UIPointerTarget(planet.transform, GameAssets.i.pointerSprite));
                }
            }
            uIPointer.SetTargets(pointerTargets);

            UpdateHUD();
        }