public void OnStay(ButtonResponder responder)
 {
     if (state.Equals(ButtonState.Off) || state.Equals(ButtonState.Exit))
     {
         state = ButtonState.Enter;
         responder.EnterTrigger(this);
         responder.StayTrigger(this);
     }
     else
     {
         state = ButtonState.On;
         responder.StayTrigger(this);
     }
 }
Beispiel #2
0
 private void DetectClick(ref GameState gameState, Game1 game)
 {
     currentLeftButtonState = Mouse.GetState().LeftButton;
     if (currentLeftButtonState.Equals(ButtonState.Pressed) && oldLeftButtonState.Equals(ButtonState.Released))
     {
         if (isButtonSelected[0])
         {
             gameState = GameState.NewGame;
         }
         if (isButtonSelected[1])
         {
             game.Exit();
         }
         if (isButtonSelected[2])
         {
             gameState = GameState.Menu;
         }
         if (isButtonSelected[3])
         {
             gameState = GameState.Game;
         }
         if (isButtonSelected[4])
         {
             gameState = GameState.Credits;
         }
     }
     oldLeftButtonState = currentLeftButtonState;
 }
Beispiel #3
0
        public void update(GameTime gameTime)
        {
            MouseState    curMouseState    = Mouse.GetState();
            KeyboardState curKeyboardState = Keyboard.GetState();
            Vector2       mousePos         = new Vector2(curMouseState.X, curMouseState.Y);

            UIElement        curElement = UIManager.The.Root.getElementAt(mousePos);
            ActiveGameObject curObject  = null;

            if (UIManager.The.Root is Frame_Game)
            {
                Frame_Game f = (Frame_Game)UIManager.The.Root;
                curObject = f.getObjectAt(mousePos);
            }

            setHover(curElement, curObject);

            // left click
            if (curMouseState.LeftButton.Equals(ButtonState.Pressed))
            {
                leftClick = ButtonState.Pressed;
            }
            else if (leftClick.Equals(ButtonState.Pressed))
            {
                // Left click detected
                leftClick = ButtonState.Released;

                if (curElement != null)
                {
                    curElement.LeftClickEvent.click(curElement);
                }
                else if (curObject != null)
                {
                    _selected = curObject;
                }
            }

            // right click
            if (curMouseState.RightButton.Equals(ButtonState.Pressed))
            {
                rightClick = ButtonState.Pressed;
            }

            else if (rightClick.Equals(ButtonState.Pressed))
            {
                // Right click detected
                rightClick = ButtonState.Released;
                if (curElement != null)
                {
                    curElement.RightClickEvent.click(curElement);
                }
                else if (curObject != null)
                {
                    if (_selected != null)
                    {
                        //move logic
                    }
                }
            }
        }
Beispiel #4
0
        public void Update()
        {
            //Check the current state of the button
            if (currentButtonState.Equals(ButtonState.Unpressed))
            {
                m_ButtonColor = Color.White;
            }

            else if (currentButtonState.Equals(ButtonState.Hover))
            {
                m_ButtonColor = Color.CornflowerBlue;
            }

            else if (currentButtonState.Equals(ButtonState.Clicked))
            {
                m_ButtonColor = Color.Red;
            }
        }
Beispiel #5
0
        public static void Update(GameTime gameTime)
        {
            updateStates();


            if (leftButtonState.Equals(ButtonState.Released) && lastLeftButtonState.Equals(ButtonState.Pressed))
            {
                //Launch Missile
            }
        }
