Exemple #1
0
        public override void CreateFrames()
        {
            Columns = (int)Math.Ceiling(Texture.Width / (float)(FrameWidth + Border));
            Rows = (int)Math.Ceiling(Texture.Height / (float)(FrameHeight + Border));
            Frames = new RawImage[Columns, Rows];

            for (int r = 0; r < Rows; r++)
            {
                for (int c = 0; c < Columns; c++)
                {
                    Frames[c, r] = TextureHelper.TextureToRaw(Texture, new Rectangle(c * (FrameWidth + Border), r * (FrameHeight + Border), FrameWidth, FrameHeight));
                }
            }
        }
Exemple #2
0
        public virtual void CreateFrames()
        {
            Columns = Texture.Width / (FrameWidth + Border);
            Rows = Texture.Height / (FrameHeight + Border);
            Frames = new RawImage[Columns, Rows];

            for (int r = 0; r < Rows; r++)
            {
                for (int c = 0; c < Columns; c++)
                {
                    Frames[c, r] = TextureHelper.TextureToRaw(Texture, new Rectangle(c * (FrameWidth + Border), r * (FrameHeight + Border), FrameWidth, FrameHeight));
                }
            }
        }
Exemple #3
0
 private static void AbgrToArgb(RawImage ints)
 {
     for (int y = 0; y < ints.Height; y++)
     {
         for (int x = 0; x < ints.Width; x++)
         {
             var c = System.Drawing.Color.FromArgb(ints[x, y]);
             ints[x, y] = (int)new Color(c.R, c.G, c.B, c.A).PackedValue;
         }
     }
 }
Exemple #4
0
 public static RawImage TextureToRaw(Texture2D text, Rectangle rect)
 {
     var ret = new RawImage(rect.Width, rect.Height);
     text.GetData(0, rect, ret.Data, 0, ret.Data.Length);
     AbgrToArgb(ret);
     return ret;
 }
Exemple #5
0
 public static RawImage TextureToRaw(Texture2D text)
 {
     var ret = new RawImage(text.Width, text.Height);
     text.GetData(ret.Data);
     AbgrToArgb(ret);
     return ret;
 }
Exemple #6
0
        private void RenderWalls(RawImage img, int startx, int starty, int width, int height)
        {
            for (int y = 0; y < height; y++)
            {
                int tiley = starty + y;
                if (tiley < 0 || tiley > Main.maxTilesY)
                    continue;
                for (int x = 0; x < width; x++)
                {
                    int tilex = startx + x;
                    if (tilex < 0 || tilex > Main.maxTilesX)
                        continue;

                    var tile = Main.tile[tilex, tiley];
                    if (tile == null)
                        continue;

                    if (tile.wall > 0)
                    {
                        var frame = Walls[tile.wall].GetFrame(tile.wallFrameX() * 2, tile.wallFrameY() * 2);
                        CopyImgTo(img, x * 16, y * 16, frame);
                    }
                }
            }
        }
Exemple #7
0
        private void RenderTreeTops(RawImage img, int startx, int starty, int width, int height)
        {
            for (int y = 0; y < height; y++)
            {
                int tiley = starty + y;
                if (tiley < 0 || tiley > Main.maxTilesY)
                    continue;
                for (int x = 0; x < width; x++)
                {
                    int tilex = startx + x;
                    if (tilex < 0 || tilex > Main.maxTilesX)
                        continue;

                    var tile = Main.tile[tilex, tiley];
                    if (tile == null)
                        continue;

                    if (!tile.active())
                        continue;

                    if (((tile.type == 0x5) && (tile.frameY >= 0xc6)) && (tile.frameX >= 0x16))
                    {
                        int num14;
                        int num18;
                        int num13 = 0x0;
                        if (tile.frameX == 0x16)
                        {
                            if (tile.frameY == 0xdc)
                            {
                                num13 = 0x1;
                            }
                            else if (tile.frameY == 0xf2)
                            {
                                num13 = 0x2;
                            }
                            num14 = 0x0;
                            int num15 = 0x50;
                            int num16 = 0x50;
                            int num17 = 0x20;
                            num18 = tiley;
                            while (num18 < (tiley + 0x64))
                            {
                                if (Main.tile[tilex, num18].type == 0x2)
                                {
                                    num14 = 0x0;
                                    break;
                                }
                                if (Main.tile[tilex, num18].type == 0x17)
                                {
                                    num14 = 0x1;
                                    break;
                                }
                                if (Main.tile[tilex, num18].type == 0x3c)
                                {
                                    num14 = 0x2;
                                    num15 = 0x72;
                                    num16 = 0x60;
                                    num17 = 0x30;
                                    break;
                                }
                                num18++;
                            }
                            CopyImgTo(img, (x * 16) - num17, ((y + 1) * 16) - num16, TreeTops[num14].GetFrame(num13 * (num15 + 0x2), 0));
                        }
                        else if (tile.frameX == 0x2c)
                        {
                            if (tile.frameY == 0xdc)
                            {
                                num13 = 0x1;
                            }
                            else if (tile.frameY == 0xf2)
                            {
                                num13 = 0x2;
                            }
                            num14 = 0x0;
                            num18 = tiley;
                            while (num18 < (tiley + 0x64))
                            {
                                if (Main.tile[tilex + 0x1, num18].type == 0x2)
                                {
                                    num14 = 0x0;
                                    break;
                                }
                                if (Main.tile[tilex + 0x1, num18].type == 0x17)
                                {
                                    num14 = 0x1;
                                    break;
                                }
                                if (Main.tile[tilex + 0x1, num18].type == 0x3c)
                                {
                                    num14 = 0x2;
                                    break;
                                }
                                num18++;
                            }
                            CopyImgTo(img, (x * 16) - 0x18, (y * 16) - 0xC, TreeBranches[num14].GetFrame(0, num13 * 0x2a));
                        }
                        else if (tile.frameX == 0x42)
                        {
                            if (tile.frameY == 0xdc)
                            {
                                num13 = 0x1;
                            }
                            else if (tile.frameY == 0xf2)
                            {
                                num13 = 0x2;
                            }
                            num14 = 0x0;
                            for (num18 = tiley; num18 < (tiley + 0x64); num18++)
                            {
                                if (Main.tile[tilex - 0x1, num18].type == 0x2)
                                {
                                    num14 = 0x0;
                                    break;
                                }
                                if (Main.tile[tilex - 0x1, num18].type == 0x17)
                                {
                                    num14 = 0x1;
                                    break;
                                }
                                if (Main.tile[tilex - 0x1, num18].type == 0x3c)
                                {
                                    num14 = 0x2;
                                    break;
                                }
                            }
                            CopyImgTo(img, (x * 16), (y * 16) - 0xC, TreeBranches[num14].GetFrame(0x2a, num13 * 0x2a));
                        }
                    }
                }
            }
        }
