コード例 #1
0
        public override void Render()
        {
            if (visibleOnCamera)
            {
                if (water == null || water.TopSurface == null)
                {
                    Draw.Rect(X + 1f, Y, 6f, height, fillColor);
                    Draw.Rect(X - 1f, Y, 2f, height, surfaceColor);
                    Draw.Rect(X + 7f, Y, 2f, height, surfaceColor);
                }
                else
                {
                    Water.Surface topSurface = water.TopSurface;
                    float         num        = height + water.TopSurface.Position.Y - water.Y;

                    for (int index = 0; index < 6; ++index)
                    {
                        Draw.Rect((float)(X + index + 1f), Y, 1f, num - topSurface.GetSurfaceHeight(new Vector2(X + 1f + index, water.Y)), fillColor);
                    }

                    Draw.Rect(X - 1f, Y, 2f, num - topSurface.GetSurfaceHeight(new Vector2(X, water.Y)), surfaceColor);
                    Draw.Rect(X + 7f, Y, 2f, num - topSurface.GetSurfaceHeight(new Vector2(X + 8f, water.Y)), surfaceColor);
                }
            }
        }
コード例 #2
0
ファイル: ColoredWater.cs プロジェクト: Cruor/PandorasBox
        // Swap around surfaces to make sure the base Update method doesn't waste cycles on non visible water
        // Use dummy surfaces to not crash vanilla waterfall
        private void updateSurfaceVisibility()
        {
            Surfaces      = visibleOnCamera ? actualSurfaces : emptySurfaces;
            TopSurface    = visibleOnCamera ? actualTopSurface : dummyTopSurface;
            BottomSurface = visibleOnCamera ? actualBottomSurface : dummyBottomSurface;
            LeftSurface   = visibleOnCamera ? actualLeftSurface : dummyLeftSurface;
            RightSurface  = visibleOnCamera ? actualRightSurface : dummyRightSurface;

            if (!visibleOnCamera)
            {
                dummyTopSurface?.Ripples?.Clear();
                dummyBottomSurface?.Ripples?.Clear();
                dummyLeftSurface?.Ripples?.Clear();
                dummyRightSurface?.Ripples?.Clear();
            }
        }
コード例 #3
0
        private void fixSurfaces()
        {
            if (!fixedSurfaces)
            {
                Color origFill    = Water.FillColor;
                Color origSurface = Water.SurfaceColor;

                changeColor(fillColorField, origFill, fillColor);
                changeColor(surfaceColorField, origSurface, surfaceColor);

                bool hasTop    = Surfaces.Contains(TopSurface);
                bool hasBottom = Surfaces.Contains(BottomSurface);

                Surfaces.Clear();

                if (hasTop)
                {
                    TopSurface = new Water.Surface(Position + new Vector2(Width / 2f, 8f), new Vector2(0.0f, -1f), Width, Height);
                    Surfaces.Add(TopSurface);

                    actualTopSurface = TopSurface;
                    dummyTopSurface  = new Water.Surface(Position + new Vector2(Width / 2f, 8f), new Vector2(0.0f, -1f), Width, Height);
                }

                if (hasBottom)
                {
                    BottomSurface = new Water.Surface(Position + new Vector2(Width / 2f, Height - 8f), new Vector2(0.0f, 1f), Width, Height);
                    Surfaces.Add(BottomSurface);

                    actualBottomSurface = BottomSurface;
                    dummyBottomSurface  = new Water.Surface(Position + new Vector2(Width / 2f, Height - 8f), new Vector2(0.0f, 1f), Width, Height);
                }

                fixedSurfaces  = true;
                actualSurfaces = Surfaces;
                emptySurfaces  = new List <Surface>();

                changeColor(fillColorField, fillColor, origFill);
                changeColor(surfaceColorField, surfaceColor, origSurface);
            }
        }
コード例 #4
0
ファイル: ColoredWater.cs プロジェクト: Cruor/PandorasBox
        private void initializeSurfaces()
        {
            Color origFill    = Water.FillColor;
            Color origSurface = Water.SurfaceColor;

            changeColor(fillColorField, origFill, fillColor);
            changeColor(surfaceColorField, origSurface, surfaceColor);

            bool hasTop    = Surfaces.Contains(TopSurface);
            bool hasBottom = Surfaces.Contains(BottomSurface);

            Surfaces.Clear();

            if (hasTop)
            {
                TopSurface = new Water.Surface(Position + new Vector2(Width / 2f, 8f), new Vector2(0.0f, -1f), Width, Height);
                Surfaces.Add(TopSurface);

                actualTopSurface = TopSurface;
                dummyTopSurface  = new Water.Surface(Position + new Vector2(Width / 2f, 8f), new Vector2(0.0f, -1f), Width, Height);
            }

            if (hasBottom)
            {
                BottomSurface = new Water.Surface(Position + new Vector2(Width / 2f, Height - 8f), new Vector2(0.0f, 1f), Width, Height);
                Surfaces.Add(BottomSurface);

                actualBottomSurface = BottomSurface;
                dummyBottomSurface  = new Water.Surface(Position + new Vector2(Width / 2f, Height - 8f), new Vector2(0.0f, 1f), Width, Height);
            }

            if (hasLeftSurface)
            {
                LeftSurface = new Water.Surface(Position + new Vector2(8, Height / 2), new Vector2(-1f, 0f), Height, Width);
                Surfaces.Add(LeftSurface);

                actualLeftSurface = LeftSurface;
                dummyLeftSurface  = new Water.Surface(Position + new Vector2(8, Height / 2), new Vector2(-1f, 0f), Height, Width);
            }

            if (hasRightSurface)
            {
                RightSurface = new Water.Surface(Position + new Vector2(Width - 8, Height / 2), new Vector2(1f, 0f), Height, Width);
                Surfaces.Add(RightSurface);

                actualRightSurface = RightSurface;
                dummyRightSurface  = new Water.Surface(Position + new Vector2(Width - 8, Height / 2), new Vector2(1f, 0f), Height, Width);
            }

            // Update fill rectangle
            if (!hasUpdatedFill && (hasLeftSurface || hasRightSurface))
            {
                Rectangle fill     = (Rectangle)fillField.GetValue(this);
                int       newX     = fill.X;
                int       newWidth = fill.Width;

                if (hasLeftSurface)
                {
                    newX     += 8;
                    newWidth -= 8;
                }

                if (hasRightSurface)
                {
                    newWidth -= 8;
                }

                Rectangle newFill = new Rectangle(newX, fill.Y, newWidth, fill.Height);

                fillField.SetValue(this, newFill);

                hasUpdatedFill = true;
            }

            actualSurfaces = Surfaces;
            emptySurfaces  = new List <Surface>();

            changeColor(fillColorField, fillColor, origFill);
            changeColor(surfaceColorField, surfaceColor, origSurface);
        }