Beispiel #6
0
        /// <summary>
        /// Method for grabbing a slice of raw input and triggering an event.
        /// </summary>
        /// <param name="gameTime">Current game time.</param>
        public static void update(GameTime gameTime)
        {
            MouseState    curMouseState    = Mouse.GetState();
            KeyboardState curKeyboardState = Keyboard.GetState();

            // mouse moved
            if (curMouseState.X != mouseLastState.X || curMouseState.Y != mouseLastState.Y)
            {
                if (MouseMovedEvent != null)
                {
                    MouseMovedEvent.Invoke(InputManager.The, new MouseEventArgs(curMouseState));
                }
            }

            // left click
            if (curMouseState.LeftButton.Equals(ButtonState.Pressed))
            {
                leftClick = ButtonState.Pressed;
            }
            else if (leftClick.Equals(ButtonState.Pressed))
            {
                // Left click detected
                leftClick = ButtonState.Released;
                if (LeftMouseUpEvent != null)
                {
                    LeftMouseUpEvent.Invoke(InputManager.The, new MouseEventArgs(curMouseState));
                }
            }

            // right click
            if (curMouseState.RightButton.Equals(ButtonState.Pressed))
            {
                rightClick = ButtonState.Pressed;
            }
            else if (rightClick.Equals(ButtonState.Pressed))
            {
                // Right click detected
                rightClick = ButtonState.Released;
                if (RightMouseUpEvent != null)
                {
                    RightMouseUpEvent.Invoke(InputManager.The, new MouseEventArgs(curMouseState));
                }
            }

            // key press
            DetectKeyStroke(curKeyboardState);

            mouseLastState = curMouseState;
        }
        public TouchpadDir getTouchpadDir(Vector2 touchpadPosition, ButtonState touchpadState)
        {
            if (touchpadState.Equals(ButtonState.Inactive))
            {
                return(TouchpadDir.Untouched);
            }
            if (touchpadPosition.magnitude < 0.2f)
            {
                return(TouchpadDir.Center);
            }

            float angle = Mathf.Atan2(touchpadPosition.y, touchpadPosition.x);

            angle *= Mathf.Rad2Deg;
            angle += 45f;
            angle %= 360f;
            while (angle < 0)
            {
                angle += 360f;
            }
            if (angle > 0f && angle <= 90f)
            {
                return(TouchpadDir.Right);
            }
            if (angle > 90f && angle <= 180f)
            {
                return(TouchpadDir.Up);
            }
            if (angle > 180f && angle <= 270f)
            {
                return(TouchpadDir.Left);
            }
            if (angle > 270f)
            {
                return(TouchpadDir.Down);
            }

            return(TouchpadDir.Center);
        }
