예제 #1
0
 public void PressReset(List <GameEntity> game_elements, ref GameEntityGroup selectedGroup)
 {
 }
예제 #2
0
 public void HoldTranslation(MouseState mouse, ref GameEntityGroup selectedGroup)
 {
 }
예제 #3
0
        private void UpdateInput()
        {
            KeyboardState state = Keyboard.GetState();
            MouseState    mouse = Mouse.GetState();

            // if S is pressed
            if (state.IsKeyDown(Keys.S) & !previousState.IsKeyDown(Keys.S))
            {
                // All the game entities get their old behaviour back
                foreach (GameEntity ge in game_elements)
                {
                    ge.moveBehaviour = ge.oldBehaviour;
                }

                #region Composite Pattern
                // The group is deleted & recreated
                selectedGroup = null;
                selectedGroup = new GameEntityGroup(graphics);
                #endregion
            }



            // Left mouse button pressed.
            if ((mouse.LeftButton == ButtonState.Pressed) & (previousmouseState.LeftButton != ButtonState.Pressed))
            {
                #region Composite Pattern
                if (selectedGroup.ClickInArea(new Vector2(mouse.X, mouse.Y)))
                {
                    #endregion
                    translateMode     = true;
                    translateOffset.X = mouse.X;
                    translateOffset.Y = mouse.Y;
                }
                else
                {
                    selectRectangle.X = mouse.X;
                    selectRectangle.Y = mouse.Y;
                    selectMode        = true;
                }
            }

            // while left mouse button pressed. Update the Width & Height of the selectRectangle
            if ((mouse.LeftButton == ButtonState.Pressed))
            {
                if (translateMode)
                {
                    #region Composite Pattern
                    selectedGroup.Translate(new Vector2(mouse.X - translateOffset.X, mouse.Y - translateOffset.Y));
                    #endregion
                    translateOffset.X = mouse.X;
                    translateOffset.Y = mouse.Y;
                }
                if (selectMode)
                {
                    selectRectangle.Width  = mouse.X - selectRectangle.X;
                    selectRectangle.Height = mouse.Y - selectRectangle.Y;
                }
            }

            // Left mouse button released. End of select mode
            if ((mouse.LeftButton == ButtonState.Released) & (previousmouseState.LeftButton != ButtonState.Released))
            {
                if (translateMode)
                {
                    translateMode = false;
                }
                else if (selectMode)
                {
                    selectMode = false;

                    #region Composite Pattern
                    // A new entity group is created.
                    GameEntityGroup newGroup = new GameEntityGroup(graphics);
                    #endregion
                    // All the game entities that are part of the selected area
                    foreach (GameEntity ge in game_elements)
                    {
                        if ((ge.position.X >= selectRectangle.X) &&
                            (ge.position.X <= (selectRectangle.X + selectRectangle.Width)) &&
                            (ge.position.Y >= selectRectangle.Y) &&
                            (ge.position.Y <= (selectRectangle.Y + selectRectangle.Height)))
                        {
                            ge.moveBehaviour = new NoWalk();

                            #region Composite Pattern
                            // Adding the game entity to a new group. All the game entities in the selection have NoWalk behaviour
                            newGroup.Add(ge);
                            #endregion
                        }
                        if ((ge.position.X <= selectRectangle.X) &&
                            (ge.position.X >= (selectRectangle.X + selectRectangle.Width)) &&
                            (ge.position.Y <= selectRectangle.Y) &&
                            (ge.position.Y >= (selectRectangle.Y + selectRectangle.Height)))
                        {
                            ge.moveBehaviour = new NoWalk();

                            #region Composite Pattern
                            // Adding the game entity to a new group. All the game entities in the selection have NoWalk behaviour
                            newGroup.Add(ge);
                            #endregion
                        }
                    }
                    // Adding the complete group to the composite structure

                    newGroup.Left   = selectRectangle.X;
                    newGroup.Top    = selectRectangle.Y;
                    newGroup.Right  = selectRectangle.X + selectRectangle.Width;
                    newGroup.Bottom = selectRectangle.Y + selectRectangle.Height;

                    // If the selection was from right to left
                    if (newGroup.Left >= newGroup.Right)
                    {
                        int temp = newGroup.Right;
                        newGroup.Right = newGroup.Left;
                        newGroup.Left  = temp;
                    }

                    // If the selection was from bottom to top
                    if (newGroup.Top >= newGroup.Bottom)
                    {
                        int temp = newGroup.Bottom;
                        newGroup.Bottom = newGroup.Top;
                        newGroup.Top    = temp;
                    }

                    #region Composite Pattern
                    selectedGroup.Add(newGroup);
                    #endregion

                    selectRectangle.Width  = 0;
                    selectRectangle.Height = 0;
                }
            }
            // set the old states of the keyboard & mouse
            previousState      = state;
            previousmouseState = mouse;
        }
예제 #4
0
 public void HoldSelection(MouseState mouse, ref GameEntityGroup selectedGroup)
 {
     this.gwStateMachine.selectRectangle.Width  = mouse.X - this.gwStateMachine.selectRectangle.X;
     this.gwStateMachine.selectRectangle.Height = mouse.Y - this.gwStateMachine.selectRectangle.Y;
 }
예제 #5
0
 public void ReleaseSelection(List <GameEntity> game_elements, ref GameEntityGroup selectedGroup)
 {
 }