Пример #1
0
        public static void Add(string name, int gridWidth, int gridHeight, int[] ids, bool[] flipX, bool[] flipY)
        {
            int mW = gridWidth * uRetroConfig.sprite_width;
            int mH = gridHeight * uRetroConfig.sprite_height;

            uRetroImage metaSprite = new uRetroImage(mW, mH);

            int tmpID = 0;

            for (int x = 0; x < gridWidth; x++)
            {
                for (int y = 0; y < gridHeight; y++)
                {
                    uRetroImage tmpSprite = uRetroSprites.GetSpriteRetroImage(ids[tmpID]).GetFlipedImage(flipX[tmpID], flipY[tmpID]);

                    for (int sx = 0; sx < tmpSprite.width; sx++)
                    {
                        for (int sy = 0; sy < tmpSprite.height; sy++)
                        {
                            byte colorID = tmpSprite.GetPixel(sx, sy);

                            metaSprite.SetPixel((gridWidth - 1 - x) * uRetroConfig.sprite_width + sx, y * uRetroConfig.sprite_height + sy, colorID);
                        }
                    }

                    tmpID++;
                }
            }

            metaSprites.Add(name, metaSprite);
        }
Пример #2
0
        public static void DrawTile(int layer, int tx, int ty, int sx, int sy)
        {
            uRetroImage tilePixels = null;

            if (uRetroConfig.flipScreenY)
            {
                ty = (uRetroConfig.tilemap_height - 1) - ty;
            }

            int spriteID = spriteID = layers[layer].tilemap[tx, ty].spriteID;

            if (spriteID == -1)
            {
                tilePixels = new uRetroImage(uRetroConfig.sprite_width, uRetroConfig.sprite_height);
            }
            else
            {
                tilePixels = uRetroSprites.GetSpriteRetroImage(spriteID).GetFlipedImage(layers[layer].tilemap[tx, ty].flipX, layers[layer].tilemap[tx, ty].flipY);
            }

            int tW = uRetroConfig.sprite_width;
            int tH = uRetroConfig.sprite_height;
            int tX = tx * tW;
            int tY = ty * tH;

            uRetroUtils.DrawImage(tilePixels, sx, sy);
        }
Пример #3
0
        public uRetroImage GetFlipedImage(bool flipX, bool flipY)
        {
            uRetroImage res = new uRetroImage(this.width, this.height);

            Array.Copy(data, res.data, this.data.Length);

            for (var iy = 0; iy < this.height; iy++)
            {
                for (var ix = 0; ix < this.width; ix++)
                {
                    var newx = ix;
                    var newy = iy;
                    if (flipX)
                    {
                        newx = this.width - 1 - ix;
                    }
                    if (flipY)
                    {
                        newy = this.height - 1 - iy;
                    }
                    res.data[iy + ix * this.height] = this.data[newy + newx * this.height];
                }
            }

            return(res);
        }
Пример #4
0
        public static void DrawImageWithFixedColor(uRetroImage source, int x, int y, byte backgroundColor = 255, byte foregroundColor = 1)
        {
            int idx = 0;

            if (uRetroConfig.flipScreenY)
            {
                for (int px = 0; px < source.width; px++)
                {
                    for (int py = 0; py < source.height; py++)
                    {
                        if (source.data[idx] == 0)
                        {
                            if (backgroundColor != 255)
                            {
                                uRetroVRAM.Pixel(x + px, (uRetroConfig.sprite_height - 1) + y - py, backgroundColor);
                            }
                        }
                        else
                        {
                            uRetroVRAM.Pixel(x + px, (uRetroConfig.sprite_height - 1) + y - py, foregroundColor);
                        }
                        idx++;
                    }
                }
            }
            else
            {
                for (int px = 0; px < source.width; px++)
                {
                    for (int py = 0; py < source.height; py++)
                    {
                        if (source.data[idx] == 0)
                        {
                            if (backgroundColor != 255)
                            {
                                uRetroVRAM.Pixel(x + px, y + py, backgroundColor);
                            }
                        }
                        else
                        {
                            uRetroVRAM.Pixel(x + px, y + py, foregroundColor);
                        }
                        idx++;
                    }
                }
            }
        }