Beispiel #8
0
        /*
         * Handles all user input to the game, depending on the keyboard/mouse states and the screen's state.
         */
        public void update(GameTime time)
        {
            KeyboardState kbs = Keyboard.GetState();
            Vector2 destination;

            /* Normal gameplay (player has control of character's movement*/
            if (screenManager.getActiveScreen().getName() == "Normal")
            {
                if (kbs.IsKeyDown(Keys.Escape))
                {
                    game.Exit();
                }
                else if (kbs.IsKeyDown(Keys.W))
                {
                    Console.WriteLine("player: " + player.getLocation().ToString());
                    player.setDirection(Direction.NORTH);
                    destination = new Vector2(player.getLocation().X, player.getLocation().Y - stepSize);
                    if (player.getLocation().Y + stepSize > 0 && collisionManager.isValid(destination, player))
                    {
                        player.deriveY(-stepSize);
                    }
                    else
                    {
                        Console.WriteLine("u wanna go north? nty");
                    }
                }
                else if (kbs.IsKeyDown(Keys.S))
                {
                    Console.WriteLine("player: " + player.getLocation().ToString());
                    player.setDirection(Direction.SOUTH);
                    destination = new Vector2(player.getLocation().X, player.getLocation().Y + stepSize);
                    if (player.getLocation().Y + stepSize < midY * 2 && collisionManager.isValid(destination, player))
                    {
                        player.deriveY(stepSize);
                    }
                    else
                    {
                        Console.WriteLine("u wanna go south? nty");
                    }
                }
                else if (kbs.IsKeyDown(Keys.A))
                {
                    Console.WriteLine("player: " + player.getLocation().ToString());
                    player.setDirection(Direction.WEST);
                    destination = new Vector2(player.getLocation().X - stepSize, player.getLocation().Y);
                    if (player.getLocation().X + stepSize > 0 && collisionManager.isValid(destination, player))
                    {
                        player.deriveX(-stepSize);
                    }
                    else
                    {
                        Console.WriteLine("u wanna go west? nty");
                    }
                }
                else if (kbs.IsKeyDown(Keys.D))
                {
                    Console.WriteLine("player: " + player.getLocation().ToString());
                    player.setDirection(Direction.EAST);
                    destination = new Vector2(player.getLocation().X + stepSize, player.getLocation().Y);
                    if (player.getLocation().X + stepSize < midX * 2 && collisionManager.isValid(destination, player))
                    {
                        player.deriveX(stepSize);
                    }
                    else
                    {
                        Console.WriteLine("u wanna go east? nty");
                    }
                }
                if (kbs.IsKeyDown(Keys.Space))
                {
                    double totalMilliseconds = time.TotalGameTime.TotalMilliseconds;
                    if (player.getLastFired() == -1 || totalMilliseconds - player.getLastFired() >= player.getProjectile().getCooldown())
                    {
                        level.addProjectile(player.createProjectile(totalMilliseconds));
                    }
                    /*foreach (Entity e in level.getNpcs()) {
                        if (e != null) {
                            npc.deriveHealth(-50);
                            // handle projectile interaction with npcs
                            // if hit, derive npc health by -1 * skilltree power
                            Console.WriteLine("Health: " + npc.getHealth());
                        }
                    }*/
                }
                else if (kbs.IsKeyDown(Keys.X))
                {
                    //switch to telekinesis-select mode (player clicks a liftable object to select it)
                    screenManager.setActiveScreen(2);
                    Console.WriteLine("Entered telekinesis mode!");
                }
            }

            /* Just entered telekinesis mode (player uses mouse to select a liftable object)*/
            else if (screenManager.getActiveScreen().getName() == "Telekinesis-Select")
            {
                lastState = state;
                state = Mouse.GetState().LeftButton;
                if (lastState.Equals(ButtonState.Pressed) && state.Equals(ButtonState.Released))
                {
                    foreach (GameObject obj in level.getObjects())
                    {
                        if (obj != null && obj.isLiftable())
                        {
                            Point p = new Point(Mouse.GetState().X, Mouse.GetState().Y);
                            if (p != null && obj.getBounds().Contains(p))
                            {
                                //select object
                                obj.setSelected(true);
                                selectedObject = obj;
                                //switch screen state to telekinesis-move (control over selected object)
                                screenManager.setActiveScreen(3);
                                Console.WriteLine("obj contains mouse!");
                            }
                        }
                    }
                    Console.WriteLine("Mouse pressed");
                }
                else if (kbs.IsKeyDown(Keys.X))
                {
                    //switch to telekinesis-select mode (player clicks a liftable object to select it)
                    screenManager.setActiveScreen(1);
                    Console.WriteLine("Entered telekinesis mode!");
                }
            }

            /* Telekinetic lifting mode (player controls the selected object's movement)*/
            else if (screenManager.getActiveScreen().getName() == "Telekinesis-Move")
            {
                if (kbs.IsKeyDown(Keys.Escape))
                {
                    game.Exit();
                }
                else if (kbs.IsKeyDown(Keys.W))
                {
                    Console.WriteLine("selectedObject: " + selectedObject.getLocation().ToString());
                    selectedObject.setDirection(Direction.NORTH);
                    //destination = new Vector2(selectedObject.getLocation().X, selectedObject.getLocation().Y + stepSize);
                    if (selectedObject.getLocation().Y + stepSize > 0/* && collisionManager.isValid(destination)*/)
                    {
                        selectedObject.deriveY(-stepSize);
                    }
                    else
                    {
                        Console.WriteLine("u wanna go north? nty");
                    }
                }
                else if (kbs.IsKeyDown(Keys.S))
                {
                    Console.WriteLine("selectedObject: " + selectedObject.getLocation().ToString());
                    selectedObject.setDirection(Direction.SOUTH);
                    //destination = new Vector2(selectedObject.getLocation().X, selectedObject.getLocation().Y - stepSize);
                    if (selectedObject.getLocation().Y - stepSize < midY * 2/* && collisionManager.isValid(destination)*/)
                    {
                        selectedObject.deriveY(stepSize);
                    }
                    else
                    {
                        Console.WriteLine("u wanna go south? nty");
                    }
                }
                else if (kbs.IsKeyDown(Keys.A))
                {
                    Console.WriteLine("selectedObject: " + selectedObject.getLocation().ToString());
                    selectedObject.setDirection(Direction.WEST);
                    //destination = new Vector2(selectedObject.getLocation().X + stepSize, selectedObject.getLocation().Y);
                    if (selectedObject.getLocation().X + stepSize > 0/* && collisionManager.isValid(destination)*/)
                    {
                        selectedObject.deriveX(-stepSize);
                    }
                    else
                    {
                        Console.WriteLine("u wanna go west? nty");
                    }
                }
                else if (kbs.IsKeyDown(Keys.D))
                {
                    Console.WriteLine("selectedObject: " + selectedObject.getLocation().ToString());
                    selectedObject.setDirection(Direction.EAST);
                    //destination = new Vector2(selectedObject.getLocation().X - stepSize, selectedObject.getLocation().Y);
                    //Console.WriteLine("dest: " + destination.ToString());
                    if (selectedObject.getLocation().X - stepSize < midX * 2/* && collisionManager.isValid(destination)*/)
                    {
                        selectedObject.deriveX(stepSize);
                    }
                    else
                    {
                        Console.WriteLine("u wanna go east? nty");
                    }
                }
                if (kbs.IsKeyDown(Keys.Space))
                {

                }
                else if (kbs.IsKeyDown(Keys.X))
                {
                    //deselect object
                    selectedObject.setSelected(false);
                    selectedObject = null;
                    //switch back to normal screen state (control over character)
                    screenManager.setActiveScreen(1);
                    Console.WriteLine("Exited telekinesis mode.");
                }
            }
        }
