Пример #1
0
        public StandardMelee(InputHandler handler)
        {
            _mousePosition = new Vector2f(500, 500);

            CurrentStatus = StatusState.WaitingForPlayers;

            uiState = UIStateTypes.Normal;
            currentHotkey = null;
            currentHotkeySheet = null;
            standardHotkeys = Settings.GetSheet("standard_game_mode_controls");

            InputHandler = handler;
            myId = 0;
            map = new TileMap();

            allowMinimapCameraMove = true;
            selectedUnits = null;
            controlGroups = new Dictionary<Keyboard.Key, List<EntityBase>>();

            for (int i = 27; i <= 35; i++)
            {
                controlGroups.Add((Keyboard.Key) i, new List<EntityBase>());
            }

            controlBoxP1 = new Vector2f(0, 0);
            controlBoxP2 = new Vector2f(0, 0);
            selectedAttackMove = false;
            releaseSelect = false;

            CameraPosition = new Vector2f(0, 0);

            miniMap = new MiniMap(map, Fog, entities);

            //Load Sprites
            bottomHUDGUI = new Sprite(ExternalResources.GTexture("Resources/Sprites/HUD/BottomGUI.png"));
            alertHUDAlert = new Sprite(ExternalResources.GTexture("Resources/Sprites/HUD/Alert_Alert.png"));
            alertHUDUnitCreated = new Sprite(ExternalResources.GTexture("Resources/Sprites/HUD/Alert_UnitCreated.png"));
            alertHUDBuildingCreated =
                new Sprite(ExternalResources.GTexture("Resources/Sprites/HUD/Alert_BuildingFinished.png"));

            avatarWorker = new Sprite(ExternalResources.GTexture("Resources/Sprites/HUD/HUD_AVATAR_WORKER.png"));

            hudBoxUnit = new Sprite(ExternalResources.GTexture("Resources/Sprites/HUD/HUD_BOX_Unit.png"));
            hudBoxBuilding = new Sprite(ExternalResources.GTexture("Resources/Sprites/HUD/HUD_BOX_Building.png"));

            hudControlBox = new Sprite(ExternalResources.GTexture("Resources/Sprites/HUD/ControlGroupBox.png"));
            hudControlBox.Origin = new Vector2f(hudControlBox.TextureRect.Width/2, 0);

            viewBounds = new Sprite(ExternalResources.GTexture("Resources/Sprites/Hud/ViewBounds.png"));

            //Load Sounds
            moveSound = new Sound(ExternalResources.GSoundBuffer("Resources/Audio/MoveCommand/0.wav"));
            attackMoveSound = new Sound(ExternalResources.GSoundBuffer("Resources/Audio/AttackCommand/0.wav"));

            backgroundMusic = new Music("Resources/Audio/Music/In Game/mario.wav");
            backgroundMusic.Loop = true;
            backgroundMusic.Volume = Settings.MUSICVOLUME;
            backgroundMusic.Play();
        }
Пример #2
0
        public override void MouseClick(Mouse.Button button, int x, int y)
        {
            bool minimapClick = false;
            Vector2f convertedPos = Program.window.ConvertCoords(new Vector2i(x, y));
            if (x >= MINIMAPPOSX && y >= MINIMAPPOSY && x <= MINIMAPPOSX + MiniMap.SIZEX && y <= MINIMAPPOSY + MiniMap.SIZEY)
            {
                if (miniMap != null)
                {
                    minimapClick = true;
                    var convert = miniMap.ConvertCoordsToView(new Vector2f(x - MINIMAPPOSX, y - MINIMAPPOSY));
                    convertedPos.X = (int)convert.X;
                    convertedPos.Y = (int)convert.Y;
                }
            }
            if (button == Mouse.Button.Left)
            {

                if(uiState == UIStateTypes.SpellCast)
                {
                    allowMinimapCameraMove = false;
                    EntityBase priorEntity = prioritySelectedUnit();
                    if (priorEntity != null)
                        sendSpellCommand(convertedPos.X, convertedPos.Y);
                    uiState = UIStateTypes.Normal;
                }
                else if (!selectedAttackMove)
                {
                    if (!minimapClick)
                    {
                        controlBoxP1 = convertedPos;
                        controlBoxP2 = controlBoxP1;
                        releaseSelect = true;
                    }
                }
                else
                {
                    allowMinimapCameraMove = false;
                    sendMoveCommand(convertedPos.X, convertedPos.Y);
                    selectedAttackMove = false;
                }
            }
            if (button == Mouse.Button.Right)
            {
                EntityBase toUse = null;
                foreach (EntityBase entity in entities.Values)
                {
                    if (entity.GetBounds().Contains(convertedPos.X, convertedPos.Y))
                    {
                        toUse = entity;
                        break;
                    }
                }
                if (toUse != null)
                {
                    sendUseCommand(toUse);
                }
                else
                {
                    sendMoveCommand(convertedPos.X, convertedPos.Y);
                }
                selectedAttackMove = false;
            }
        }
Пример #3
0
        public override void KeyPress(KeyEventArgs keyEvent)
        {
            //Setting Control Groups
            if ((byte) keyEvent.Code >= 27 && (byte) keyEvent.Code <= 35)
            {
                if (keyEvent.Shift)
                {
                    if (selectedUnits != null)
                    {
                        var copy = new List<EntityBase>(controlGroups[keyEvent.Code]);

                        foreach (EntityBase selectedUnit in selectedUnits)
                        {
                            if (copy.Contains(selectedUnit) == false)
                            {
                                controlGroups[keyEvent.Code].Add(selectedUnit);
                            }
                        }
                    }
                }
                else if (keyEvent.Control)
                {
                    if (selectedUnits != null)
                        controlGroups[keyEvent.Code] = new List<EntityBase>(selectedUnits);
                }
                else if (controlGroups.ContainsKey(keyEvent.Code))
                {
                    if (controlGroups[keyEvent.Code].Count > 0)
                        selectedUnits = controlGroups[keyEvent.Code].ToArray();
                }
            }
            else if (keyEvent.Code == standardHotkeys.Hotkeys[0].Key)
            {
                //Attack hotkey was pressed
                selectedAttackMove = true;
            }
            else if(selectedAttackMove == false)
            {
                EntityBase priorEntity = prioritySelectedUnit();
                if (priorEntity == null) return;

                currentHotkeySheet = GetHotkeySheet(priorEntity);

                if (currentHotkeySheet != null)
                {
                    currentHotkey = currentHotkeySheet.ProcessInput(keyEvent.Code);
                    if (currentHotkey != null && currentHotkey.RequiresClick == false)
                    {
                        sendSpellCommand(0, 0);
                    }
                    else if (currentHotkey != null)
                    {
                        uiState = UIStateTypes.SpellCast;
                    }
                }
            }
        }