Example #1
0
        public void Should_Return_Points_That_Contained_In_Dest_Area()
        {
            var srcArea = Area2D.Create(0, 0, 3, 3);

            var areas = new[]
            {
                new Tuple <Area2D, Area2D>(Area2D.Create(0, 0, 5, 5), srcArea),
                new Tuple <Area2D, Area2D>(Area2D.Create(4, 4, 6, 6), srcArea),
                new Tuple <Area2D, Area2D>(Area2D.Create(-3, -3, 6, 6), srcArea)
            };
            var areaMap = new Area2DMap(areas, _emptyArea);

            for (var i = 0; i < areaMap.DestElementsCount; i++)
            {
                var point = areaMap[i];
                var found = false;

                for (var j = 0; j < areas.Length; j++)
                {
                    var dest = areas[j].Item1;

                    if (dest.GetPointIndex(point) > -1)
                    {
                        found = true;
                        break;
                    }
                }

                found.ShouldBeTrue();
            }
        }
Example #2
0
        public void Should_Throw_ArgumentNullException_When_Area2_Is_Null()
        {
            var    a1 = Area2D.Create(0, 0, 0, 0);
            Area2D a2 = null;

            Should.Throw <ArgumentNullException>(() => a1.IsSameAs(a2));
        }
Example #3
0
        static void Main(string[] args)
        {
            const string basePath = "..\\..\\..\\..\\..\\..\\images";

            using (var bitmap = new Bitmap(Path.Combine(basePath, "pm2.png")))
                using (var mask2Bmp = new Bitmap(Path.Combine(basePath, "m007.png")))
                {
                    var mask0 = mask2Bmp.ToArea();
                    var rect  = Area2D.Create(mask0.Bound.X, mask0.Bound.Y, mask0.Bound.Width, mask0.Bound.Height);
                    var grect = rect.Dilation(3).Substract(rect);

                    var mask2 = mask2Bmp.ToArea()
                                .Translate(240, 80)
                                .Dilation(71);

                    var mask1 = mask2.Translate(mask2.Bound.Width / 3, mask2.Bound.Height / 2);
                    var mask3 = mask2.Translate(-mask2.Bound.Width / 3, mask2.Bound.Height / 2);

                    bitmap.ToRgbImage()
                    .SetComponentsValues(mask1, new[] { 1.0 }, 0)
                    .SetComponentsValues(mask2, new[] { 1.0 }, 1)
                    .SetComponentsValues(mask3, new[] { 1.0 }, 2)
                    .SetComponentsValues(grect, new[] { 1.0, 1.0, 1.0 }, 0)
                    .SetComponentsValues(mask0, new[] { 1.0, 1.0, 1.0 }, 0)
                    .FromRgbToBitmap()
                    .SaveTo("..\\..\\..\\output.png", ImageFormat.Png)
                    .ShowFile();
                }
        }
Example #4
0
    private void OnAreaEntered(Area2D area)
    {
        if (area.GetGroups().Contains("attacks"))
        {
            float swordFlow = (float)_player.GetSwordFlow();
            switch (area.Name)
            {
            case "sword":
                _health -= (int)Math.Round(10.0f + 40.0f * swordFlow / 100.0f);
                break;

            case "spinsword":
                _health -= (int)Math.Round(5.0f + 20.0f * swordFlow / 100.0f);
                break;

            case "pulse":
                _health -= (int)Math.Round(1.0f + 9.0f * swordFlow / 100.0f);
                Knockback(_player);
                break;

            case "spray_pulse":
                _health -= (int)Math.Round(2.0f + 13.0f * swordFlow / 100.0f);
                Knockback(_player);
                break;

            case "dash_sword":
                _health -= (int)Math.Round(7.0f + 33.0f * swordFlow / 100.0f);
                break;
            }
        }
    }
Example #5
0
        public void Should_Return_False_When_Area2_Is_Empty()
        {
            var a1 = Area2D.Create(12, 2, 10, 10);
            var a2 = Area2D.Create(0, 0, 0, 0);

            a1.IsSameAs(a2).ShouldBeFalse();
        }
Example #6
0
 public void OnEnable()
 {
     area2d                    = target as Area2D;
     Tools.hidden              = editMode;
     EditorApplication.update -= OnUpdate;
     EditorApplication.update += OnUpdate;
 }
