Esempio n. 1
0
        public void DrawMaskXZSolidRange(TransformedMaskData tmd, int startY, int endY, SortedList <int, Color> heightColorGradient)
        {
            // NOTE: Draw back-to-front
            for (int maskZ = tmd.maskData.StartY; maskZ < tmd.maskData.EndY; maskZ++)
            {
                for (int maskX = tmd.maskData.StartX; maskX < tmd.maskData.EndX; maskX++)
                {
                    const int zTestOffset = 1; // <- The top surface should be "under" any other pixels
                    if (tmd[maskX, maskZ])
                    {
                        DrawPixel(new Position(maskX, endY, maskZ),
                                  heightColorGradient.GetColorFromGradient(endY), zTestOffset);

                        if (maskZ > tmd.maskData.StartY && tmd[maskX, maskZ - 1])
                        {
                            continue; // Previous row covers this one's "solid" section
                        }
                        for (int h = startY; h < endY; h++)
                        {
                            Color c = Color.Lerp(heightColorGradient.GetColorFromGradient(h), Color.Black, 0.6f);
                            DrawPixel(new Position(maskX, h, maskZ), c, 0);
                        }
                    }
                }
            }
        }
Esempio n. 2
0
        public void DrawMaskBlend(TransformedMaskData tmd, Color foreground, Color background)
        {
            for (int maskY = tmd.maskData.StartY; maskY < tmd.maskData.EndY; maskY++)
            {
                for (int maskX = tmd.maskData.StartX; maskX < tmd.maskData.EndX; maskX++)
                {
                    int x = tmd.flipX ? -maskX : maskX;
                    int y = -maskY - 1; // Convert World to Display coordinates

                    // Translate into buffer region
                    x -= displayBounds.X;
                    y -= displayBounds.Y;

                    Color color = tmd.maskData[maskX, maskY] ? foreground : background;

                    // Bounds check:
                    if ((uint)x < (uint)displayBounds.Width && (uint)y < (uint)displayBounds.Height)
                    {
                        int i = x + y * displayBounds.Width;

                        // Blend (would rather avoid floating point here, but oh well)
                        Vector4 source      = color.ToVector4();
                        Vector4 destination = colorBuffer[i].ToVector4();
                        float   alpha       = (float)color.A / 255f;
                        colorBuffer[i] = new Color(source + destination * (1f - alpha));

                        dirty = true;
                    }
                }
            }
        }
Esempio n. 3
0
 public void DrawMaskXZ(TransformedMaskData tmd, int y, Color color)
 {
     for (int maskZ = tmd.maskData.StartY; maskZ < tmd.maskData.EndY; maskZ++)
     {
         for (int maskX = tmd.maskData.StartX; maskX < tmd.maskData.EndX; maskX++)
         {
             const int zTestOffset = 1; // <- The top surface should be "under" any other pixels
             if (tmd[maskX, maskZ])
             {
                 DrawPixel(new Position(maskX, y, maskZ), color, zTestOffset); // <- NOTE: Use of Y value as Z value (and
             }
         }
     }
 }
Esempio n. 4
0
        public static bool Collide(TransformedMaskData a, TransformedMaskData b)
        {
            Rectangle aRect        = a.Bounds;
            Rectangle bRect        = b.Bounds;
            Rectangle intersection = Rectangle.Intersect(aRect, bRect);

            for (int iy = 0; iy < intersection.Height; iy++)
            {
                for (int ix = 0; ix < intersection.Width; ix++)
                {
                    int x = ix + intersection.X;
                    int y = iy + intersection.Y;
                    if (a[x, y] & b[x, y])
                    {
                        return(true); // Masks collide
                    }
                }
            }

            return(false);
        }
Esempio n. 5
0
 public bool CollidesWith(TransformedMaskData other)
 {
     return(Collide(this, other));
 }