예제 #1
0
        public override void HandleInput(InputHelper Input, GameTime GameTime)
        {   //pass input to dog and possibly editor
            dog.HandleInput(Input.inputState);
            gameManager.SetBark();
            gameManager.FollowHero(); //make the human follow the dog
            //human.HandleInput(Input.inputState, GameTime); //we could also control the human like so

            titleWidget.HandleInput(Input);
            if (screenManager.game.release == false)
            {
                editor.HandleInput(Input);
                if (Input.IsNewKeyPress(Keys.Enter))
                {
                    editor.playTesting = false;
                }                                                                    //show editor
                //test beating a level, beating the game, losing the game
                if (Input.IsNewKeyPress(Keys.D1))
                {
                    titleWidget.Open(TitleWidget.State.Level1);
                }
                if (Input.IsNewKeyPress(Keys.D2))
                {
                    titleWidget.Open(TitleWidget.State.Level2);
                }
                if (Input.IsNewKeyPress(Keys.D3))
                {
                    titleWidget.Open(TitleWidget.State.Level3);
                }
                if (Input.IsNewKeyPress(Keys.D4))
                {
                    titleWidget.Open(TitleWidget.State.Level4);
                }
                if (Input.IsNewKeyPress(Keys.D5))
                {
                    titleWidget.Open(TitleWidget.State.GameOver);
                }
                if (Input.IsNewKeyPress(Keys.D6))
                {
                    titleWidget.Open(TitleWidget.State.WonGame);
                }
            }
        }
예제 #2
0
        public void HandleInput(InputHelper Input)
        {
            if (playTesting == false) //we are not simulating the game in release mode
            {                         //set the cursor sprite to the cursor pointer frame
                cursorSprite.currentFrame = cursorPointer;
                //match cursor sprite to mouse cursor position
                cursorSprite.position.X = Input.cursorPosition.X + 6;
                cursorSprite.position.Y = Input.cursorPosition.Y + 6;
                //match the top gray rectangle to the viewport's width
                topRec.Width = gameScreen.screenManager.game.GraphicsDevice.Viewport.Width;


                #region Handle button input/update

                for (counter = 0; counter < buttons.Count; counter++)
                {                                                                //loop through all buttons on the buttons list
                    if (buttons[counter].rectangle.Contains(Input.cursorPosition))
                    {                                                            //set the current buttons over state if the cursor collides with it's background rec
                        buttons[counter].drawColor = buttons[counter].overColor; //set the button rec's draw color to overColor

                        if (Input.IsNewMouseButtonPress(MouseButtons.LeftButton))
                        {   //if user clicked on the button, set the buttons rec's draw color to downCOlor
                            buttons[counter].drawColor = buttons[counter].downColor;

                            //check to see which button user clicked on
                            if (buttons[counter] == buttonPlaytest)
                            {
                                playTesting           = true;                                    //hide editor, playTesting can be set false by enter key
                                drawDebug             = false; buttonDrawDebug.selected = false; //set debug and roam false
                                gameScreen.cameraRoam = false; buttonRoam.selected = false;
                            }
                            else if (buttons[counter] == buttonDrawDebug)
                            {   //toggle game.drawDebug true/false
                                if (drawDebug == false)
                                {
                                    drawDebug = true; buttonDrawDebug.selected = true;
                                }
                                else
                                {
                                    drawDebug = false; buttonDrawDebug.selected = false;
                                }
                            }
                            else if (buttons[counter] == buttonNewLevel)
                            {                             //create a new level and time it, cycling through the level difficulties
                                gameScreen.stopWatch.Reset(); gameScreen.stopWatch.Start();
                                gameScreen.levelNumber++; //test level progression
                                if (gameScreen.levelNumber > 4)
                                {
                                    gameScreen.levelNumber = 1;
                                }                                                                //cycle back to level 1
                                gameScreen.levelGenerator.GenerateLevel(gameScreen.levelNumber); //generate a new level
                                gameScreen.stopWatch.Stop(); gameScreen.updateTime = gameScreen.stopWatch.Elapsed;
                                System.Diagnostics.Debug.WriteLine(
                                    "generated " + gameScreen.levelGenerator.difficulty +
                                    " level in: " + gameScreen.updateTime.Milliseconds + "ms");
                            }
                            else if (buttons[counter] == buttonRoam)
                            {   //toggle gamescreen.cameraRoam true/false
                                if (gameScreen.cameraRoam == false)
                                {
                                    gameScreen.cameraRoam = true; buttonRoam.selected = true;
                                }
                                else
                                {
                                    gameScreen.cameraRoam = false; buttonRoam.selected = false;
                                }
                            }
                        }
                    }
                    else
                    {
                        buttons[counter].drawColor = buttons[counter].upColor;
                    }                                                               //set untouched buttons to upcolor
                }

                #endregion


                #region Handle keyboard input

                if (gameScreen.cameraRoam)
                {                                               //if the camera is allowed to roam
                    if (Input.IsKeyDown(Keys.Space))
                    {                                           //allow camera panning via photoshop spacebar slide drag
                        cursorSprite.currentFrame = cursorHand; //switch to open hand
                        if (Input.IsMouseButtonDown(MouseButtons.LeftButton))
                        {
                            cursorSprite.currentFrame = cursorFist;                  //switch to closed hand
                            if (Input.lastCursorPosition.X > Input.cursorPosition.X) //draw horizontally based on cursor movement
                            {
                                gameScreen.camera.targetPosition.X += Math.Abs(Input.lastCursorPosition.X - Input.cursorPosition.X);
                            }
                            else if (Input.lastCursorPosition.X < Input.cursorPosition.X)
                            {
                                gameScreen.camera.targetPosition.X -= Math.Abs(Input.lastCursorPosition.X - Input.cursorPosition.X);
                            }

                            if (Input.lastCursorPosition.Y > Input.cursorPosition.Y) //draw vertically based on cursor movement
                            {
                                gameScreen.camera.targetPosition.Y += Math.Abs(Input.lastCursorPosition.Y - Input.cursorPosition.Y);
                            }
                            else if (Input.lastCursorPosition.Y < Input.cursorPosition.Y)
                            {
                                gameScreen.camera.targetPosition.Y -= Math.Abs(Input.lastCursorPosition.Y - Input.cursorPosition.Y);
                            }
                        }
                    }

                    if (Input.IsKeyDown(Keys.RightControl))
                    {   //photoshop zoom in/out using ctrl+ or ctrl-
                        if (Input.IsNewKeyPress(Keys.OemPlus))
                        {
                            gameScreen.camera.targetZoom = gameScreen.camera.targetZoom * 1.25f;
                        }
                        if (Input.IsNewKeyPress(Keys.OemMinus))
                        {
                            gameScreen.camera.targetZoom = gameScreen.camera.targetZoom * 0.75f;
                        }
                    }
                }

                #endregion
            }
        }