Beispiel #1
0
 public static void AddPixelMask(string name, PixelMask pixelMask)
 {
     if (PIXEL_MASKS.ContainsKey(name))
     {
         throw new Exception("PixelMask with name '" + name + "' already exists!");
     }
     PIXEL_MASKS[name] = pixelMask;
 }
Beispiel #2
0
 public PixelMaskSet(Tileset tileset)
 {
     masks = new PixelMask[tileset.TileCount];
     for (var i = 0; i < tileset.TileCount; i++)
     {
         var region = tileset.GetTileRegion(i);
         masks[i] = new PixelMask(region);
     }
 }
Beispiel #3
0
        private HitInfo(bool hit, Entity other, Tile tile, PixelMask pixelMask)
        {
            Hit       = hit;
            Other     = other;
            Tile      = tile;
            PixelMask = pixelMask;

            DeltaX  = 0;
            DeltaY  = 0;
            Stopped = false;
        }
Beispiel #4
0
 public void SetPixelMaskAt(int x, int y, PixelMask pixelMask, Dictionary <string, string> properties = null)
 {
     grid[y * Width + x] = new Tile(x, y, pixelMask, properties);
 }
Beispiel #5
0
 public Tile(int x, int y, PixelMask pixelMask, Dictionary <string, string> properties = null) : this(x, y, TileSolidType.PixelMask, properties)
 {
     PixelMask = pixelMask;
 }
Beispiel #6
0
        private bool CollidePixelMaskToPixelMask(float x, float y, float otherX, float otherY, PixelMask otherMask)
        {
            var otherOffsetX = (int)(otherX - x);
            var startX       = otherOffsetX;

            if (startX < 0)
            {
                startX = 0;
            }

            var otherOffsetY = (int)(otherY - y);
            var startY       = otherOffsetY;

            if (startY < 0)
            {
                startY = 0;
            }

            var endX = (int)(otherX + otherMask.WidthPx - x);

            if (endX > WidthPx)
            {
                endX = WidthPx;
            }

            var endY = (int)(otherY + otherMask.HeightPx - y);

            if (endY > HeightPx)
            {
                endY = HeightPx;
            }

            //Log.Debug("startX=" + startX + " startY=" + startY + " endX=" + endX + " endY=" + endY);

            for (var ix = startX; ix < endX; ix++)
            {
                for (var iy = startY; iy < endY; iy++)
                {
                    if (mask[ix, iy] && otherMask.mask[ix - otherOffsetX, iy - otherOffsetY])
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
Beispiel #7
0
 public static HitInfo CreateHit(Tile tile, PixelMask pixelMask = null)
 {
     return(new HitInfo(true, null, tile, pixelMask));
 }
Beispiel #8
0
 public static HitInfo CreateHit(Entity other = null, Tile tile = null, PixelMask pixelMask = null)
 {
     return(new HitInfo(true, other, tile, pixelMask));
 }