예제 #1
0
        void OnLevelLoadingComplete(EventArgs <ILevelInfo> arg)
        {
//            Debug.Log("Level load complete");

            // Test HUD
            Hud = SceneObject.Instantiate <UiHud>(Root);

            var resources = new Resources();

            resources.OnResourcesChanged += OnResourcesChanged;

            // Create object placer
            var host = GameObject.Instantiate <GameObject>();

            host.AddComponent <Inventory>().Setup(resources);

            // Display gameobject counter
            SceneObject.Instantiate <UiDebug>(Parent);

            // Player mouse interaction
            WorldMouse = new WorldMouse();

            // Create grid
            new Grid(16, 16, 2);

            LevelSystem.LoadingComplete -= OnLevelLoadingComplete;
        }
예제 #2
0
        void Sell()
        {
            if (selectedConstructionPoint == null)
            {
                return;
            }

            // Tell the Construction Point to remove its associated tower.
            // The 'onRemove' callback allows access to the tower before it is removed.
            selectedConstructionPoint.RemoveTower((tower) =>
            {
                ui.DisplayMessage = string.Format("Removed object '{0}' with id {1}", tower.Name, tower.Entity.ID);

                // Refund cost
                resources.Add(tower.CurrentTower.RefundCost);

                UiHud.CreateHitMarker(tower.Position, (text) =>
                {
                    text.Label.Alignment = Alignment.Center;
                    text.Label.ApplyStyle(AssetLibrary.TextStyles.HudWorldSpaceText);
                    text.Label.Color   = Color.Green;
                    text.Label.Content = "+" + tower.CurrentTower.RefundCost;
                });
            });

            upgradeMenuController.HideMenu();

            selectedConstructionPoint = null;
        }
예제 #3
0
        void Upgrade()
        {
            if (selectedConstructionPoint.Tower.NextTower != null)
            {
                if (resources.Value < selectedConstructionPoint.Tower.NextTower.Cost)
                {
                    ui.DisplayWarning = AssetLibrary.Strings.BuildNotEnoughResourcesToUpgrade;
                }
                else
                {
                    ui.DisplayMessage = AssetLibrary.Strings.BuildUpgradeSuccesful;

                    resources.Remove(selectedConstructionPoint.Tower.NextTower.Cost);

                    // Upgrade the selected construction point's associated tower.
                    selectedConstructionPoint.Tower?.Upgrade();

                    UiHud.CreateHitMarker(selectedConstructionPoint.Tower.Position, (text) =>
                    {
                        text.Label.ApplyStyle(AssetLibrary.TextStyles.HudWorldSpaceText);
                        text.Label.Color   = Color.White;
                        text.Label.Content = "UPGRADE!";
                    });
                }

                // Update the menu to reflect the values of the recently upgrade tower.
                upgradeMenuController.UpdateMenu(selectedConstructionPoint.Tower);
            }
        }
예제 #4
0
        void Build(UnitTowerData towerData)
        {
            if (towerData.UpgradePath.Count == 0)
            {
                Log.Error("Cannot build Tower '{0}' as it has no data inside its upgrade path. It needs at least one upgrade.", towerData.Name);
                return;
            }

            if (resources.Value < towerData.UpgradePath[0].Cost)
            {
                ui.DisplayWarning = AssetLibrary.Strings.BuildNotEnoughResources;
            }
            else
            {
                ui.DisplayMessage = AssetLibrary.Strings.BuildSuccessful;

                // Tell the construction point to place a tower. This is where the tower is instantiated and initialized.
                selectedConstructionPoint.PlaceTower(towerData);

                ghost.Hide();

                resources.Remove(towerData.UpgradePath[0].Cost);

                buildMenuController.HideMenu();

                // Display a hitmarker UI showing how many resources have been deducted for building this tower.
                UiHud.CreateHitMarker(selectedConstructionPoint.Position, (text) =>
                {
                    text.Label.ApplyStyle(AssetLibrary.TextStyles.HudWorldSpaceText);
                    text.Label.Color   = Color.Red;
                    text.Label.Content = "-" + towerData.UpgradePath[0].Cost.ToString();
                });
            }
        }
예제 #5
0
        public void Setup(UiHud hud, Resources resources)
        {
            this.hud = hud;
            this.resources = resources;

            // Update the HUD when the number of resources is changed
            resources.OnResourcesChanged += (amount) => hud.Resources.Value = resources.Value;

            // Create the level manager that references the player's base, enemies, and player-placed units
            levelManager = GameObject.AddComponent<LevelManager>();

            // Create the wave controller that controls the spawning on enemies
            waveController = new WaveManager(levelManager);
            waveController.EnemyReachedBase += OnEnemyReachedBase;
            waveController.EnemyKilled += OnEnemyKilled;
            waveController.WaveComplete += OnWaveComplete;

            // Assign default waves
            waveController.Data = AssetLibrary.Data.DefaultWaveData;

            // DEBUG
            Input.OnKey += (arg) =>
            {
                if (arg.KeyDown(EKeyId.eKI_Left))
                    playerBase.Health.ApplyDamage(10);

                if (arg.KeyDown(EKeyId.eKI_Right))
                    playerBase.Health.ApplyDamage(-10);
            };
        }
예제 #6
0
 private void Health_OnDamageReceived(int arg)
 {
     UiHud.CreateHitMarker(Position, (text) =>
     {
         text.Label.ApplyStyle(AssetLibrary.TextStyles.HudWorldSpaceText);
         text.Label.Color   = Color.Yellow;
         text.Label.Content = "-" + arg.ToString();
     });
 }
예제 #7
0
        void LevelSystem_LoadingComplete(EventArgs <ILevelInfo> arg)
        {
            // Create objects and inject dependencies
            levelManager = new LevelManager();
            hud          = new UiHud(Root);
            resources    = new Resources();
            new ObjectPlacer(resources);

            StartGame();
        }
예제 #8
0
        void EndGame()
        {
            Global.gEnv.pLog.LogToConsole("Game Over!");

            roundManager.RoundOver -= EndGame;

            host.Destroy();
            hud.Destroy();

            roundManager = null;
            resources    = null;
            hud          = null;

            GameOver?.Invoke();
        }
예제 #9
0
        void OnLevelLoadComplete(EventArgs <ILevelInfo> arg)
        {
            // Create objects and inject dependencies
            host = GameObject.Instantiate <GameObject>();

            resources = new Resources();
            hud       = SceneObject.Instantiate <UiHud>(Root);

            var inventory = host.AddComponent <Inventory>();

            inventory.Setup(resources);

            roundManager = host.AddComponent <RoundManager>();
            roundManager.Setup(hud, resources);
            roundManager.RoundOver += EndGame;

            new ManagedEntityTest();

            StartGame();
        }