Beispiel #9
0
        public virtual void OnRendererTabPageItem(Graphics gfx, Rectangle tabPageItemRct, string tabPageText, int index, ButtonState btnState)
        {
            Rectangle itemRct = tabPageItemRct;

            using (StringFormat format = new StringFormat(StringFormatFlags.LineLimit))
            {
                format.Alignment = StringAlignment.Center;
                format.LineAlignment = StringAlignment.Center;
                format.HotkeyPrefix = System.Drawing.Text.HotkeyPrefix.Show;

                //背景色
                Color backColor = Color.Empty;

                //边框颜色
                Color borderColor = Color.Empty;

                //前景色
                Color foreColor = Color.Empty;

                //图标
                Image image = null;

                //边框宽度
                int borderWidth = 0;

                if (btnState.Equals(ButtonState.Hover))
                {
                    //设置背景色,如果没有指定悬浮背景色,则使用正常选项卡的
                    if (TabControl.TabItemHoverBackColor != null && !TabControl.TabItemHoverBackColor.Equals(Color.Empty))
                        backColor = TabControl.TabItemHoverBackColor;
                    else if (TabControl.TabItemBackColor != null && !TabControl.TabItemBackColor.Equals(Color.Empty))
                        backColor = TabControl.TabItemBackColor;

                    //设置图标,如果没有指定悬浮图标,则使用正常选项卡的
                    if (TabControl.TabItemStyle.Equals(TabItemStyle.Image) || TabControl.TabItemStyle.Equals(TabItemStyle.TextAndImage))
                    {
                        NeoTabPage page = TabControl.TabPages[index] as NeoTabPage;

                        if (page != null)
                        {
                            if (page.TabHoverImage != null)
                                image = page.TabHoverImage;
                            else if (page.TabImage != null)
                                image = page.TabImage;
                        }
                    }

                    //设置边框样式,如果没有指定悬浮样式,则使用正常选项卡的
                    if (TabControl.TabItemHoverBorderStyle != null)
                    {
                        if (!TabControl.TabItemHoverBorderStyle.Color.Equals(Color.Empty))
                            borderColor = TabControl.TabItemHoverBorderStyle.Color;

                        borderWidth = TabControl.TabItemHoverBorderStyle.Width;
                    }
                    else if (TabControl.TabItemBorderStyle != null)
                    {
                        if (!TabControl.TabItemBorderStyle.Color.Equals(Color.Empty))
                            borderColor = TabControl.TabItemBorderStyle.Color;

                        borderWidth = TabControl.TabItemBorderStyle.Width;
                    }

                    //设置前景色,如果没有指定悬浮前景色,则使用正常选项卡的
                    if (TabControl.TabItemHoverForeColor != null && !TabControl.TabItemHoverForeColor.Equals(Color.Empty))
                        foreColor = TabControl.TabItemHoverForeColor;
                    else if (TabControl.TabItemForeColor != null && !TabControl.TabItemForeColor.Equals(Color.Empty))
                        foreColor = TabControl.TabItemForeColor;

                    DrawTabItem(gfx, itemRct, tabPageText, backColor, borderColor, borderWidth, foreColor, image, format);
                }
                else if (btnState.Equals(ButtonState.Normal))
                {
                    //设置背景色
                    if (TabControl.TabItemBackColor != null && !TabControl.TabItemBackColor.Equals(Color.Empty))
                        backColor = TabControl.TabItemBackColor;

                    //设置图标,如果没有指定悬浮图标,则使用正常选项卡的
                    if (TabControl.TabItemStyle.Equals(TabItemStyle.Image) || TabControl.TabItemStyle.Equals(TabItemStyle.TextAndImage))
                    {
                        NeoTabPage page = TabControl.TabPages[index] as NeoTabPage;

                        if (page != null && page.TabImage != null)
                        {
                            image = page.TabImage;
                        }
                    }

                    //设置边框样式
                    if (TabControl.TabItemBorderStyle != null)
                    {
                        if (!TabControl.TabItemBorderStyle.Color.Equals(Color.Empty))
                            borderColor = TabControl.TabItemBorderStyle.Color;

                        borderWidth = TabControl.TabItemBorderStyle.Width;
                    }

                    //设置前景色,如果没有指定悬浮前景色,则使用正常选项卡的
                    if (TabControl.TabItemForeColor != null && !TabControl.TabItemForeColor.Equals(Color.Empty))
                        foreColor = TabControl.TabItemForeColor;

                    DrawTabItem(gfx, itemRct, tabPageText, backColor, borderColor, borderWidth, foreColor, image, format);
                }
                else if (btnState.Equals(ButtonState.Pressed))
                {
                    //设置背景色,如果没有指定活动选项卡背景色,则使用正常选项卡的
                    if (TabControl.TabItemActiveBackColor != null && !TabControl.TabItemActiveBackColor.Equals(Color.Empty))
                        backColor = TabControl.TabItemActiveBackColor;
                    else if (TabControl.TabItemBackColor != null && !TabControl.TabItemBackColor.Equals(Color.Empty))
                        backColor = TabControl.TabItemBackColor;

                    //设置图标,如果没有指定悬浮图标,则使用正常选项卡的
                    if (TabControl.TabItemStyle.Equals(TabItemStyle.Image) || TabControl.TabItemStyle.Equals(TabItemStyle.TextAndImage))
                    {
                        NeoTabPage page = TabControl.TabPages[index] as NeoTabPage;

                        if (page != null)
                        {
                            if (page.TabActiveImage != null)
                                image = page.TabActiveImage;
                            else if (page.TabImage != null)
                                image = page.TabImage;
                        }
                    }

                    //设置边框样式,如果没有指定悬浮样式,则使用正常选项卡的
                    if (TabControl.TabItemActiveBorderStyle != null)
                    {
                        if (!TabControl.TabItemActiveBorderStyle.Color.Equals(Color.Empty))
                            borderColor = TabControl.TabItemActiveBorderStyle.Color;

                        borderWidth = TabControl.TabItemActiveBorderStyle.Width;
                    }
                    else if (TabControl.TabItemBorderStyle != null)
                    {
                        if (!TabControl.TabItemBorderStyle.Color.Equals(Color.Empty))
                            borderColor = TabControl.TabItemBorderStyle.Color;

                        borderWidth = TabControl.TabItemBorderStyle.Width;
                    }

                    //设置前景色,如果没有指定悬浮前景色,则使用正常选项卡的
                    if (TabControl.TabItemActiveForeColor != null && !TabControl.TabItemActiveForeColor.Equals(Color.Empty))
                        foreColor = TabControl.TabItemActiveForeColor;
                    else if (TabControl.TabItemForeColor != null && !TabControl.TabItemForeColor.Equals(Color.Empty))
                        foreColor = TabControl.TabItemForeColor;

                    DrawTabItem(gfx, itemRct, tabPageText, backColor, borderColor, borderWidth, foreColor, image, format);
                }
                else if (btnState.Equals(ButtonState.Disabled))
                {
                    //设置背景色,如果没有指定悬浮背景色,则使用正常选项卡的
                    if (TabControl.TabItemDisabledBackColor != null && !TabControl.TabItemDisabledBackColor.Equals(Color.Empty))
                        backColor = TabControl.TabItemDisabledBackColor;
                    else if (TabControl.TabItemBackColor != null && !TabControl.TabItemBackColor.Equals(Color.Empty))
                        backColor = TabControl.TabItemBackColor;

                    //设置图标,如果没有指定悬浮图标,则使用正常选项卡的
                    if (TabControl.TabItemStyle.Equals(TabItemStyle.Image) || TabControl.TabItemStyle.Equals(TabItemStyle.TextAndImage))
                    {
                        NeoTabPage page = TabControl.TabPages[index] as NeoTabPage;

                        if (page != null)
                        {
                            if (page.TabDistabledImage != null)
                                image = page.TabDistabledImage;
                            else if (page.TabImage != null)
                                image = page.TabImage;
                        }
                    }

                    //设置边框样式,如果没有指定悬浮样式,则使用正常选项卡的
                    if (TabControl.TabItemDisabledBorderStyle != null)
                    {
                        if (!TabControl.TabItemDisabledBorderStyle.Color.Equals(Color.Empty))
                            borderColor = TabControl.TabItemDisabledBorderStyle.Color;

                        borderWidth = TabControl.TabItemDisabledBorderStyle.Width;
                    }
                    else if (TabControl.TabItemBorderStyle != null)
                    {
                        if (!TabControl.TabItemBorderStyle.Color.Equals(Color.Empty))
                            borderColor = TabControl.TabItemBorderStyle.Color;

                        borderWidth = TabControl.TabItemBorderStyle.Width;
                    }

                    //设置前景色,如果没有指定悬浮前景色,则使用正常选项卡的
                    if (TabControl.TabItemDisabledForeColor != null && !TabControl.TabItemDisabledForeColor.Equals(Color.Empty))
                        foreColor = TabControl.TabItemDisabledForeColor;
                    else if (TabControl.TabItemForeColor != null && !TabControl.TabItemForeColor.Equals(Color.Empty))
                        foreColor = TabControl.TabItemForeColor;

                    DrawTabItem(gfx, itemRct, tabPageText, backColor, borderColor, borderWidth, foreColor, image, format);
                }
            }
        }
