Beispiel #1
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;
        }
Beispiel #2
0
        void InputController_Select(InputController.InputEvent inputEvent)
        {
            selectedConstructionPoint = inputEvent.Selection.Controller;

            if (!inputEvent.SelectionChanged && ActiveMenu != null)
            {
                // Hide the menu of the currently selected object if it is currently visible.
                ActiveMenu.HideMenu();
            }
            else
            {
                if (selectedConstructionPoint.Occupied)
                {
                    buildMenuController.HideMenu();
                    upgradeMenuController.ShowMenu(selectedConstructionPoint.Tower);
                }
                else
                {
                    upgradeMenuController.HideMenu();
                    buildMenuController.ShowMenu(selectedConstructionPoint.Position);
                }
            }
        }
Beispiel #3
0
        /// <summary>
        /// Sets up the level ready for the round to begin.
        /// </summary>
        public void Setup()
        {
            spawnPoints        = new List <SpawnPoint>();
            constructionPoints = new List <ConstructionPointController>();
            units = new List <Unit>();

            // Set the camera
            var camera = Env.EntitySystem.FindEntityByName(cameraName);

            if (camera != null)
            {
                var host = SceneObject.Instantiate(null);
                Camera.Current = host.AddComponent <Camera>();
                Camera.Current.OnPlayerEntityAssigned += (arg) =>
                {
                    arg.HostEntity.Position = camera.GetPos();
                    arg.HostEntity.Rotation = camera.GetRotation();
                    Env.Console.ExecuteString("gamezero_cam_fov 45");
                };
            }
            else
            {
                Global.gEnv.pLog.LogError("Level Manager: Camera is missing from the level. Make sure there is a Camera named " + cameraName);
            }

            // Find the Base reference entity
            PlayerBase = EntityFramework.GetEntity <Base>();
            if (PlayerBase != null)
            {
                PlayerBase.Setup();
            }
            else
            {
                Global.gEnv.pLog.LogError("Level Manager: Player Base is missing from the level. Make sure their is an entity named " + playerBaseName);
            }

            // Find construction point reference entities
            EntityFramework.GetEntities <ConstructionPoint>().ForEach(x =>
            {
                // Create construction point
                var cell = new ConstructionPointController(x.NativeEntity.GetPos(), x.NativeEntity.GetRotation(), 4, x);
                constructionPoints.Add(cell);

                // Register callback for a Unit is added or removed. We need a reference so we can update the unit with the position of each enemy.
                cell.OnUnitPlaced  += AddUnit;
                cell.OnUnitRemoved += RemoveUnit;
            });

            // Find spawn point reference entities
            var spawnsInLevel = EntityFramework.GetEntities <SpawnPoint>();

            if (spawnsInLevel.Count == 0)
            {
                Log.Warning("Failed to find any spawn points");
            }
            else
            {
                spawnsInLevel.ForEach(x =>
                {
                    // Create spawn point
                    Path path = null;

                    if (PlayerBase != null)
                    {
                        path = new Path(x.NativeEntity.GetPos(), PlayerBase.Position);
                    }

                    var instance = new SpawnPoint(path);
                    spawnPoints.Add(instance);

                    // Register callback for when an enemy is spawned and despawned
                    instance.OnEnemySpawned   += AddUnit;
                    instance.OnEnemyDespawned += RemoveUnit;
                });
            }

            // Create a grid, if the level requires one
            var gridEntity = Env.EntitySystem.FindEntityByName("Grid");

            if (gridEntity != null)
            {
                new Grid(16, 16, 2);
            }
        }