Esempio n. 1
0
        /// <summary>
        /// Move the camera using the Keyboard
        /// </summary>
        /// <param name="amount">The amount of time, frame-independent thing</param>
        private void HandleKeyboard(float amount)
        {
            KeyboardState keyboardState = WaveServices.Input.KeyboardState;

            if (keys.IsCommandExecuted(CommandEnum.CameraUp) && !(transform.Y < topLeftCorner.Y + tileHeight))
            {
                transform.Y -= speed * amount;
            }
            else if (keys.IsCommandExecuted(CommandEnum.CameraDown) && !(transform.Y > bottomRightCorner.Y - tileHeight))
            {
                transform.Y += speed * amount;
            }

            if (keys.IsCommandExecuted(CommandEnum.CameraLeft) && !(transform.X < topLeftCorner.X + tileWidth))
            {
                transform.X -= speed * amount;
            }
            else if (keys.IsCommandExecuted(CommandEnum.CameraRight) && !(transform.X > bottomRightCorner.X - tileWidth))
            {
                transform.X += speed * amount;
            }
            else if (keys.IsCommandExecuted(CommandEnum.CameraCenter))
            {
                Player selected = UIBehavior.ui.activePlayer;
                if (selected != null && selected.selectedWO != null)
                {
                    transform.Position = selected.selectedWO.transform.Position;
                }
            }
        }
Esempio n. 2
0
        protected override void Update(TimeSpan gameTime)
        {
            if (debugSwitch.IsOn)
            {
                //Only for debug purposes
                HandleDebugUI();
            }
            else
            {
                HandleUI();
            }

            if (cottageList[0].IsVisible && (activePlayer == null || activePlayer.selectedWO == null))
            {
                //Disable cottage list if no longer active
                UpdateCottageUI(null);
            }


            if (keysBehavior.IsCommandExecuted(CommandEnum.StopCreation))
            {
                Uncheck();
            }
            if (creating != null && keysBehavior.IsCommandExecuted(CommandEnum.Create) && !MouseOverGUI())
            {
                if (creating == "Castle")
                {
                    CreateCastle();
                }
                else
                {
                    Create();
                }
            }
            if (debugSwitch.IsOn)
            {
                foreach (CommandEnum cmd in woCreationButtons.Keys)
                {
                    if (keysBehavior.IsCommandExecuted(cmd))
                    {
                        woCreationButtons[cmd].IsChecked = true;
                        break;
                    }
                }
            }
            foreach (CommandEnum cmd in buildingCreationButtons.Keys)
            {
                if (keysBehavior.IsCommandExecuted(cmd))
                {
                    buildingCreationButtons[cmd].IsChecked = true;
                    break;
                }
            }

            if (keysBehavior.IsCommandExecuted(CommandEnum.ToggleFog))
            {
                // fog.ToggleFog(fogOn);
                fogOn = !fogOn;
            }
        }
Esempio n. 3
0
        protected override void Update(TimeSpan gameTime)
        {
            KeyboardState keyboard     = WaveServices.Input.KeyboardState;
            MouseState    currentMouse = WaveServices.Input.MouseState;

            if (keysBehavior.IsCommandExecuted(CommandEnum.ToggleFog))
            {
                Trace.WriteLine(string.Format("Keyboard P state = {0,8} Keyboard O state = {1,8}", keyboard.P, keyboard.O));
            }


            if (keysBehavior.IsCommandExecuted(CommandEnum.StartPath))
            {
                ShowMapInfo();
            }
        }