Beispiel #10
0
        protected void UpdateMouse()
        {
            MouseState current_mouse = Mouse.GetState();

            // The mouse x and y positions are returned relative to the
            // upper-left corner of the game window.
            mouseX = current_mouse.X;
            mouseY = current_mouse.Y;

            int x = mouseX / 64, y = mouseY / 64;

            bool mouseOutOfBounds = false;

            if ((x > 7 || x < 0 || y > 7 || y < 0) && activePiece != 0 && activePiece != 99)
            {
                mouseOutOfBounds = true;
                Board[origX, origY] = activePiece;
                activePiece = 0;
                x = 0; y = 0;
            }
            else if (x > 7 || x < 0 || y > 7 || y < 0)
            {
                x = 0; y = 0;
            }

            LastMouseState = CurrentMouseState;
            CurrentMouseState = current_mouse.LeftButton;

            //OnClick
            if (current_mouse.LeftButton.Equals(ButtonState.Pressed) && LastMouseState.Equals(ButtonState.Released) && !mouseOutOfBounds)
            {
                if (Board[x, y] == turn || Board[x,y] == 2*turn)
                {
                    activePiece = Board[x, y];
                    origX = x; origY = y;
                    Board[x, y] = 0;
                }
            }

            //OnRelease
            if (current_mouse.LeftButton.Equals(ButtonState.Released) && LastMouseState.Equals(ButtonState.Pressed) && !mouseOutOfBounds)
            {
                if (isLegalMove(origX, origY, x, y, activePiece))
                {
                    Move(x, y);
                    if (!multiJump)
                        turn = -turn;
                }
                else if (activePiece != 0 && activePiece != 99)
                    Board[origX, origY] = activePiece;
                activePiece = 0;
            }
        }