Example #7
0
 public Area2DMap(Area2DMapState state)
 {
     _areas       = state.Areas.Select(t => new Tuple <Area2D, Area2D>(Area2D.RestoreFrom(t[0]), Area2D.RestoreFrom(t[1]))).ToArray();
     _outsideArea = Area2D.RestoreFrom(state.OutsideAreaState);
     _destArea    = Area2D.RestoreFrom(state.DestAreaState);
     _sourceArea  = Area2D.RestoreFrom(state.SourceAreaState);
 }
Example #8
0
        public void Should_Ignore_Donor_That_Reside_Within_Inpaint_Area()
        {
            var mock       = new Mock <IArea2DMapBuilder>();
            var mapBuilder = mock.Object;

            var imageArea = Area2D.Create(0, 0, 15, 15);

            var donor1   = Area2D.Create(3, 3, 2, 2);
            var inpaint1 = Area2D.Create(3, 3, 3, 3);

            mock.Setup(mb => mb.InitNewMap(imageArea, imageArea))
            .Returns(mapBuilder);
            mock.Setup(mb => mb.SetIgnoredSourcedArea(It.Is <Area2D>(d => d.IsSameAs(inpaint1))))
            .Returns(mapBuilder);
            mock.Setup(mb => mb.Build())
            .Returns((Area2DMap)null);

            var inpaintMapBuilder = new InpaintMapBuilder(mapBuilder);

            inpaintMapBuilder.InitNewMap(imageArea);
            inpaintMapBuilder.AddDonor(donor1);
            inpaintMapBuilder.SetInpaintArea(inpaint1);
            inpaintMapBuilder.Build();

            mock.VerifyAll();
        }
Example #9
0
        public void Should_Build_Proper_Mapping()
        {
            var testName = "InpaintMapBuilderTest";
            var ts       = TestSet.Init("256x128");

            // create map
            var mapBuilder = new InpaintMapBuilder();
            var imageArea  = Area2D.Create(0, 0, ts.Picture.Width, ts.Picture.Height);

            mapBuilder.InitNewMap(imageArea);
            var inpaintArea = ts.RemoveMarkup.ToArea();

            mapBuilder.SetInpaintArea(inpaintArea);

            for (int i = 0; i < ts.Donors.Count; i++)
            {
                var donorArea = ts.Donors[i].ToArea();
                mapBuilder.AddDonor(donorArea);
            }

            var sw = new Stopwatch();

            sw.Restart();
            var mapping = mapBuilder.Build();

            sw.Stop();

            // convert mapping to areas
            var areaPairs = (mapping as IAreasMapping).AssociatedAreasAsc;

            for (int i = 0; i < areaPairs.Length; i++)
            {
                var areaPair = areaPairs[i];

                SaveToOutput(areaPair.Item1, $"dest{i}", testName, ts.Path, Color.Red);
                SaveToOutput(areaPair.Item2, $"src{i}", testName, ts.Path, Color.Green);
            }

            // compare output and references
            string[] reffiles = Directory.GetFiles($"{ts.Path}\\{testName}\\refs", "*.*", SearchOption.TopDirectoryOnly);
            string[] outfiles = Directory.GetFiles($"{ts.Path}\\{testName}\\output", "*.*", SearchOption.TopDirectoryOnly);

            reffiles.Length.ShouldBe(outfiles.Length);

            if (reffiles.Length != outfiles.Length)
            {
                foreach (var refFilePath in reffiles)
                {
                    var refFileName = Path.GetFileName(refFilePath);
                    var outFilePath = $"{ts.Path}\\{testName}\\output\\{refFileName}";

                    File.Exists(outFilePath).ShouldBeTrue();

                    var refArea = new Bitmap(refFilePath).ToArea();
                    var outArea = new Bitmap(outFilePath).ToArea();

                    refArea.IsSameAs(outArea).ShouldBeTrue();
                }
            }
        }
 private void OnCollision(Area2D with)
 {
     if (with.GetParent() is Player player)
     {
         timer.Start(1);
     }
 }
 private void OnCollisionNoMore(Area2D with)
 {
     if (with.GetParent() is Player player)
     {
         timer.Stop();
     }
 }
Example #12
0
 public void _on_Area2D_area_entered(Area2D area)
 {
     if (area.GetCollisionLayerBit(2))
     {
         QueueFree();//Delete
     }
 }
