Пример #1
0
        protected override void LoadContent()
        {
            spriteBatch = new SpriteBatch(GraphicsDevice);

            /*
             * This is the code to read in levels.
             * The constructor reads in the map data file (.map) located in Content\MapData
             * that is specified by the Content.RootDirectory that is set in the Game3
             * constructor. It also reads in the tile set data and creates a Tile class
             * within the TileMap class that uses the texture that is given to, in this
             * case, tiles and defines the dimensions of each tile in the tile set texture.             *
             */
            //Texture2D tiles = Content.Load<Texture2D>(@"Textures\TileSets\input1");
            //testLevel = new TileMap("testlevel", Content.RootDirectory, tiles, 32, 32, 2);
            Texture2D tiles2 = Content.Load<Texture2D>(@"Textures\TileSets\input2");
            testLevel = new TileMap("testleveltwo", Content.RootDirectory, tiles2, 48, 48, 0);

            /*
             * This is the code to initialize the camera.
             * ViewWidth and ViewHeight set the viewport in the camera class.
             * WorldWidth and WorldHeight set the dimensions of the level map.
             * DisplayOffset helps the camera stay in bounds.
             */
            Camera.viewWidth = this.graphics.PreferredBackBufferWidth;
            Camera.viewHeight = this.graphics.PreferredBackBufferHeight;
            Camera.worldWidth = testLevel.mapWidth * testLevel.tileProperties.width;
            Camera.worldHeight = testLevel.mapHeight * testLevel.tileProperties.height;
            Camera.displayOffset = new Vector2(baseOffsetX, baseOffsetY);
            Camera.location = Vector2.Zero;

            base.LoadContent();
        }
Пример #2
0
        /// <summary>
        /// Creates a new level
        /// </summary>
        /// <param name="service">
        /// Service provider used for a ContentManager
        /// </param>
        /// <param name="filePath">
        /// String of path to file containing tile placement data
        /// </param>
        public Level(IServiceProvider service, int levelIndex)
        {
            //Create content manager for current level.
            content = new ContentManager(service, "Content");

            //Load level map
            levelMap = new TileMap(this, levelIndex, content.Load<Texture2D>("Tiles/tiles"));

            //Initialize Camera
            Camera.InitializeLevel(levelMap);
            player = new Player(this, start);
        }
Пример #3
0
 /// <summary>
 /// Initializes the screen's min and max positions for the level.
 /// </summary>
 /// <param name="levelMap">
 /// Level the camera is displaying.
 /// </param>
 public static void InitializeLevel(TileMap levelMap)
 {
     Camera.worldWidth = levelMap.mapWidth * Tile.WIDTH;
     Camera.worldHeight = levelMap.mapHeight * Tile.HEIGHT;
     Camera.location = Vector2.Zero;
 }