Esempio n. 4
0
        protected override void Update(TimeSpan gameTime)
        {
            if (!active || !isLocalPlayer)

            {
                return;
            }

            currentTile = Map.map.GetTileByWorldPosition(GetMousePosition());


            //If the wo is inside other (p.e: a cottage) we deselect it
            if (selectedWO != null && (selectedWO.GetAction() == ActionEnum.Inside || selectedWO.IsDestroyed()))
            {
                selectedWO = null;
                SendSelect(selectedWO);

                ui.ClearActionButtons();
                lastActionTile = null;
            }


            if (ui.MouseOverGUI())
            {
                return;
            }


            //If we are selecting something we own
            if (selectedWO != null && !selectedWO.IsDestroyed() && selectedWO.player == this)
            {
                if (currentTile != null)
                {
                    currentMobile = Map.map.GetMobile(currentTile.X, currentTile.Y);
                    currentWO     = Map.map.GetWorldObject(currentTile.X, currentTile.Y);

                    //If we are not creating a path
                    if (!readingTiles && selectedWO.IsMobile())
                    {
                        //But we want to start a new path
                        if (keysBehavior.IsCommandExecuted(CommandEnum.StartPath))
                        {
                            if (!selectedWO.IsActionBlocking() && map.Adjacent(currentTile, map.GetTileByWorldPosition(selectedWO.GetCenteredPosition())))
                            {
                                //Start path
                                readingTiles = true;
                                path.Add(Map.map.GetTileByWorldPosition(selectedWO.GetCenteredPosition()));
                            }
                        }
                    }

                    if (readingTiles && keysBehavior.IsCommandExecuted(CommandEnum.AddTile))
                    {
                        AddTile();
                    }
                    if (readingTiles && keysBehavior.IsCommandExecuted(CommandEnum.FinishPath))
                    {
                        //Right button no longer pressed, set path
                        MovementBehavior per = selectedWO.Owner.FindComponent <MovementBehavior>();
                        if (path.Count > 2 && per != null)
                        {
                            SendPath(path);
                        }
                        readingTiles = false;
                        path.Clear();
                    }
                    if (keysBehavior.IsCommandExecuted(CommandEnum.ActInTile))
                    {
                        readingTiles = false;
                        path.Clear();
                        if (ui.optionsAlreadyShown && currentTile == lastActionTile && selectedWO.IsMobile() && !selectedWO.IsActionBlocking())
                        {
                            for (int i = 0; i < ui.actions.Count; i++)
                            {
                                if (ui.actions[i].text == "Move")
                                {
                                    ui.actions[i].buttonAction(null, null);
                                    break;
                                }
                            }
                            lastActionTile = null;
                        }
                        else
                        {
                            HandleAction();
                        }
                    }

                    //Shortcuts for vicious ones

                    if (keysBehavior.IsCommandExecuted(CommandEnum.Chop))
                    {
                        Chop();
                    }
                    if (keysBehavior.IsCommandExecuted(CommandEnum.Fight))
                    {
                        Fight();
                    }
                    if (keysBehavior.IsCommandExecuted(CommandEnum.Build))
                    {
                        Build();
                    }
                    if (keysBehavior.IsCommandExecuted(CommandEnum.Heal))
                    {
                        Heal();
                    }
                    if (keysBehavior.IsCommandExecuted(CommandEnum.Train))
                    {
                        Train();
                    }

                    //Cottage shortcuts
                    Cottage cottage = selectedWO.Owner.FindComponent <Cottage>();
                    if (cottage != null)
                    {
                        if (keysBehavior.IsCommandExecuted(CommandEnum.CottageOne))
                        {
                            SendExit(1, currentTile);
                        }
                        if (keysBehavior.IsCommandExecuted(CommandEnum.CottageTwo))
                        {
                            SendExit(2, currentTile);
                        }
                        if (keysBehavior.IsCommandExecuted(CommandEnum.CottageThree))
                        {
                            SendExit(3, currentTile);
                        }
                        if (keysBehavior.IsCommandExecuted(CommandEnum.CottageFour))
                        {
                            SendExit(4, currentTile);
                        }
                        if (keysBehavior.IsCommandExecuted(CommandEnum.CottageFive))
                        {
                            SendExit(5, currentTile);
                        }
                        if (keysBehavior.IsCommandExecuted(CommandEnum.CottageSix))
                        {
                            SendExit(6, currentTile);
                        }
                    }
                    //Update cottage info any
                    ui.UpdateCottageUI(cottage);
                }
                if (keysBehavior.IsCommandExecuted(CommandEnum.Stop))
                {
                    SendStop(selectedWO);
                }
                if (keysBehavior.IsCommandExecuted(CommandEnum.Destroy))
                {
                    Destroy();
                }
            }

            //Select
            if (keysBehavior.IsCommandExecuted(CommandEnum.Select))
            {
                lastActionTile = null;
                Select();
            }
        }