Ejemplo n.º 1
0
        void DrawTile(GraphicsDevice device, NamelessGame game, int screenPositionX, int screenPositionY, int positionX, int positionY,
                      AtlasTileData atlasTileData,
                      Color color, Color backGroundColor, TileModel foregroundModel, TileModel backgroundModel)
        {
            if (atlasTileData == null)
            {
                atlasTileData = new AtlasTileData(1, 1);
            }


            int tileHeight = game.GetSettings().GetFontSizeZoomed();
            int tileWidth  = game.GetSettings().GetFontSizeZoomed();


            float textureX = atlasTileData.X * (Constants.tileAtlasTileSize / (float)tileAtlas.Width);
            float textureY = atlasTileData.Y * (Constants.tileAtlasTileSize / (float)tileAtlas.Height);

            float textureXend = (atlasTileData.X + 1f) * (Constants.tileAtlasTileSize / (float)tileAtlas.Width);

            float textureYend = (atlasTileData.Y + 1f) * (Constants.tileAtlasTileSize / (float)tileAtlas.Height);

            var settings = game.GetSettings();

            var arrayPosition = (screenPositionX * 4) + (screenPositionY * settings.GetWidthZoomed() * 4);



            var foregroundvertices = foregroundModel.Vertices;

            foregroundvertices[arrayPosition] = new Vertex(new Vector3(positionX, positionY, 0), color.ToVector4(),
                                                           backGroundColor.ToVector4(), new Vector2(textureX, textureY));
            foregroundvertices[arrayPosition + 1] = new Vertex(new Vector3(positionX + tileWidth, positionY, 0), color.ToVector4(),
                                                               backGroundColor.ToVector4(), new Vector2(textureXend, textureY));
            foregroundvertices[arrayPosition + 2] = new Vertex(new Vector3(positionX, positionY + tileHeight, 0), color.ToVector4(),
                                                               backGroundColor.ToVector4(), new Vector2(textureX, textureYend));
            foregroundvertices[arrayPosition + 3] = new Vertex(new Vector3(positionX + tileWidth, positionY + tileHeight, 0), color.ToVector4(),
                                                               backGroundColor.ToVector4(), new Vector2(textureXend, textureYend));

            var backgroundVertices = backgroundModel.Vertices;

            backgroundVertices[arrayPosition] = new Vertex(new Vector3(positionX, positionY, 0), color.ToVector4(),
                                                           backGroundColor.ToVector4(), new Vector2(textureX, textureY));
            backgroundVertices[arrayPosition + 1] = new Vertex(new Vector3(positionX + tileWidth, positionY, 0), color.ToVector4(),
                                                               backGroundColor.ToVector4(), new Vector2(textureXend, textureY));
            backgroundVertices[arrayPosition + 2] = new Vertex(new Vector3(positionX, positionY + tileHeight, 0), color.ToVector4(),
                                                               backGroundColor.ToVector4(), new Vector2(textureX, textureYend));
            backgroundVertices[arrayPosition + 3] = new Vertex(new Vector3(positionX + tileWidth, positionY + tileHeight, 0), color.ToVector4(),
                                                               backGroundColor.ToVector4(), new Vector2(textureXend, textureYend));
        }
        void DrawTile(GraphicsDevice device, NamelessGame game, int positionX, int positionY,
                      AtlasTileData atlasTileData,
                      Color color, Color backGroundColor)
        {
            if (atlasTileData == null)
            {
                atlasTileData = new AtlasTileData(1, 1);
            }
            var fontsize = game.GetSettings().GetFontSizeZoomed();
            var tilesize = tileAtlas.Width / 16;

            if (fontsize < 4)
            {
                _spriteBatch.Draw(whiteRectangle, new Rectangle(positionX, game.GetActualCharacterHeight() - positionY, fontsize, fontsize), null, color.ToXnaColor(), 0, default(Vector2), SpriteEffects.None, 0);
            }
            else
            {
                _spriteBatch.Draw(whiteRectangle, new Rectangle(positionX, game.GetActualCharacterHeight() - positionY, fontsize, fontsize), null, backGroundColor.ToXnaColor(), 0, default(Vector2), SpriteEffects.None, 0);
                _spriteBatch.Draw(tileAtlas, new Rectangle(positionX, game.GetActualCharacterHeight() - positionY, fontsize, fontsize), new Rectangle(atlasTileData.X * tilesize, atlasTileData.Y * tilesize, tilesize, tilesize), color.ToXnaColor(), 0, default(Vector2), SpriteEffects.None, 1);
            }
        }