Exemplo n.º 1
0
        private void drawMap(Renderer renderer)
        {
            TileData    testTile        = Area.Data.OverworldTileTextureNamesToList()[0];
            TextureData testTextureData = ResourceManager.GetTextureData(testTile.TextureDataName);
            //TextureData pixelTexture = ResourceManager.GetTextureData("white_pixel");

            Rectangle cameraBoundingBox = camera.GetBoundingBox();
            int       startX            = Math.Max((cameraBoundingBox.Left / Map.TileSize) - 1, 0);
            int       finishX           = Math.Min(((cameraBoundingBox.Left + cameraBoundingBox.Width) / Map.TileSize) + 2, Map.TileWidth - 1);
            int       startY            = Math.Max((cameraBoundingBox.Top / Map.TileSize) - 1, 0);
            int       finishY           = Math.Min(((cameraBoundingBox.Top + cameraBoundingBox.Height) / Map.TileSize) + 2, Map.TileHeight - 1);

            /*for (int x = startX; x <= finishX; ++x)
             * {
             *  for (int y = startY; y <= finishY; ++y)
             *  {
             *      if (Map.CollisionMap[x, y])
             *          renderer.Draw(pixelTexture, new Vector2(x, y) * Map.TileSize, Color.Black * 0.5f, 0.0f, new Vector2(Map.TileSize));
             *  }
             * }*/

            for (int x = startX; x <= finishX; ++x)
            {
                for (int y = startY; y <= finishY; ++y)
                {
                    if (Map.CollisionMap[x, y])// && x % 2 == 0 && y % 2 == 0)
                    {
                        renderer.Draw(testTextureData, new Vector2(x, y) * Map.TileSize, Color.White);
                    }
                }
            }
        }
Exemplo n.º 2
0
        private void drawBackground(Renderer renderer)
        {
            const float scale             = 0.5f;
            Rectangle   cameraBoundingBox = Camera.GetBoundingBox();

            float textureWidth     = lowestBackgroundTextureWidth * scale * Camera.Scale.X;
            int   drawCount        = (int)Math.Ceiling(cameraBoundingBox.Right / textureWidth) + 1;
            int   textureDataIndex = 0;

            for (int i = 0; i < drawCount; ++i)
            {
                TextureData textureData = backgroundTextureData[textureDataIndex];
                renderer.Draw(textureData, new Vector2(textureData.Width * scale * i, 0.0f), Color.White, 0.0f, new Vector2(scale));
                if (++textureDataIndex > backgroundTextureData.Count)
                {
                    textureDataIndex = 0;
                }
            }

            if (cameraBoundingBox.Left < 0)
            {
                drawCount        = (int)Math.Ceiling(Math.Abs(cameraBoundingBox.Left) / textureWidth) + 1;
                textureDataIndex = backgroundTextureData.Count - 1;
                for (int i = -1; i >= -drawCount; --i)
                {
                    TextureData textureData = backgroundTextureData[textureDataIndex];
                    renderer.Draw(textureData, new Vector2(textureData.Width * scale * i, 0.0f), Color.White, 0.0f, new Vector2(scale));
                    if (--textureDataIndex < 0)
                    {
                        textureDataIndex = backgroundTextureData.Count - 1;
                    }
                }
            }
        }