示例#1
0
        /// <summary>
        /// Initialize the world and set up the game
        /// </summary>
        public void Initialize(string path)
        {
            //Create the controllers
            kinect   = new KinectManager(gameHeight);
            mouse    = new MouseController();
            keyboard = new KeyController();

            //Make sure there is a Kinect connected
            if (!kinect.Initialize())
            {
                Console.WriteLine("No Kinect Sensor Connected!");
                Environment.Exit(0);
            }

            //Load the map and retrieve the dimensions
            map = new Map();
            map.LoadLevel(@"Levels\" + path + ".txt", content);
            gameHeight        = map.GameDimensions[0];
            gameWidth         = map.GameDimensions[1];
            kinect.GameHeight = gameHeight;

            //Create the objects and set up the world
            slingshot           = new SlingShot(content, kinect, gameHeight);
            map.SetSlingShot    = slingshot;
            player              = new Player(kinect, mouse, content, slingshot);
            map.SetPlayer       = player;
            slingshot.PlayerPos = player.GetSprite.GetPosition;
            pointer             = new Pointer(content, kinect, mouse);

            //Create the Pause Button
            font = content.Load <SpriteFont>("pauseFont");
            SpriteFont buttonFont = content.Load <SpriteFont>("buttonFont");
            string     output     = "Play";
            Vector2    textSize   = buttonFont.MeasureString(output);

            unPause      = new Button(new Vector2((screenWidth * 0.5f) - (textSize.X * 0.5f), screenHeight * 0.5f + textSize.Y), output, buttonFont, content, pointer);
            output       = "Return To Menu";
            textSize     = buttonFont.MeasureString(output);
            returnToMenu = new Button(new Vector2((screenWidth * 0.5f) - (textSize.X * 0.5f), unPause.GetSprite.GetPosition.Y + 50), output, buttonFont, content, pointer);

            //Set up the background
            Texture2D bg = content.Load <Texture2D>("Background");

            Background = new Sprite(new Rectangle(0, 0, bg.Width, screenHeight), bg);

            //Set up the designer & menu
            levelDesigner = new Designer(kinect, content, pointer, screenWidth, screenHeight);
            menu          = new Menu(content, pointer, screenWidth, screenHeight, this);


            // Set up all of your camera options
            //Set the bounding rectangle around the whole World
            cam.SetLimits(new Rectangle(0, 0, gameWidth, gameHeight));
            //Set the maximum factor to zoom in by, 3.0 is the default
            cam.SetZoom(1.0f);
            cam.SetMaxZoom(4.0f);
            //Set the starting World position of the camera, The below code sets it to the exact centre of the default screen size
            cam.SetPosition(player.GetSprite.GetPosition);
            //Set the origin of the camera, typically is the starting position of the camera
            cam.SetOrigin(cam.GetPosition());
            //centre the camera on the player
            cam.LookAt(player.GetSprite.GetBounds);

            //If the game is reseting
            if (worldState == States.reset)
            {
                //Start the game
                worldState = States.play;
            }
        }
        protected override void Update(GameTime gameTime)
        {
            gameTimePublic = gameTime;

            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
            {
                Exit();
            }

            penumbra.Transform = playerCam.GetTransformation();

            if (runOnce)
            {
                worlds[0].initialize();

                ToolBelt.Initialize();

                runOnce = false;
            }


            if (kb.IsKeyDown(Keys.Q))
            {
                renderSize += 10;
            }
            else if (kb.IsKeyDown(Keys.E))
            {
                playerCam.SetZoom(3f);
                renderSize = 600;
            }

            Zoom();

            kb    = Keyboard.GetState();
            mouse = Mouse.GetState();

            worlds[0].Update();
            Player.Update();
            ToolBelt.Update();

            playerCam.LookAt(Player.rec);

            // TODO: Add your update logic here

            if (kb.IsKeyDown(Keys.R) && kbPre.IsKeyUp(Keys.R))
            {
                if (penumbra.Visible == false)
                {
                    penumbra.Visible = true;
                }
                else
                {
                    penumbra.Visible = false;
                }
            }

            frames++;
            mousePre = mouse;
            kbPre    = kb;
            base.Update(gameTime);
        }