Пример #1
0
    private void UpdateAtCursor()
    {
        var contents = GetGridContents((int)cursorGrid.x, (int)cursorGrid.y);

        switch (contents)
        {
        case GridStatus.Empty:
            deleteButton.Disabled  = true;
            upgradeButton.Disabled = true;
            tower1Button.Disabled  = credits < TowerCosts.GetTowerCost(1, 1).Cost;
            tower2Button.Disabled  = credits < TowerCosts.GetTowerCost(2, 1).Cost;
            break;

        case GridStatus.Wall:
            deleteButton.Disabled  = true;
            upgradeButton.Disabled = true;
            tower1Button.Disabled  = true;
            tower2Button.Disabled  = true;
            break;

        case GridStatus.Tower:
            deleteButton.Disabled  = false;
            upgradeButton.Disabled = false;
            tower1Button.Disabled  = true;
            tower2Button.Disabled  = true;
            break;
        }
    }
Пример #2
0
    private void CreateTower(Tower tower)
    {
        //tower.Type = type;
        tower.X = (int)cursorGrid.x;
        tower.Y = (int)cursorGrid.y;
        var pos = GetPosition((int)cursorGrid.x, (int)cursorGrid.y);

        tower.Position = pos;
        AddChild(tower);
        var cost = TowerCosts.GetTowerCost(tower.Type, tower.Level);

        credits -= cost.Cost;
        SetCredits();
    }
Пример #3
0
    private void TowerTargetting()
    {
        foreach (Tower tower in GetTree().GetNodesInGroup("tower"))
        {
            var towerPos = tower.Position;

            foreach (Alien alien in GetTree().GetNodesInGroup("alien"))
            {
                var alienPos = alien.GlobalPosition;

                var distance = towerPos.DistanceTo(alienPos);
                var cost     = TowerCosts.GetTowerCost(tower.Type, tower.Level);
                if (distance < cost.Range)
                {
                    var vector = alienPos - towerPos;
                    tower.FireAtAlien(vector);
                    tower.LookAt(alienPos);
                    break;
                }
            }
        }
    }