Exemplo n.º 1
0
        private static void DrawEnvironmentWithMirrorAndTurns(this IZone zone, Position position, EntityEnvironmentDescription description, int rotationTurns, bool flipX, bool flipY, BlockingFlags blockingFlag)
        {
            if (description.Equals(default(EntityEnvironmentDescription)))
            {
                return;
            }

            if (description.blocksTiles == null || description.blocksTiles.Count <= 0)
            {
                return;
            }

            var terrain        = zone.Terrain;
            var originAltitude = terrain.Altitude.GetAltitudeAsDouble(position);

            using (new TerrainUpdateMonitor(zone))
            {
                foreach (var tile in description.blocksTiles)
                {
                    var tx = tile.x;
                    var ty = tile.y;

                    if (flipX)
                    {
                        tx *= -1;
                    }

                    if (flipY)
                    {
                        ty *= -1;
                    }

                    var tilePos    = new Position(tx, ty);
                    var rotatedPos = Position.RotateCWWithTurns(tilePos, rotationTurns);

                    var offsetPosition = new Position(position.intX + rotatedPos.intX, position.intY + rotatedPos.intY);

                    if (!offsetPosition.IsValid(zone.Size))
                    {
                        continue;
                    }

                    zone.Terrain.Blocks.UpdateValue(offsetPosition, bi =>
                    {
                        var altitude = terrain.Altitude.GetAltitudeAsDouble(offsetPosition);
                        var altDiff  = (int)(altitude - originAltitude);
                        var resultingBlockingHeight = (byte)((tile.data - altDiff).Clamp(0, 255));
                        return(new BlockingInfo(blockingFlag, Math.Max(bi.Height, resultingBlockingHeight)));
                    });
                }
            }
        }
Exemplo n.º 2
0
        private static void CleanEnvironmentWithMirrorAndTurns(this IZone zone, Position position, EntityEnvironmentDescription description, int rotationTurns, bool flipX, bool flipY)
        {
            if (description.Equals(default(EntityEnvironmentDescription)))
            {
                return;
            }


            if (description.blocksTiles == null || description.blocksTiles.Count <= 0)
            {
                return;
            }

            var bi = new BlockingInfo();

            using (new TerrainUpdateMonitor(zone))
            {
                foreach (var tile in description.blocksTiles)
                {
                    var tx = tile.x;
                    var ty = tile.y;

                    if (flipX)
                    {
                        tx *= -1;
                    }

                    if (flipY)
                    {
                        ty *= -1;
                    }

                    var tilePos    = new Position(tx, ty);
                    var rotatedPos = Position.RotateCWWithTurns(tilePos, rotationTurns);

                    var offsetPosition = new Position(position.intX + rotatedPos.intX, position.intY + rotatedPos.intY);
                    if (offsetPosition.IsValid(zone.Size))
                    {
                        zone.Terrain.Blocks.SetValue(offsetPosition, bi);
                    }
                }
            }
        }
Exemplo n.º 3
0
        private static void CleanEnvironmentFromLayers(this IZone zone, Position position, EntityEnvironmentDescription description)
        {
            if (description.Equals(default(EntityEnvironmentDescription)))
            {
                return;
            }

            if (description.blocksTiles == null || description.blocksTiles.Count <= 0)
            {
                return;
            }

            foreach (var tile in description.blocksTiles)
            {
                var offsetPosition = new Position(position.intX + tile.x, position.intY + tile.y);
                if (!offsetPosition.IsValid(zone.Size))
                {
                    continue;
                }

                zone.Terrain.Blocks.SetValue(offsetPosition, new BlockingInfo());
            }
        }