Example #13
0
 public void _on_Area2D_area_entered(Area2D area)
 {
     if (area.GetCollisionLayerBit(2))
     {
         explode();
     }
 }
Example #14
0
        public void Should_Contain_Points_From_Dest_Areas()
        {
            var srcArea = Area2D.Create(0, 0, 3, 3);

            var areas = new[]
            {
                new Tuple <Area2D, Area2D>(Area2D.Create(0, 0, 5, 5), srcArea),
                new Tuple <Area2D, Area2D>(Area2D.Create(4, 4, 6, 6), srcArea),
                new Tuple <Area2D, Area2D>(Area2D.Create(-3, -3, 6, 6), srcArea)
            };
            var areaMap = new Area2DMap(areas, _emptyArea);

            for (var j = 0; j < areas.Length; j++)
            {
                var dest = areas[j].Item1;

                foreach (var destPoint in dest.Points)
                {
                    var found = false;

                    for (var i = 0; i < areaMap.DestElementsCount; i++)
                    {
                        var point = areaMap[i];

                        if (destPoint.X == point.X && destPoint.Y == point.Y)
                        {
                            found = true;
                        }
                    }

                    found.ShouldBeTrue();
                }
            }
        }
Example #15
0
        static void Main(string[] args)
        {
            const string basePath = "..\\..\\..\\..\\..\\..\\images";

            var bitmap1 = new Bitmap(Path.Combine(basePath, "pm1.png"));
            var image1  = bitmap1.ToRgbImage();

            bitmap1.Dispose();

            var bitmap2 = new Bitmap(Path.Combine(basePath, "pm2.png"));
            var image2  = bitmap2.ToRgbImage();

            bitmap2.Dispose();

            var bitmap3 = new Bitmap(Path.Combine(basePath, "pm2_m.png"));
            var srcArea = bitmap3.ToArea();

            bitmap3.Dispose();

            var dstArea = Area2D.Create(image2.Width / 2, 50, image2.Width / 2, image2.Height);

            image1
            .CopyFromImage(dstArea, image2, srcArea)
            .FromRgbToBitmap()
            .SaveTo(@"..\..\..\out.png", ImageFormat.Png)
            .ShowFile();
        }
Example #16
0
        public void Should_Build_Proper_Mapping_Fast()
        {
            var ts = TestSet.Init("1280x720");

            // create map
            var mapBuilder = new InpaintMapBuilder();
            var imageArea  = Area2D.Create(0, 0, ts.Picture.Width, ts.Picture.Height);

            mapBuilder.InitNewMap(imageArea);
            var inpaintArea = ts.RemoveMarkup.ToArea();

            mapBuilder.SetInpaintArea(inpaintArea);

            for (int i = 0; i < ts.Donors.Count; i++)
            {
                var donorArea = ts.Donors[i].ToArea();
                mapBuilder.AddDonor(donorArea);
            }

            var sw = new Stopwatch();

            sw.Restart();
            mapBuilder.Build();
            sw.Stop();

            sw.ElapsedMilliseconds.ShouldBeLessThan(800);
        }
Example #17
0
 public void OnAreaEnter(Area2D area)
 {
     _target = (Circle)area;
     // _target.GetNode<Node2D>("Pivot").Rotation = (Position - _target.Position).Angle();
     velocity = Vector2.Zero;
     EmitSignal(nameof(OnCapture), _target);
 }
Example #18
0
        public void Should_Extract_Source_And_Dest_Areas_From_Donor()
        {
            var mock       = new Mock <IArea2DMapBuilder>();
            var mapBuilder = mock.Object;
            var imageArea  = Area2D.Create(0, 0, 15, 15);

            var donor1  = Area2D.Create(0, 3, 8, 3);
            var inpaint = Area2D.Create(3, 3, 3, 3);

            var srcArea = Area2D.Create(0, 3, 3, 3).Join(Area2D.Create(6, 3, 2, 3));
            var dstArea = Area2D.Create(3, 3, 3, 3);

            mock.Setup(mb => mb.InitNewMap(imageArea, imageArea))
            .Returns(mapBuilder);
            mock.Setup(mb => mb.SetIgnoredSourcedArea(It.Is <Area2D>(d => d.IsSameAs(inpaint))))
            .Returns(mapBuilder);
            mock.Setup(mb => mb.AddAssociatedAreas(It.Is <Area2D>(d => d.IsSameAs(dstArea)),
                                                   It.Is <Area2D>(d => d.IsSameAs(srcArea))))
            .Returns(mapBuilder);
            mock.Setup(mb => mb.Build())
            .Returns(default(Area2DMap));

            var inpaintMapBuilder = new InpaintMapBuilder(mapBuilder);

            inpaintMapBuilder.InitNewMap(imageArea);
            inpaintMapBuilder.AddDonor(donor1);
            inpaintMapBuilder.SetInpaintArea(inpaint);
            inpaintMapBuilder.Build();

            mock.VerifyAll();
        }
