Exemple #1
0
        public static void CheckKeys()
        {
            if (!NeedUpdate())
            {
                return;
            }

            KeyboardState state = Keyboard.GetState();

            Game         game   = Game.instance;
            EntityPlayer player = game.localPlayer;

            if (state.IsKeyDown(EXIT))
            {
                game.Exit();
            }

            if (state.IsKeyDown(FULLSCREEN))
            {
                game.WindowState =
                    game.WindowState == WindowState.Fullscreen ? WindowState.Normal : WindowState.Fullscreen;
            }

            if (state.IsKeyDown(LEVEL_ONE))
            {
                game.ChangeLevel(ContentManager.GetLevel("main"));
            }

            if (state.IsKeyDown(LEVEL_TWO))
            {
                game.ChangeLevel(ContentManager.GetLevel("two"));
            }

            int speed = game.localPlayer.speed;


            if (state.IsKeyDown(UP))
            {
                player.direction = Direction.UP;

                if (!player.CollidesSolid(player.x, player.y - speed))
                {
                    player.y -= speed;
                }
            }

            if (state.IsKeyDown(DOWN))
            {
                player.direction = Direction.DOWN;
                if (!player.CollidesSolid(player.x, player.y + speed))
                {
                    player.y += speed;
                }
            }

            if (state.IsKeyDown(LEFT))
            {
                player.direction = Direction.LEFT;

                if (!player.CollidesSolid(player.x - speed, player.y))
                {
                    player.x -= speed;
                }
            }

            if (state.IsKeyDown(RIGHT))
            {
                player.direction = Direction.RIGHT;
                if (!player.CollidesSolid(player.x + speed, player.y))
                {
                    player.x += speed;
                }
            }

            if (state.IsKeyDown(DEBUG))
            {
                Console.WriteLine("===Begin debug message===");
                foreach (LevelObject lo in Game.instance.level.GetObjectsAt(player.x, player.y, null))
                {
                    Console.WriteLine(lo.objectName);
                }
                Console.WriteLine("=== End  debug message===");
            }
        }