Пример #1
0
        /// <summary>
        /// Draw the terrain out, using the spritebatch and
        /// specified world camera.
        /// </summary>
        /// <param name="spriteBatch"></param>
        /// <param name="worldCamera"></param>
        public void Draw(SpriteBatch spriteBatch, WorldCamera worldCamera)
        {
            Rectangle viewRect = worldCamera.getRectangle();

            int xStart = ( viewRect.Left < 0)?(int)Math.Floor(viewRect.Left / (float)Tiles.TILE_WIDTH): viewRect.Left/Tiles.TILE_WIDTH;
            int xEnd = (viewRect.Left < 0) ? (int)Math.Floor(viewRect.Right / (float)Tiles.TILE_WIDTH) : viewRect.Right / Tiles.TILE_WIDTH;
            int yStart = (viewRect.Top < 0) ? (int)Math.Floor(viewRect.Top / (float)Tiles.TILE_HEIGHT) : viewRect.Top / Tiles.TILE_HEIGHT;
            int yEnd = (viewRect.Bottom < 0) ? (int)Math.Floor(viewRect.Bottom / (float)Tiles.TILE_HEIGHT) : viewRect.Bottom / Tiles.TILE_HEIGHT;

            for (int i = xStart; i <= xEnd; i++)
                for (int j = yStart; j <= yEnd; j++)
                {
                    // If we're outside the bounds of the tilemap, do nothing.
                    // TODO: Consider an option to handle wrapping.
                    if (i < 0 || i >= _mapWidth || j < 0 || j >= _mapHeight)
                        continue;
                    _data[i, j].Draw(spriteBatch, _terrainTexture, i * Tiles.TILE_WIDTH, j * Tiles.TILE_HEIGHT);
                }
        }
Пример #2
0
        /// <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()
        {
            // TODO: Add your initialization logic here

            // Initialize camera
            worldCamera = new WorldCamera(this.GraphicsDevice);

            guiCamera = new Camera(this.GraphicsDevice);

            base.Initialize();

            // We need to move this down because we need LoadContent to load up numbers.
            fpsCounter = new FPSCounter(numbers, new Rectangle(0, 0, 8, 10), Color.Yellow);

            // Initialize random map data for testing
            terrain = new Tilemap(1000, 1000, myTexture);
            terrain.MapFillPattern1();
        }