Exemple #8
0
        private void RenderTiles(RawImage img, int startx, int starty, int width, int height)
        {
            for (int y = 0; y < height; y++)
            {
                int tiley = starty + y;
                if (tiley < 0 || tiley > Main.maxTilesY)
                    continue;
                for (int x = 0; x < width; x++)
                {
                    int tilex = startx + x;
                    if (tilex < 0 || tilex > Main.maxTilesX)
                        continue;

                    var tile = Main.tile[tilex, tiley];
                    if (tile == null)
                        continue;

                    if (tile.active())
                    {
                        if (TileTypes[tile.type] == -1)
                            continue;
                        var frame = Tiles[tile.type].GetFrame(tile.frameX, tile.frameY);
                        CopyImgTo(img, x * 16, y * 16, frame);
                    }
                }
            }
        }
Exemple #9
0
 private void RenderSky(RawImage img, int startx, int starty, int width, int height)
 {
     for (int y = 0; y < img.Height; y++)
     {
         for (int x = 0; x < img.Width; x++)
         {
             img[x, y] = Sky;
         }
     }
 }
Exemple #10
0
 private void RenderClouds(RawImage img, int startx, int starty, int width, int height)
 {
     var rand = new Random();
     int surface = ((int)Main.worldSurface - starty);
     if (surface > 0)
     {
         int space = surface * width;
         int count = space / 1000;
         for (int i = 0; i < count; i++)
         {
             int x = rand.Next(0, width * 16);
             int y = rand.Next(0, surface * 16);
             int type = rand.Next(0, 4);
             CopyImgTo(img, x, y, Clouds[type]);
         }
     }
 }
Exemple #11
0
        private void RenderBackgrounds(RawImage img, int startx, int starty, int width, int height)
        {
            int surface = (int)Main.worldSurface - (starty + 1);
            if (surface > 0 && surface < height)
            {
                for (int x = 0; x < img.Width; x += Backgrounds[1].Width)
                {
                    CopyImgTo(img, x, surface * 16, Backgrounds[1]);
                }
            }

            surface++;
            if (surface > 0 && surface < height)
            {
                for (int y = (surface * 16); y < (height * 16) && y < img.Height; y += Backgrounds[2].Height)
                {
                    for (int x = 0; x < img.Width; x += Backgrounds[2].Width)
                    {
                        CopyImgTo(img, x, y, Backgrounds[2]);
                    }
                }
            }

            int rock = (int)Main.rockLayer - starty;
        }
Exemple #12
0
        private void Render(int startx, int starty, int width, int height)
        {
            var img = new RawImage(width * 16, height * 16);

            RenderSky(img, startx, starty, width, height);
            RenderClouds(img, startx, starty, width, height);
            RenderBackgrounds(img, startx, starty, width, height);
            RenderWalls(img, startx, starty, width, height);
            RenderTreeTops(img, startx, starty, width, height);
            RenderTiles(img, startx, starty, width, height);

            var bmp = new Bitmap(img.Width, img.Height);
            var data = bmp.LockBits(new System.Drawing.Rectangle(0, 0, bmp.Width, bmp.Height), ImageLockMode.WriteOnly, PixelFormat.Format32bppArgb);
            for (int y = 0; y < img.Height; y++)
            {
                for (int x = 0; x < img.Width; x++)
                {
                    data.SetPixelInt(x, y, img[x, y]);
                }
            }
            bmp.UnlockBits(data);
            bmp.Save("test.png");
        }
Exemple #13
0
 public static void CopyImgTo(RawImage dest, int destx, int desty, RawImage src)
 {
     if (src == null)
         return;
     for (int y = 0; y < src.Height; y++)
     {
         for (int x = 0; x < src.Width; x++)
         {
             if (src[x, y] != 0)
                 dest[(x + destx), (y + desty)] = src[x, y];
         }
     }
 }