예제 #1
0
 public DynamicMap(IServiceProvider serviceProvider, Camera2D camera, GraphicsDevice gd)
 {
     this.content = new ContentManager(serviceProvider, "Content");
     this.levelFactory = new LevelFactory(serviceProvider, this,gd);
     this.player = new Player(Content, new Vector2(), this);
     this.camera = new TrackingDirector(camera, Player);
     this.existingLevels = new Dictionary<string, Level>();
 }
예제 #2
0
        /// <summary>
        /// Update the Player state, the tracking camera, and the currently active level.
        /// </summary>
        /// <param name="gameTime">The current time step of the game.</param>
        /// <param name="keyboardState">The current state of the PC keyboard.</param>
        /// <param name="gamePadState"></param>
        /// <param name="touchState"></param>
        /// <param name="accelState"></param>
        /// <param name="orientation"></param>
        public void Update(GameTime gameTime, 
            KeyboardState keyboardState,
            GamePadState gamePadState,
            TouchCollection touchState,
            AccelerometerState accelState,
            DisplayOrientation orientation,
            InputManager inputManager)
        {
            //Update the Player
            if (!Player.IsAlive && !deathPan)
            {
                // Still want to perform physics on the player.
                Player.ApplyPhysics(gameTime);

                //TODO: Pan the camera to the active spawn
                //if(keyboardState.IsKeyDown(Keys.R))
                //Player.Reset(activeLevel.ActiveSpawn.Position);
                camera = new PanningDirector(camera.Camera, activeLevel.ActiveSpawn, 0.75f);
                deathPan = true;
            }
            else
            {
                Player.Update(gameTime, keyboardState, gamePadState, touchState, accelState, orientation, inputManager);

                if (!Player.IsAlive)
                {
                    activeLevel.ActiveSpawn.Spawn();
                }
            }

            // Update the camera
            if (camera is PanningDirector)
            {
                PanningDirector panningDirector = (PanningDirector)camera;
                if (panningDirector.Completed)
                {
                    camera = new TrackingDirector(panningDirector.Camera, player);
                }
                else if(deathPan && panningDirector.Returning)
                    {
                        Player.Reset(activeLevel.ActiveSpawn.Position - new Vector2(2, 0));
                        camera = new TrackingDirector(panningDirector.Camera, player);
                        deathPan = false;
                    }
            }
            camera.update(gameTime);

            //Update the current level
            activeLevel.Update(Player, gameTime, keyboardState, inputManager);
        }