Example #19
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Area2DMap" /> class.
        /// </summary>
        /// <param name="areas">The array of area tuples which are Dest Area and Source Area.</param>
        /// <param name="outsideArea">The area to map points that area not mapped.</param>
        /// <exception cref="System.ArgumentNullException">
        /// </exception>
        /// <exception cref="EmptyAreaException"></exception>
        /// <remarks>
        /// - Dest areas and Source areas can not be nither null nor empty.
        /// - In a case when dest areas have common point, the source area of the last dest area is associated with the points.
        /// - Outside area can not be null.
        /// </remarks>
        // NOTE: It is IMPORTANT that the constructor of this class is INTERNAL. This constructor is not allowed to
        // be called by a client code. Someone should control the allowence of empty areas in the mapping. Now  the
        // builder class requires from the client to allow it implicitly.
        internal Area2DMap(Tuple <Area2D, Area2D>[] areas, Area2D outsideArea)
        {
            if (areas == null)
            {
                throw new ArgumentNullException(nameof(areas));
            }

            if (outsideArea == null)
            {
                throw new ArgumentNullException(nameof(outsideArea));
            }

            if (areas.Any(a => a.Item2 == null || a.Item1 == null))
            {
                throw new ArgumentNullException();
            }

            //NOTE: The requirement below is no longer valid since the dest can be allowed to get reduced to
            // an empty area by the client of the builder class implicitly and than the client is responsible
            // for handling of this case.
            //if (areas.Any(a => a.Item2.IsEmpty || a.Item1.IsEmpty))
            //    throw new EmptyAreaException();

            _areas       = areas;
            _outsideArea = outsideArea;
            _destArea    = areas.Aggregate(Area2D.Empty, (current, t) => current.Join(t.Item1));
            _sourceArea  = areas.Aggregate(Area2D.Empty, (current, t) => current.Join(t.Item2));
        }
Example #20
0
    public override void _Ready()
    {
        collisionPolygone = (CollisionPolygon2D)FindNode("CollisionPolygon2D");
        area = (Area2D)FindNode("Area2D");

        _player = (AudioStreamPlayer)FindNode("AudioStreamPlayer");
    }
Example #21
0
 private void _on_Hitbox_area_entered(Area2D area)
 {
     if (area.IsInGroup("light"))
     {
         ChangeState("Weakened");
     }
 }
Example #22
0
    private void MoveCharacter(float speed, Area2D _char, int i)
    {
        var lastPosition = _char.Position;

        if (_paths[i] == null)
        {
            return;
        }
        for (var x = 0; x < _paths[i].Length; x++)
        {
            var distanceBetweenPoints = lastPosition.DistanceTo(_paths[i][x]);
            if (speed <= distanceBetweenPoints)
            {
                _char.Position = lastPosition.LinearInterpolate(_paths[i][x], speed / distanceBetweenPoints);
                break;
            }

            if (speed < 0.0)
            {
                _char.Position = _paths[i][0];
                moveNode[i]    = false;
                break;
            }

            speed       -= distanceBetweenPoints;
            lastPosition = _paths[i][x];
            _paths[i]    = _paths[i].Skip(1).Take(_paths[i].Length - 1).ToArray();
        }
    }
Example #23
0
        public void Should_Return_True_When_Both_Are_Empty()
        {
            var a1 = Area2D.Create(0, 0, 0, 0);
            var a2 = Area2D.Create(12, 2, 0, 10);

            a1.IsSameAs(a2).ShouldBeTrue();
        }