Beispiel #11
0
        /*
         * Handles all user input to the game, depending on the keyboard/mouse states and the screen's state.
         */
        public void update(GameTime time)
        {
            KeyboardState kbs = Keyboard.GetState();
            Vector2       destination;

            /* Normal gameplay (player has control of character's movement*/
            if (screenManager.getActiveScreen().getName() == "Normal")
            {
                if (kbs.IsKeyDown(Keys.Escape))
                {
                    game.Exit();
                }
                else if (kbs.IsKeyDown(Keys.W))
                {
                    Console.WriteLine("player: " + player.getLocation().ToString());
                    player.setDirection(Direction.NORTH);
                    destination = new Vector2(player.getLocation().X, player.getLocation().Y - stepSize);
                    if (player.getLocation().Y + stepSize > 0 && collisionManager.isValid(destination, player))
                    {
                        player.deriveY(-stepSize);
                    }
                    else
                    {
                        Console.WriteLine("u wanna go north? nty");
                    }
                }
                else if (kbs.IsKeyDown(Keys.S))
                {
                    Console.WriteLine("player: " + player.getLocation().ToString());
                    player.setDirection(Direction.SOUTH);
                    destination = new Vector2(player.getLocation().X, player.getLocation().Y + stepSize);
                    if (player.getLocation().Y + stepSize < midY * 2 && collisionManager.isValid(destination, player))
                    {
                        player.deriveY(stepSize);
                    }
                    else
                    {
                        Console.WriteLine("u wanna go south? nty");
                    }
                }
                else if (kbs.IsKeyDown(Keys.A))
                {
                    Console.WriteLine("player: " + player.getLocation().ToString());
                    player.setDirection(Direction.WEST);
                    destination = new Vector2(player.getLocation().X - stepSize, player.getLocation().Y);
                    if (player.getLocation().X + stepSize > 0 && collisionManager.isValid(destination, player))
                    {
                        player.deriveX(-stepSize);
                    }
                    else
                    {
                        Console.WriteLine("u wanna go west? nty");
                    }
                }
                else if (kbs.IsKeyDown(Keys.D))
                {
                    Console.WriteLine("player: " + player.getLocation().ToString());
                    player.setDirection(Direction.EAST);
                    destination = new Vector2(player.getLocation().X + stepSize, player.getLocation().Y);
                    if (player.getLocation().X + stepSize < midX * 2 && collisionManager.isValid(destination, player))
                    {
                        player.deriveX(stepSize);
                    }
                    else
                    {
                        Console.WriteLine("u wanna go east? nty");
                    }
                }
                if (kbs.IsKeyDown(Keys.Space))
                {
                    double totalMilliseconds = time.TotalGameTime.TotalMilliseconds;
                    if (player.getLastFired() == -1 || totalMilliseconds - player.getLastFired() >= player.getProjectile().getCooldown())
                    {
                        level.addProjectile(player.createProjectile(totalMilliseconds));
                    }

                    /*foreach (Entity e in level.getNpcs()) {
                     *  if (e != null) {
                     *      npc.deriveHealth(-50);
                     *      // handle projectile interaction with npcs
                     *      // if hit, derive npc health by -1 * skilltree power
                     *      Console.WriteLine("Health: " + npc.getHealth());
                     *  }
                     * }*/
                }
                else if (kbs.IsKeyDown(Keys.X))
                {
                    //switch to telekinesis-select mode (player clicks a liftable object to select it)
                    screenManager.setActiveScreen(2);
                    Console.WriteLine("Entered telekinesis mode!");
                }
            }

            /* Just entered telekinesis mode (player uses mouse to select a liftable object)*/
            else if (screenManager.getActiveScreen().getName() == "Telekinesis-Select")
            {
                lastState = state;
                state     = Mouse.GetState().LeftButton;
                if (lastState.Equals(ButtonState.Pressed) && state.Equals(ButtonState.Released))
                {
                    foreach (GameObject obj in level.getObjects())
                    {
                        if (obj != null && obj.isLiftable())
                        {
                            Point p = new Point(Mouse.GetState().X, Mouse.GetState().Y);
                            if (p != null && obj.getBounds().Contains(p))
                            {
                                //select object
                                obj.setSelected(true);
                                selectedObject = obj;
                                //switch screen state to telekinesis-move (control over selected object)
                                screenManager.setActiveScreen(3);
                                Console.WriteLine("obj contains mouse!");
                            }
                        }
                    }
                    Console.WriteLine("Mouse pressed");
                }
                else if (kbs.IsKeyDown(Keys.X))
                {
                    //switch to telekinesis-select mode (player clicks a liftable object to select it)
                    screenManager.setActiveScreen(1);
                    Console.WriteLine("Entered telekinesis mode!");
                }
            }

            /* Telekinetic lifting mode (player controls the selected object's movement)*/
            else if (screenManager.getActiveScreen().getName() == "Telekinesis-Move")
            {
                if (kbs.IsKeyDown(Keys.Escape))
                {
                    game.Exit();
                }
                else if (kbs.IsKeyDown(Keys.W))
                {
                    Console.WriteLine("selectedObject: " + selectedObject.getLocation().ToString());
                    selectedObject.setDirection(Direction.NORTH);
                    //destination = new Vector2(selectedObject.getLocation().X, selectedObject.getLocation().Y + stepSize);
                    if (selectedObject.getLocation().Y + stepSize > 0 /* && collisionManager.isValid(destination)*/)
                    {
                        selectedObject.deriveY(-stepSize);
                    }
                    else
                    {
                        Console.WriteLine("u wanna go north? nty");
                    }
                }
                else if (kbs.IsKeyDown(Keys.S))
                {
                    Console.WriteLine("selectedObject: " + selectedObject.getLocation().ToString());
                    selectedObject.setDirection(Direction.SOUTH);
                    //destination = new Vector2(selectedObject.getLocation().X, selectedObject.getLocation().Y - stepSize);
                    if (selectedObject.getLocation().Y - stepSize < midY * 2 /* && collisionManager.isValid(destination)*/)
                    {
                        selectedObject.deriveY(stepSize);
                    }
                    else
                    {
                        Console.WriteLine("u wanna go south? nty");
                    }
                }
                else if (kbs.IsKeyDown(Keys.A))
                {
                    Console.WriteLine("selectedObject: " + selectedObject.getLocation().ToString());
                    selectedObject.setDirection(Direction.WEST);
                    //destination = new Vector2(selectedObject.getLocation().X + stepSize, selectedObject.getLocation().Y);
                    if (selectedObject.getLocation().X + stepSize > 0 /* && collisionManager.isValid(destination)*/)
                    {
                        selectedObject.deriveX(-stepSize);
                    }
                    else
                    {
                        Console.WriteLine("u wanna go west? nty");
                    }
                }
                else if (kbs.IsKeyDown(Keys.D))
                {
                    Console.WriteLine("selectedObject: " + selectedObject.getLocation().ToString());
                    selectedObject.setDirection(Direction.EAST);
                    //destination = new Vector2(selectedObject.getLocation().X - stepSize, selectedObject.getLocation().Y);
                    //Console.WriteLine("dest: " + destination.ToString());
                    if (selectedObject.getLocation().X - stepSize < midX * 2 /* && collisionManager.isValid(destination)*/)
                    {
                        selectedObject.deriveX(stepSize);
                    }
                    else
                    {
                        Console.WriteLine("u wanna go east? nty");
                    }
                }
                if (kbs.IsKeyDown(Keys.Space))
                {
                }
                else if (kbs.IsKeyDown(Keys.X))
                {
                    //deselect object
                    selectedObject.setSelected(false);
                    selectedObject = null;
                    //switch back to normal screen state (control over character)
                    screenManager.setActiveScreen(1);
                    Console.WriteLine("Exited telekinesis mode.");
                }
            }
        }
