Example #1
0
        public Bitmap drawSelectedObject(Bitmap image, Object selected)
        {
            Color     border = Color.White;
            FastPixel fp     = new FastPixel(image);

            fp.rgbValues = new byte[160 * 128 * 4];
            fp.Lock();
            foreach (Object obj in objects)
            {
                if (obj.x != selected.x)
                {
                    continue;
                }
                if (obj.y != selected.y)
                {
                    continue;
                }
                if (obj.direction != selected.direction)
                {
                    continue;
                }
                if (obj.length != selected.length)
                {
                    continue;
                }
                if (obj.id != selected.id)
                {
                    continue;
                }
                int x = obj.x * 16;
                int y = obj.y * 16;
                if (obj.hFlip)
                {
                    x = -16;
                }
                if (obj.vFlip)
                {
                    y = -16;
                }
                bool v = false;
                bool h = false;

                if (!obj.is3Byte)
                {
                    if (obj.x > 9 || obj.y > 7)
                    {
                        continue;
                    }
                }
                if (!obj.is3Byte)
                {
                    if (obj.isEntrance || obj.isDoor1 || obj.isDoor2)
                    {
                        for (int yy = 0; yy < obj.h * 16; yy++)
                        {
                            for (int xx = 0; xx < obj.w * 16; xx++)
                            {
                                if (x < 0 && !h)
                                {
                                    xx = xx + 16;
                                    h  = true;
                                }
                                if (y < 0 && !v)
                                {
                                    yy = yy + 16;
                                    v  = true;
                                }
                                if (x + xx >= 160 || x + xx < 0)
                                {
                                    continue;
                                }
                                if (y + yy >= 128 || y + yy < 0)
                                {
                                    continue;
                                }
                                if (yy > 0 && yy != ((obj.h * 16) - 1))
                                {
                                    if (xx == 0 || xx == (obj.w * 16) - 1)
                                    {
                                        fp.SetPixel(x + xx, y + yy, border);
                                    }
                                }
                                else
                                {
                                    fp.SetPixel(x + xx, y + yy, border);
                                }
                            }
                        }
                    }
                    else
                    {
                        for (int yy = 0; yy < 16; yy++)
                        {
                            for (int xx = 0; xx < 16; xx++)
                            {
                                if (yy > 0 && yy != 15)
                                {
                                    if (xx == 0 || xx == 15)
                                    {
                                        fp.SetPixel(x + xx, y + yy, border);
                                    }
                                }
                                else
                                {
                                    fp.SetPixel(x + xx, y + yy, border);
                                }
                            }
                        }
                    }
                }
                else
                {
                    if (!obj.isDoor1 || !obj.isDoor2 || !obj.isEntrance)
                    {
                        if (obj.direction == 8)
                        {
                            for (int yy = 0; yy < 16; yy++)
                            {
                                for (int xx = 0; xx < (obj.length * 16); xx++)
                                {
                                    if (x < 0 && !h)
                                    {
                                        xx = xx + 16;
                                        h  = true;
                                    }
                                    if (y < 0 && !v)
                                    {
                                        yy = yy + 16;
                                        v  = true;
                                    }
                                    if (x + xx >= 160 || x + xx < 0)
                                    {
                                        continue;
                                    }
                                    if (y + yy >= 128 || y + yy < 0)
                                    {
                                        continue;
                                    }
                                    if (yy > 0 && yy != 15)
                                    {
                                        if (xx == 0 || xx == (obj.length * 16) - 1)
                                        {
                                            fp.SetPixel(x + xx, y + yy, border);
                                        }
                                    }
                                    else
                                    {
                                        fp.SetPixel(x + xx, y + yy, border);
                                    }
                                }
                            }
                        }
                        else
                        {
                            for (int yy = 0; yy < obj.length * 16; yy++)
                            {
                                for (int xx = 0; xx < 16; xx++)
                                {
                                    if (x < 0 && !h)
                                    {
                                        xx = xx + 16;
                                        h  = true;
                                    }
                                    if (y < 0 && !v)
                                    {
                                        yy = yy + 16;
                                        v  = true;
                                    }
                                    if (x + xx >= 160 || x + xx < 0)
                                    {
                                        continue;
                                    }
                                    if (y + yy >= 128 || y + yy < 0)
                                    {
                                        continue;
                                    }
                                    if (yy > 0 && yy != (obj.length * 16) - 1)
                                    {
                                        if (xx == 0 || xx == 15)
                                        {
                                            fp.SetPixel(x + xx, y + yy, border);
                                        }
                                    }
                                    else
                                    {
                                        fp.SetPixel(x + xx, y + yy, border);
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        if (obj.direction == 8)
                        {
                            for (int i = 0; i < obj.length; i++)
                            {
                                for (int yy = 0; yy < obj.h * 16; yy++)
                                {
                                    for (int xx = 0 + (i * 16); xx < obj.w * (obj.length * 16); xx++)
                                    {
                                        if (x < 0 && !h)
                                        {
                                            xx = xx + 16;
                                            h  = true;
                                        }
                                        if (y < 0 && !v)
                                        {
                                            yy = yy + 16;
                                            v  = true;
                                        }
                                        if (x + xx >= 160 || x + xx < 0)
                                        {
                                            continue;
                                        }
                                        if (y + yy >= 128 || y + yy < 0)
                                        {
                                            continue;
                                        }
                                        if (yy > 0 && yy != ((obj.h * 16) - 1))
                                        {
                                            if (xx == 0 || xx == ((obj.length * 16) * obj.w) - 1)
                                            {
                                                fp.SetPixel(x + xx, y + yy, border);
                                            }
                                        }
                                        else
                                        {
                                            fp.SetPixel(x + xx, y + yy, border);
                                        }
                                    }
                                }
                            }
                        }
                        else
                        {
                            for (int i = 0; i < obj.length; i++)
                            {
                                for (int yy = 0 + (i * 16); yy < obj.h * (obj.length * 16); yy++)
                                {
                                    for (int xx = 0; xx < obj.w * 16; xx++)
                                    {
                                        if (x < 0 && !h)
                                        {
                                            xx = xx + 16;
                                            h  = true;
                                        }
                                        if (y < 0 && !v)
                                        {
                                            yy = yy + 16;
                                            v  = true;
                                        }
                                        if (x + xx >= 160 || x + xx < 0)
                                        {
                                            continue;
                                        }
                                        if (y + yy >= 128 || y + yy < 0)
                                        {
                                            continue;
                                        }
                                        if (yy > 0 && yy != ((obj.length * 16) * obj.h) - 1)
                                        {
                                            if (xx == 0 || xx == obj.w * 16)
                                            {
                                                fp.SetPixel(x + xx, y + yy, border);
                                            }
                                        }
                                        else
                                        {
                                            fp.SetPixel(x + xx, y + yy, border);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            fp.Unlock(true);
            return(image);
        }
Example #2
0
        public Bitmap drawSpritePair16(byte[] tileData, byte entityTileOffset)
        {
            Bitmap    bmp = new Bitmap(16, 16);
            FastPixel fp  = new FastPixel(bmp);

            fp.rgbValues = new byte[16 * 16 * 4];
            fp.Lock();

            loadPalette();

            int ctr;

            if (tileData == null)
            {
                for (int yy = 0; yy < 16; yy++)
                {
                    for (int xx = 0; xx < 16; xx++)
                    {
                        fp.SetPixel(xx, yy, Color.Black);
                    }
                }
                fp.Unlock(true);

                return(bmp);
            }

            byte palOffset = 0;

            for (int i = 0; i < tileData.Length; i += 2)
            {
                palOffset = ((byte)(tileData[i + 1] & 0x0f));

                for (int y = 0; y < 8; y++)
                {
                    ctr = 7;
                    for (int x = 0; x < 8; x++)
                    {
                        if ((tileData[i + 1] & 0x60) == 0x60) //Y and X Flip
                        {
                            fp.SetPixel(x + ((i / 2) * 8), y, palette[palOffset, spriteData[tileData[i] + entityTileOffset - 0x40, ctr, ctr]]);
                            fp.SetPixel(x + ((i / 2) * 8), y + 8, palette[palOffset, spriteData[tileData[i] + 1 + entityTileOffset - 0x40, ctr, ctr]]);
                            ctr--;
                        }
                        else if ((tileData[i + 1] & 0x20) == 0x20)//X Flip
                        {
                            fp.SetPixel(x + ((i / 2) * 8), y, palette[palOffset, spriteData[tileData[i] + entityTileOffset - 0x40, ctr, y]]);
                            fp.SetPixel(x + ((i / 2) * 8), y + 8, palette[palOffset, spriteData[tileData[i] + 1 + entityTileOffset - 0x40, ctr, y]]);
                            ctr--;
                        }
                        else if ((tileData[i + 1] & 0x40) == 0x40)//Y Flip
                        {
                            fp.SetPixel(x + ((i / 2) * 8), y, palette[palOffset, spriteData[tileData[i] + entityTileOffset - 0x40, x, ctr]]);
                            fp.SetPixel(x + ((i / 2) * 8), y + 8, palette[palOffset, spriteData[tileData[i] + 1 + entityTileOffset - 0x40, x, ctr]]);
                            ctr--;
                        }
                        else //Normal
                        {
                            fp.SetPixel(x + ((i / 2) * 8), y, palette[palOffset, spriteData[tileData[i] + entityTileOffset - 0x40, x, y]]);
                            fp.SetPixel(x + ((i / 2) * 8), y + 8, palette[palOffset, spriteData[tileData[i] + 1 + entityTileOffset - 0x40, x, y]]);
                        }
                    }
                }
            }

            fp.Unlock(true);
            if (spriteBank != 0 || LAGame.dungeon == 0xFF)
            {
                bmp.MakeTransparent(palette[palOffset, 0]);
            }
            return(bmp);
        }
Example #3
0
        public Bitmap drawBorders(Bitmap image)
        {
            FastPixel fp = new FastPixel(image);

            fp.rgbValues = new byte[160 * 128 * 4];
            fp.Lock();
            foreach (Object obj in objects)
            {
                int x = obj.x * 16;
                int y = obj.y * 16;
                if (obj.hFlip)
                {
                    x = -16;
                }
                if (obj.vFlip)
                {
                    y = -16;
                }
                bool v = false;
                bool h = false;
                if (!obj.is3Byte)
                {
                    if (obj.x > 9 || obj.y > 7)
                    {
                        continue;
                    }
                }
                if (!obj.is3Byte)
                {
                    if (obj.isEntrance || obj.isDoor1 || obj.isDoor2)
                    {
                        for (int yy = 0; yy < obj.h * 16; yy++)
                        {
                            for (int xx = 0; xx < obj.w * 16; xx++)
                            {
                                if (x < 0 && !h)
                                {
                                    xx = xx + 16;
                                    h  = true;
                                }
                                if (y < 0 && !v)
                                {
                                    yy = yy + 16;
                                    v  = true;
                                }
                                if (x + xx >= 160 || x + xx < 0)
                                {
                                    continue;
                                }
                                if (y + yy >= 128 || y + yy < 0)
                                {
                                    continue;
                                }
                                if (yy > 0 && yy != ((obj.h * 16) - 1))
                                {
                                    if (xx == 0 || xx == (obj.w * 16) - 1)
                                    {
                                        fp.SetPixel(x + xx, y + yy, Color.DeepPink);
                                    }
                                }
                                else
                                {
                                    fp.SetPixel(x + xx, y + yy, Color.DeepPink);
                                }
                            }
                        }
                    }
                    else
                    {
                        for (int yy = 0; yy < 16; yy++)
                        {
                            for (int xx = 0; xx < 16; xx++)
                            {
                                if (yy > 0 && yy != 15)
                                {
                                    if (xx == 0 || xx == 15)
                                    {
                                        fp.SetPixel(x + xx, y + yy, Color.DarkGreen);
                                    }
                                }
                                else
                                {
                                    fp.SetPixel(x + xx, y + yy, Color.DarkGreen);
                                }
                            }
                        }
                    }
                }
                else
                {
                    if (!obj.isDoor1 || !obj.isDoor2 || !obj.isEntrance)
                    {
                        if (obj.direction == 8)
                        {
                            for (int yy = 0; yy < 16; yy++)
                            {
                                for (int xx = 0; xx < (obj.length * 16); xx++)
                                {
                                    if (x < 0 && !h)
                                    {
                                        xx = xx + 16;
                                        h  = true;
                                    }
                                    if (y < 0 && !v)
                                    {
                                        yy = yy + 16;
                                        v  = true;
                                    }
                                    if (x + xx >= 160 || x + xx < 0)
                                    {
                                        continue;
                                    }
                                    if (y + yy >= 128 || y + yy < 0)
                                    {
                                        continue;
                                    }
                                    if (yy > 0 && yy != 15)
                                    {
                                        if (xx == 0 || xx == (obj.length * 16) - 1)
                                        {
                                            fp.SetPixel(x + xx, y + yy, Color.DarkRed);
                                        }
                                    }
                                    else
                                    {
                                        fp.SetPixel(x + xx, y + yy, Color.DarkRed);
                                    }
                                }
                            }
                        }
                        else
                        {
                            for (int yy = 0; yy < obj.length * 16; yy++)
                            {
                                for (int xx = 0; xx < 16; xx++)
                                {
                                    if (x < 0 && !h)
                                    {
                                        xx = xx + 16;
                                        h  = true;
                                    }
                                    if (y < 0 && !v)
                                    {
                                        yy = yy + 16;
                                        v  = true;
                                    }
                                    if (x + xx >= 160 || x + xx < 0)
                                    {
                                        continue;
                                    }
                                    if (y + yy >= 128 || y + yy < 0)
                                    {
                                        continue;
                                    }
                                    if (yy > 0 && yy != (obj.length * 16) - 1)
                                    {
                                        if (xx == 0 || xx == 15)
                                        {
                                            fp.SetPixel(x + xx, y + yy, Color.DarkBlue);
                                        }
                                    }
                                    else
                                    {
                                        fp.SetPixel(x + xx, y + yy, Color.DarkBlue);
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        if (obj.direction == 8)
                        {
                            for (int i = 0; i < obj.length; i++)
                            {
                                for (int yy = 0; yy < obj.h * 16; yy++)
                                {
                                    for (int xx = 0 + (i * 16); xx < obj.w * (obj.length * 16); xx++)
                                    {
                                        if (x < 0 && !h)
                                        {
                                            xx = xx + 16;
                                            h  = true;
                                        }
                                        if (y < 0 && !v)
                                        {
                                            yy = yy + 16;
                                            v  = true;
                                        }
                                        if (x + xx >= 160 || x + xx < 0)
                                        {
                                            continue;
                                        }
                                        if (y + yy >= 128 || y + yy < 0)
                                        {
                                            continue;
                                        }
                                        if (yy > 0 && yy != ((obj.h * 16) - 1))
                                        {
                                            if (xx == 0 || xx == ((obj.length * 16) * obj.w) - 1)
                                            {
                                                fp.SetPixel(x + xx, y + yy, Color.DarkGoldenrod);
                                            }
                                        }
                                        else
                                        {
                                            fp.SetPixel(x + xx, y + yy, Color.DarkGoldenrod);
                                        }
                                    }
                                }
                            }
                        }
                        else
                        {
                            for (int i = 0; i < obj.length; i++)
                            {
                                for (int yy = 0 + (i * 16); yy < obj.h * (obj.length * 16); yy++)
                                {
                                    for (int xx = 0; xx < obj.w * 16; xx++)
                                    {
                                        if (x < 0 && !h)
                                        {
                                            xx = xx + 16;
                                            h  = true;
                                        }
                                        if (y < 0 && !v)
                                        {
                                            yy = yy + 16;
                                            v  = true;
                                        }
                                        if (x + xx >= 160 || x + xx < 0)
                                        {
                                            continue;
                                        }
                                        if (y + yy >= 128 || y + yy < 0)
                                        {
                                            continue;
                                        }
                                        if (yy > 0 && yy != ((obj.length * 16) * obj.h) - 1)
                                        {
                                            if (xx == 0 || xx == obj.w * 16)
                                            {
                                                fp.SetPixel(x + xx, y + yy, Color.Purple);
                                            }
                                        }
                                        else
                                        {
                                            fp.SetPixel(x + xx, y + yy, Color.Purple);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            fp.Unlock(true);
            return(image);
        }