Example #24
0
        public void Should_Return_Correct_Number_Of_Elements(int x, int y, byte[] r1, byte[] r2, byte[] r3, byte[] r4, byte[] r5, int result)
        {
            var markup = new[] { r1, r2, r3, r4, r5 };
            var area   = Area2D.Create(x, y, markup);

            area.ElementsCount.ShouldBe(result);
        }
Example #25
0
        public void Should_Return_False_When_Area2_Contains_Additional_Points()
        {
            var a1 = Area2D.Create(0, 0,
                                   new[]
            {
                new byte[] { 0, 0, 0, 0, 0, 0, 0 },
                new byte[] { 0, 1, 1, 0, 0, 0, 0 },
                new byte[] { 0, 1, 0, 1, 0, 0, 0 },
                new byte[] { 0, 1, 0, 0, 0, 0, 0 },
                new byte[] { 0, 0, 0, 0, 0, 0, 0 },
                new byte[] { 0, 0, 0, 0, 0, 0, 0 },
                new byte[] { 0, 1, 1, 1, 0, 1, 0 },
                new byte[] { 0, 0, 0, 0, 0, 1, 0 },
                new byte[] { 0, 0, 0, 0, 0, 0, 0 },
            });

            var a2 = Area2D.Create(0, 0,
                                   new[]
            {
                new byte[] { 0, 0, 0, 0, 0, 0, 0 },
                new byte[] { 0, 1, 1, 0, 0, 0, 0 },
                new byte[] { 0, 1, 0, 1, 0, 0, 0 },
                new byte[] { 0, 1, 0, 0, 0, 1, 0 },
                new byte[] { 0, 0, 0, 0, 0, 0, 0 },
                new byte[] { 0, 0, 0, 0, 0, 0, 0 },
                new byte[] { 0, 1, 1, 1, 0, 1, 0 },
                new byte[] { 0, 0, 0, 0, 0, 1, 0 },
                new byte[] { 0, 0, 0, 0, 0, 0, 0 },
            });


            a1.IsSameAs(a2).ShouldBeFalse();
        }
        public void Should_Create_An_Instance_Of_Area2D(int x, int y, byte[] r1, byte[] r2, byte[] r3, byte[] r4, byte[] r5)
        {
            var markup = new[] { r1, r2, r3, r4, r5 };
            var area   = new Area2D(x, y, markup);

            area.ShouldBeOfType <Area2D>();
        }
Example #27
0
    public void _OnHurtAreaEnter(Area2D hurtArea)
    {
        // Setup explosion
        if (++pierces >= maxPierces)
        {
            smokeTrailEmitter.Emitting       = false;
            smokeTrailEmitter.Scale          = new Vector2(0, 0);
            fireTrailEmitter.Emitting        = false;
            explosionEmitter.Emitting        = true;
            explosionEmitter.ProcessMaterial = explosionMaterial;
            explosionMaterial.Gravity        = new Vector3(velocity / 2, 0f, 0f);
            exploded       = true;
            sprite.Visible = false;
            hitArea.QueueFree();
            explosionCompleteTimer.Start();
            initialBoomVelocityTimer.Start();
        }

        // Affect target(s)
        foreach (Enemy target in GetTree().GetNodesInGroup("Enemies"))
        {
            if (Position.DistanceTo(target.Position) < effectRadius)
            {
                target.Damage(damage, GlobalPosition.DirectionTo(target.GlobalPosition) * knockbackStrength);
            }
        }
    }
Example #28
0
 private void OnAreaEntered(Area2D area)
 {
     if (area.IsInGroup(GameConstants.ActionRadiusGroup))
     {
         treeActionRadiusList.Add(area);
     }
 }
Example #29
0
 public void _on_ShotgunBullet_body_entered(Area2D body)
 {
     if (!body.IsInGroup("enemy") && !body.IsInGroup("playerBullet"))
     {
         QueueFree();
     }
 }
Example #30
0
        public void Should_Throw_IndexOutOfRangeException_When_Index_Greater_Than_DestElementsCount()
        {
            var areas = new[] { new Tuple <Area2D, Area2D>(Area2D.Create(0, 0, 10, 10), Area2D.Create(0, 0, 10, 10)) };
            var map   = new Area2DMap(areas, _emptyArea);

            Should.Throw <IndexOutOfRangeException>(() => { var p = map[100]; });
        }