예제 #1
0
        /// <summary>
        /// Load graphics content for the game.
        /// </summary>
        public override void LoadContent()
        {
            if (content == null)
            {
                content = new ContentManager(ScreenManager.Game.Services, "Content");
            }
            //Add game cam
            cam = new Camera(ScreenManager.GraphicsDevice.Viewport);
            ScreenManager.Game.Services.AddService(typeof(Camera), cam);

            //ScreenManager.DeserializeState();
            collisionMananger = new CollisionManager(ScreenManager.Game);

            // Adds collision manager to Game.Service, This Service unloads when UnloadContent is called.
            ScreenManager.Game.Services.AddService(typeof(ICollisionService), collisionMananger);

            spriteBatch = ScreenManager.SpriteBatch;
            mapDisaplayDevice = new XnaDisplayDevice(this.content, ScreenManager.GraphicsDevice);
            map = content.Load<Map>(_mapLevelName);
            map.LoadTileSheets(mapDisaplayDevice);

            _collisionLayers = new CollisionLayers(ScreenManager.Game, map);

            _gameObjectLayerManager = new GameObjectLayersManager(ScreenManager.Game, map, cam);
            gameObjects.AddRange(_gameObjectLayerManager.GameObjects);

            soundManager = new Sound(ScreenManager.Game);
            ScreenManager.Game.Services.AddService(typeof(ISound), soundManager);
            soundManager.LoadContent();
            soundManager.PlayMusic("main");

            //Adds GUI buttons
            gamePlayButtons = new GamePlayButtons(ScreenManager.Game);

            //Add players
            playerManager = new PlayerManager(ScreenManager.Game, map, gravity);
            gameObjects.AddRange(playerManager.players);

            cam.activePlayer = playerManager.currentPlayer;

            // once the load has finished, we use ResetElapsedTime to tell the game's
            // timing mechanism that we have just finished a very long frame, and that
            // it should not try to catch up.
            ScreenManager.Game.ResetElapsedTime();

            foreach (GameObject obj in gameObjects)
            {
                if (obj is TargetTile)
                {
                    cam.center = obj.position;
                    cam.MoveCameraToGameObject(obj, 4.0f, 800.0f);
                    break;
                }
            }
            GC.Collect(); //Requesting garbage collect
        }
        /// <summary>
        /// Load graphics content for the game.
        /// </summary>
        public override void LoadContent()
        {
            if (content == null)
            {
                content = new ContentManager(ScreenManager.Game.Services, "Content");
            }

            collisionMananger = new CollisionManager(ScreenManager.Game);

            // Adds collision manager to Game.Service, This Service unloads when UnloadContent is called.
            ScreenManager.Game.Services.AddService(typeof(ICollisionService), collisionMananger);

            spriteBatch = ScreenManager.SpriteBatch;
            gameFont = content.Load<SpriteFont>("gamefont");

            //Add game world
            world = new World(ScreenManager.Game);
            world.LoadContent();
            gameObjects.AddRange(world.tiles);

            //Add Trigger objects
            gameObjects.AddRange(world.triggerTile);

            //Add Destroyable Tile objects
            foreach (Trigger triggerObj in world.triggerTile)
            {
                 gameObjects.Add(triggerObj.GetDestroyableTile());
            }

            soundManager = new Sound(ScreenManager.Game);
            soundManager.LoadContent();
            soundManager.PlayMusic("main");

            //Adds GUI buttons
            gamePlayButtons = new GamePlayButtons(ScreenManager.Game);

            //Add players
            playerManager = new PlayerManager(ScreenManager.Game, gravity);
            playerManager.LoadContent();
            gameObjects.AddRange(playerManager.players);
            endPicture = content.Load<Texture2D>("endpicture");
            //Add game cam
            cam = new Camera(ScreenManager.GraphicsDevice.Viewport);
            cam.activePlayer = playerManager.currentPlayer;

            // once the load has finished, we use ResetElapsedTime to tell the game's
            // timing mechanism that we have just finished a very long frame, and that
            // it should not try to catch up.
            ScreenManager.Game.ResetElapsedTime();

            GC.Collect(); //Requesting garbage collect
        }