Beispiel #1
0
        private void OUInput(GameTime gameTime)  //Input handler for overworld.
        {
            KeyboardState newState = Keyboard.GetState();

            bool movingDown = false;

            if (newState.IsKeyDown(Keys.W) || newState.IsKeyDown(Keys.A) || newState.IsKeyDown(Keys.S) || newState.IsKeyDown(Keys.D))
            {
                if (moveCD <= 0)
                {
                    movingDown = true;
                }
                else
                {
                    moveCD -= gameTime.ElapsedGameTime.Milliseconds;
                }
            }
            else
            {
                moveCD = 0;
            }

            if (newState != oldState || movingDown)
            {
                bool    moved = false;
                Vector2 pGP   = new Vector2(player.GridPosition.X / 10, player.GridPosition.Y / 10);

                if (newState.IsKeyDown(Keys.W))
                {
                    pGP.Y -= 1;
                    moveCD = 120;
                    moved  = true;
                }
                else if (newState.IsKeyDown(Keys.A))
                {
                    pGP.X -= 1;
                    moveCD = 120;
                    moved  = true;
                }
                else if (newState.IsKeyDown(Keys.S))
                {
                    pGP.Y += 1;
                    moveCD = 120;
                    moved  = true;
                }
                else if (newState.IsKeyDown(Keys.D))
                {
                    pGP.X += 1;
                    moveCD = 120;
                    moved  = true;
                }

                if (newState.IsKeyDown(Keys.F3))
                {
                    fMode = !fMode;
                }

                if (newState.IsKeyDown(Keys.F2)) //DEBUG ONLY, REMOVE FOR RELEASE.
                {
                    Tiles = level1.map();
                    Vector2 spawn = level1.getSpawn();
                    player.jumpRegardless(level1.getSpawn());
                    player.setExit(level1.getExit());
                    player.respawn();
                    cPos   = new Vector2(spawn.X - (vPort.X / 2), spawn.Y - (vPort.Y / 2) + 1);
                    FoW    = new int[Consts.mapWidth, Consts.mapHeight];
                    score -= 100;
                    if (score < 0)
                    {
                        score = 0;
                    }
                }

                if (newState.IsKeyDown(Keys.R))
                {
                    if (gameOver)
                    {
                        gameOver = false;

                        Tiles = level1.map();

                        Vector2 spawn = level1.getSpawn();
                        player.jumpRegardless(level1.getSpawn());
                        player.setExit(level1.getExit());
                        player.respawn();
                        cPos  = new Vector2(spawn.X - (vPort.X / 2), spawn.Y - (vPort.Y / 2) + 1);
                        FoW   = new int[Consts.mapWidth, Consts.mapHeight];
                        score = 0;
                    }
                }

                if (moved)
                {
                    Vector2 temp = player.GridPosition;
                    player.jump((int)pGP.X, (int)pGP.Y, Tiles[(int)pGP.X, (int)pGP.Y]);
                    cPos -= ((temp - player.GridPosition) / 10);

                    foreach (EnemyBase enemy in enemyList)
                    {
                        if (enemy != null && Tiles[(int)pGP.X, (int)pGP.Y] != 1)
                        {
                            enemy.AddAP(100);
                        }
                    }
                }

                // Update saved state.
                oldState = newState;
            }
        }