Пример #1
0
    public override void HandleInput(InputHelper inputHelper)
    {
        base.HandleInput(inputHelper);
        mousePos = inputHelper.MousePosition;

        plane = GameWorld.FindByType <Camera>()[0].currentPlane;
        node  = plane.NodeAt(mousePos / Camera.scale, false);
        if (previousNode != node)
        {
            if (previousNode != null)
            {
                previousNode.selected = false;
            }
            previousNode = node;
        }

        if (node == null)
        {
            return;
        }
        else
        {
            node.selected = true;
        }

        selectedPossible = !node.solid && node.available && inputHelper.MouseInGameWindow;

        if (inputHelper.MouseLeftButtonPressed() &&
            inputHelper.MouseInGameWindow &&
            selected != null &&
            selectedPossible)
        {
            Type       t    = Type.GetType(selected.itemType);              //Get the type of the object
            object     temp = Activator.CreateInstance(t);                  //Create an instance of that object
            GameObject obj  = temp as GameObject;                           //Cast it as a GameObject
            obj.Position = node.Position + new Vector2(NODE_SIZE.X / 2, 0); //Adjust the position to the middle of the GridNode
            if (selected.itemType.Equals("ResourceTower") && GameWorld.FindByType <ResourceTower>().Count > 2)
            {
                selected = null;
                return;
            }
            plane.Add(obj);                                        //Add it to the hierarchy
            obj.MyParticleControl.AddTowerBuildGlow(obj.Position); //Add particle effect
            EcResources -= selected.cost;                          //Subtract its cost from the resources
            PlaySound(SND_TOWERPLACE);

            if (!inputHelper.IsKeyDown(Keys.LeftShift) || selected.cost > EcResources) //allow shift-clicking multiple towers
            {
                selected = null;                                                       //Reset the selected object reference
            }
        }

        //Cancel the current selection with X or right click
        if (inputHelper.KeyPressed(Keys.X) && selected != null || inputHelper.MouseRightButtonPressed() && selected != null)
        {
            selected = null;
        }
    }
Пример #2
0
    public Overlay() : base()
    {
        selected         = null;
        selectedPossible = false;
        mousePos         = Vector2.Zero;
        gridSize         = 128;
        gridWidth        = 4;
        gridHeight       = 4;
        gridPos          = new Vector2(450 + 2, SCREEN_SIZE.Y - OVERLAY_SIZE.Y + 2);
        List <string> TowerNames = new List <string>(TOWER_INFO.Keys);

        for (int i = 0; i < TowerNames.Count; ++i)
        {
            Add(new OverlayTowerItem(TowerNames[i], gridPos + new Vector2((gridSize + 40) * i, 16)));
        }
        Add(TowerInfo = new OverlayTowerInfo {
            Position = new Vector2(5, SCREEN_SIZE.Y - OVERLAY_SIZE.Y)
        });
        Add(new MiniMap());
        Add(new UltimateTimer());
    }