Exemple #1
0
 public unsafe void SetTile(int xx, int yy, byte layer)
 {
     if (xx + (yy * 64) < 4096)
     {
         ushort t = GFX.getshortilesinfo(GetTileInfo());
         if (layer == 0)
         {
             GFX.tilesBg1Buffer[xx + (yy * 64)] = t;
         }
         else
         {
             GFX.tilesBg2Buffer[xx + (yy * 64)] = t;
         }
     }
 }
        public unsafe void draw_tile(Tile t, int xx, int yy, ushort tileUnder = 0xFFFF)
        {
            if (width < xx + 8)
            {
                width = xx + 8;
            }
            if (height < yy + 8)
            {
                height = yy + 8;
            }
            if (preview)
            {
                if (xx < 57 && yy < 57 && xx >= 0 && yy >= 0)
                {
                    var      alltilesData = (byte *)GFX.currentgfx16Ptr.ToPointer();
                    byte *   ptr          = (byte *)GFX.previewObjectsPtr[previewId].ToPointer();
                    TileInfo ti           = t.GetTileInfo();
                    for (var yl = 0; yl < 8; yl++)
                    {
                        for (var xl = 0; xl < 4; xl++)
                        {
                            int  mx = xl;
                            int  my = yl;
                            byte r  = 0;

                            if (ti.h != 0)
                            {
                                mx = 3 - xl;
                                r  = 1;
                            }
                            if (ti.v != 0)
                            {
                                my = 7 - yl;
                            }

                            //Formula information to get tile index position in the array
                            //((ID / nbrofXtiles) * (imgwidth/2) + (ID - ((ID/16)*16) ))
                            int tx    = ((ti.id / 16) * 512) + ((ti.id - ((ti.id / 16) * 16)) * 4);
                            var pixel = alltilesData[tx + (yl * 64) + xl];
                            //nx,ny = object position, xx,yy = tile position, xl,yl = pixel position

                            int index = ((xx / 8) * 8) + ((yy / 8) * 512) + ((mx * 2) + (my * 64));
                            ptr[index + r ^ 1] = (byte)((pixel & 0x0F) + ti.palette * 16);
                            ptr[index + r]     = (byte)(((pixel >> 4) & 0x0F) + ti.palette * 16);
                        }
                    }
                }
            }
            else
            {
                if (((xx / 8) + nx + offsetX) + ((ny + offsetY + (yy / 8)) * 64) < 4096 && ((xx / 8) + nx + offsetX) + ((ny + offsetY + (yy / 8)) * 64) >= 0)
                {
                    ushort td = GFX.getshortilesinfo(t.GetTileInfo());

                    collisionPoint.Add(new Point(xx + ((nx + offsetX) * 8), yy + ((ny + +offsetY) * 8)));

                    if (layer == 0 || layer == 2 || allBgs)
                    {
                        if (tileUnder == GFX.tilesBg1Buffer[((xx / 8) + offsetX + nx) + ((ny + offsetY + (yy / 8)) * 64)])
                        {
                            return;
                        }

                        GFX.tilesBg1Buffer[((xx / 8) + offsetX + nx) + ((ny + offsetY + (yy / 8)) * 64)] = td;
                    }

                    if (layer == 1 || allBgs)
                    {
                        if (tileUnder == GFX.tilesBg2Buffer[((xx / 8) + nx + offsetX) + ((ny + offsetY + (yy / 8)) * 64)])
                        {
                            return;
                        }

                        GFX.tilesBg2Buffer[((xx / 8) + nx) + offsetX + ((ny + offsetY + (yy / 8)) * 64)] = td;
                    }
                }
            }
        }