Пример #5
0
        public static void DrawImage(uRetroImage source, int x, int y, bool transparent = true)
        {
            int idx = 0;

            if (uRetroConfig.flipScreenY)
            {
                for (int px = 0; px < source.width; px++)
                {
                    for (int py = 0; py < source.height; py++)
                    {
                        if (source.data[idx] == 0)
                        {
                            if (!transparent)
                            {
                                uRetroVRAM.Pixel(x + px, y + 7 - py, source.data[idx]);
                            }
                        }
                        else
                        {
                            uRetroVRAM.Pixel(x + px, y + 7 - py, source.data[idx]);
                        }
                        idx++;
                    }
                }
            }
            else
            {
                for (int px = 0; px < source.width; px++)
                {
                    for (int py = 0; py < source.height; py++)
                    {
                        if (source.data[idx] == 0)
                        {
                            if (!transparent)
                            {
                                uRetroVRAM.Pixel(x + px, y + py, source.data[idx]);
                            }
                        }
                        else
                        {
                            uRetroVRAM.Pixel(x + px, y + py, source.data[idx]);
                        }
                        idx++;
                    }
                }
            }
        }
Пример #6
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="texture"></param>
        public static void CreateSprites(Texture2D texture)
        {
            if (texture.width % uRetroConfig.sprite_width != 0)
            {
                Debug.LogError("Sprites source image width is not power of 8");
                return;
            }

            if (texture.height % uRetroConfig.sprite_height != 0)
            {
                Debug.LogError("Sprites source image height is not power of 8");
                return;
            }

            sprites = new List <uRetroImage>();

            // Sprite grid [X,Y] = (8x8 pixels)

            sheetWidth  = texture.width;
            sheetHeight = texture.height;

            for (int y = texture.height / uRetroConfig.sprite_height; y >= 0; y--)
            {
                for (int x = 0; x < texture.width / uRetroConfig.sprite_width; x++)
                {
                    uRetroImage sprite = new uRetroImage(uRetroConfig.sprite_width, uRetroConfig.sprite_height);
                    int         idx    = 0;
                    // sprite cell (sprite width x sprite height)
                    for (int sx = 0; sx < uRetroConfig.sprite_width; sx++)
                    {
                        for (int sy = 0; sy < uRetroConfig.sprite_height; sy++)
                        {
                            Color c = texture.GetPixel(x * uRetroConfig.sprite_width + sx, y * uRetroConfig.sprite_height + sy - 8);
                            sprite.data[idx] = uRetroColors.GetColorIndex(c);
                            idx++;
                        }
                    }

                    sprites.Add(sprite);
                }
            }

            //Debug.Log("Sprites count: " + sprites.Count);
        }
Пример #7
0
        public static void CreateFont(Texture2D texture)
        {
            if (texture.width % uRetroConfig.sprite_width != 0)
            {
                Debug.LogError("Character source image width is not power of 8");
                return;
            }

            if (texture.height % uRetroConfig.sprite_height != 0)
            {
                Debug.LogError("Character source image height is not power of 8");
                return;
            }

            characters = new List <uRetroImage>();

            for (int y = texture.height / uRetroConfig.sprite_height; y >= 0; y--)
            {
                for (int x = 0; x < texture.width / uRetroConfig.sprite_width; x++)
                {
                    uRetroImage character = new uRetroImage(uRetroConfig.sprite_width, uRetroConfig.sprite_height);
                    int         idx       = 0;

                    // char cell (sprite width x sprite height)
                    for (int sx = 0; sx < uRetroConfig.sprite_width; sx++)
                    {
                        for (int sy = 0; sy < uRetroConfig.sprite_height; sy++)
                        {
                            Color c = texture.GetPixel(x * uRetroConfig.sprite_width + sx, y * uRetroConfig.sprite_height + sy - 8);
                            character.data[idx] = uRetroColors.GetColorIndex(c);
                            idx++;
                        }
                    }

                    characters.Add(character);
                }
            }

            for (int i = 0; i < 4; i++)
            {
                SetFont(i, 0, uRetroConfig.charSpacing);
            }
        }
Пример #8
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="id"></param>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <param name="transparent"></param>
        public static void DrawSprite(int id, int x, int y, bool flipX = false, bool flipY = false, bool transparent = true)
        {
            uRetroImage sprite = sprites[id].GetFlipedImage(flipX, flipY);

            uRetroUtils.DrawImage(sprite, x, y, transparent);
        }