Beispiel #1
0
        /// <summary>
        /// Constructs a new level.
        /// </summary>
        /// <param name="serviceProvider">
        /// The service provider that will be used to construct a ContentManager.
        /// </param>
        /// <param name="fileStream">
        /// A stream containing the tile data.
        /// </param>
        public Level(IServiceProvider serviceProvider, Game game, int levelIndex, Texture2D background)
            : base(game)
        {
            _levelIndex = levelIndex;

            _game = (MainGameClass)game;

            _camera = _game.MainCamera;

            _camera.InitializeView(640,480, 0, 0);

            // Create a new content manager to load content used just by this level.
            levelContent = new ContentManager(serviceProvider, "Content");

            //makes a new array of backgrounds
            backgroundLayers = new Texture2D[_backgrounds];
            for (int i = 0; i < backgroundLayers.Length; ++i)
            {
                // Choose a random segment if each background layer for level variety.
                int segmentIndex = levelIndex;
                backgroundLayers[i] = LevelContent.Load<Texture2D>("PHArt/bgDefault.jpg");
            }
        }
        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            config.Initialize();
            InputState inputState = new InputState(true, config);
            mainCamera = new Camera();
            mainCamera.SubscribeToHandler(inputState);
            // Create the screen manager component.
            screenManager = new ScreenManager(this, inputState);
            graphics.PreferredBackBufferWidth = 1080;
            graphics.PreferredBackBufferHeight = 720;
            //Resolution.Init(ref graphics);
            mainCamera.Init(ref graphics);
            // Change Virtual Resolution
            bool b;
            Point p = config.GetStartUpResolution(out b); //used out to get all three SetRes params
            //Resolution.SetResolution(p.X, p.Y, b);
            mainCamera.SetResolution(p.X, p.Y, b);
            p = config.GetStartUpVResolution();
            //Resolution.SetVirtualResolution(p.X, p.Y);
            mainCamera.InitializeView(p.X, p.Y, 50, 50);

            Content.RootDirectory = "Content";
            Components.Add(screenManager);
            /*
            Components.Add(screenManager);

            // Activate the first screens.
            screenManager.AddScreen(new BackgroundScreen(), null);
            screenManager.AddScreen(new MainMenuScreen(), null);
            */

            base.Initialize();
        }