Beispiel #12
0
        private void DetectKeypad(ref GameState gameState, Game1 game)
        {
            currentLeftButtonState = Mouse.GetState().LeftButton;
            if (currentLeftButtonState.Equals(ButtonState.Pressed) && oldLeftButtonState.Equals(ButtonState.Released))
            {
                int x         = Mouse.GetState().X;
                int y         = Mouse.GetState().Y;
                int selection = -1;
                for (int i = 0; i < 4; ++i)
                {
                    for (int j = 0; j < 3; ++j)
                    {
                        int bordX = keypadFrame.Left + (int)(10.0 / 240.0 * keypadFrame.Width) + j * (int)(80.0 / 240.0 * keypadFrame.Width);
                        int bordY = keypadFrame.Bottom - (int)(10.0 / 240.0 * keypadFrame.Width) - (3 - i) * (int)(80.0 / 240.0 * keypadFrame.Width);
                        if (x >= bordX && x < bordX + (int)(60.0 / 240.0 * keypadFrame.Width) &&
                            y >= bordY - (int)(60.0 / 240.0 * keypadFrame.Width) && y < bordY)
                        {
                            selection = 3 * i + j;
                            break;
                        }
                    }
                    if (selection > -1)
                    {
                        break;
                    }
                }
                if (selection > -1)
                {
                    switch (selection)
                    {
                    case 0: keypad.Passcode = keypad.Passcode + '1'; break;

                    case 1: keypad.Passcode = keypad.Passcode + '2'; break;

                    case 2: keypad.Passcode = keypad.Passcode + '3'; break;

                    case 3: keypad.Passcode = keypad.Passcode + '4'; break;

                    case 4: keypad.Passcode = keypad.Passcode + '5'; break;

                    case 5: keypad.Passcode = keypad.Passcode + '6'; break;

                    case 6: keypad.Passcode = keypad.Passcode + '7'; break;

                    case 7: keypad.Passcode = keypad.Passcode + '8'; break;

                    case 8: keypad.Passcode = keypad.Passcode + '9'; break;

                    case 9: keypad.Passcode = ""; break;

                    case 10: keypad.Passcode = keypad.Passcode + '0'; break;

                    case 11:
                    {
                        if (keypad.Check())
                        {
                            isSelectingKeypad = false;
                            gameState         = GameState.Game;
                        }
                        else
                        {
                            keypad.Passcode = "";
                        }
                        break;
                    }
                    }
                    if (keypad.Passcode.Length > 4)
                    {
                        keypad.Passcode = keypad.Passcode.Substring(0, 4);
                    }
                }
            }
            oldLeftButtonState = currentLeftButtonState;
        }