コード例 #1
0
        public void Collision_FloatingPointError_StillWorks()
        {
            var hitbox = new CollisionBox(-7.5f, -9f, 15, 21);

            hitbox.Name        = "Test";
            hitbox.Environment = true;
            hitbox.PushAway    = true;
            _position.SetPosition(5f, 115.999992f);
            _collision.AddBox(hitbox);
            _collision.Message(new HitBoxMessage(EntityMock.Object, new List <CollisionBox>(), new HashSet <string>()
            {
                "Test"
            }, false));

            var layer = new Mock <IScreenLayer>();

            layer.SetupGet(l => l.Stage).Returns(Container);

            var tileset = new Common.Tileset()
            {
                TileSize = 16
            };
            var backTile    = new Common.Tile(1, new Common.TileSprite(tileset));
            var blankSquare = new MapSquare(layer.Object, backTile, 0, 0, 16);

            Screen.Setup(s => s.SquareAt(It.IsAny <float>(), It.IsAny <float>())).Returns(blankSquare);


            var blockTile = new Common.Tile(2, new Common.TileSprite(tileset));

            blockTile.Properties = new Common.TileProperties()
            {
                Blocking = true
            };
            var blockSquare = new MapSquare(layer.Object, blockTile, 0, 8, 16);

            Screen.Setup(s => s.SquareAt(It.IsInRange <float>(0, 16, Range.Inclusive), It.IsInRange <float>(128, 144, Range.Inclusive))).Returns(blockSquare);

            Assert.IsFalse(_collision.BlockBottom);

            Container.Tick();

            Assert.IsTrue(_collision.BlockBottom);

            Container.Tick();

            Assert.IsTrue(_collision.BlockBottom);

            Container.Tick();

            Assert.IsTrue(_collision.BlockBottom);
        }
コード例 #2
0
        private double GetTileDifferenceScore(WriteableBitmap image, Common.Tile tile)
        {
            var frame = SpriteBitmapCache.GetOrLoadFrame(Stage.Tileset.SheetPath.Absolute, tile.Sprite[0].SheetLocation);

            var scores = new List <int>();

            for (var y = 0; y < frame.PixelHeight; y++)
            {
                for (var x = 0; x < frame.PixelWidth; x++)
                {
                    var imgPixel   = image.GetPixel(x, y);
                    var framePixel = frame.GetPixel(x, y);
                    scores.Add((imgPixel.R - framePixel.R) + (imgPixel.G - framePixel.G) + (imgPixel.B - framePixel.B));
                }
            }

            return(Math.Abs(scores.Average()));
        }
コード例 #3
0
        public void Collision_FloatingPointError_StillWorks()
        {
            var hitbox = new CollisionBox(-7.5f, -9f, 15, 21);
            hitbox.Name = "Test";
            hitbox.Environment = true;
            hitbox.PushAway = true;
            _position.SetPosition(5f, 115.999992f);
            _collision.AddBox(hitbox);
            _collision.Message(new HitBoxMessage(EntityMock.Object, new List<CollisionBox>(), new HashSet<string>() { "Test" }, false));

            var layer = new Mock<IScreenLayer>();
            layer.SetupGet(l => l.Stage).Returns(Container);

            var tileset = new Common.Tileset() { TileSize = 16 };
            var backTile = new Common.Tile(1, new Common.TileSprite(tileset));
            var blankSquare = new MapSquare(layer.Object, backTile, 0, 0, 16);

            Screen.Setup(s => s.SquareAt(It.IsAny<float>(), It.IsAny<float>())).Returns(blankSquare);

            var blockTile = new Common.Tile(2, new Common.TileSprite(tileset));
            blockTile.Properties = new Common.TileProperties() { Blocking = true };
            var blockSquare = new MapSquare(layer.Object, blockTile, 0, 8, 16);

            Screen.Setup(s => s.SquareAt(It.IsInRange<float>(0, 16, Range.Inclusive), It.IsInRange<float>(128, 144, Range.Inclusive))).Returns(blockSquare);

            Assert.IsFalse(_collision.BlockBottom);

            Container.Tick();

            Assert.IsTrue(_collision.BlockBottom);

            Container.Tick();

            Assert.IsTrue(_collision.BlockBottom);

            Container.Tick();

            Assert.IsTrue(_collision.BlockBottom);
        }