Пример #1
0
        private void AssertBounds2CellCollides(DummyCell cell1, DummyCell cell2, float dx, float dy, bool collides)
        {
            float px = cell1.px;
            float py = cell2.py;

            cell1.SetPos(px - dx, py - dy);
            Assert.AreEqual(collides, cell1.CheckBounds2CellCollision(cell2));

            cell1.SetPos(px, py - dy);
            Assert.AreEqual(collides, cell1.CheckBounds2CellCollision(cell2));

            cell1.SetPos(px + dx, py - dy);
            Assert.AreEqual(collides, cell1.CheckBounds2CellCollision(cell2));

            cell1.SetPos(px + dx, py);
            Assert.AreEqual(collides, cell1.CheckBounds2CellCollision(cell2));

            cell1.SetPos(px + dx, py + dy);
            Assert.AreEqual(collides, cell1.CheckBounds2CellCollision(cell2));

            cell1.SetPos(px, py + dy);
            Assert.AreEqual(collides, cell1.CheckBounds2CellCollision(cell2));

            cell1.SetPos(px - dx, py + dy);
            Assert.AreEqual(collides, cell1.CheckBounds2CellCollision(cell2));

            cell1.SetPos(px - dx, py);
            Assert.AreEqual(collides, cell1.CheckBounds2CellCollision(cell2));

            cell1.SetPos(px, py);
        }
        public void TestBounds2CellCollision()
        {
            DummyCell cell1 = new DummyCell(2, 2);
            DummyCell cell2 = new DummyCell(2, 2);

            Assert.IsTrue(cell1.CheckBounds2CellCollision(cell2));

            float dx = 0.25f * Constant.CELL_WIDTH;
            float dy = 0.25f * Constant.CELL_HEIGHT;

            AssertBounds2CellCollides(cell1, cell2, dx, dy, true);

            dx = 0.5f * Constant.CELL_WIDTH;
            dy = 0.5f * Constant.CELL_HEIGHT;

            AssertBounds2CellCollides(cell1, cell2, dx, dy, true);

            dx = 0.75f * Constant.CELL_WIDTH;
            dy = 0.75f * Constant.CELL_HEIGHT;

            AssertBounds2CellCollides(cell1, cell2, dx, dy, true);

            dx = Constant.CELL_WIDTH;
            dy = Constant.CELL_HEIGHT;

            AssertBounds2CellCollides(cell1, cell2, dx, dy, false);

            dx = 1.25f * Constant.CELL_WIDTH;
            dy = 1.25f * Constant.CELL_HEIGHT;

            AssertBounds2CellCollides(cell1, cell2, dx, dy, false);
        }
Пример #3
0
        public void TestBounds2CellCollision()
        {
            DummyCell cell1 = new DummyCell(2, 2);
            DummyCell cell2 = new DummyCell(2, 2);

            Assert.IsTrue(cell1.CheckBounds2CellCollision(cell2));

            float dx = 0.25f * Constant.CELL_WIDTH;
            float dy = 0.25f * Constant.CELL_HEIGHT;

            AssertBounds2CellCollides(cell1, cell2, dx, dy, true);

            dx = 0.5f * Constant.CELL_WIDTH;
            dy = 0.5f * Constant.CELL_HEIGHT;

            AssertBounds2CellCollides(cell1, cell2, dx, dy, true);

            dx = 0.75f * Constant.CELL_WIDTH;
            dy = 0.75f * Constant.CELL_HEIGHT;

            AssertBounds2CellCollides(cell1, cell2, dx, dy, true);

            dx = Constant.CELL_WIDTH;
            dy = Constant.CELL_HEIGHT;

            AssertBounds2CellCollides(cell1, cell2, dx, dy, false);

            dx = 1.25f * Constant.CELL_WIDTH;
            dy = 1.25f * Constant.CELL_HEIGHT;

            AssertBounds2CellCollides(cell1, cell2, dx, dy, false);
        }
        private void AssertBounds2CellCollides(DummyCell cell1, DummyCell cell2, float dx, float dy, bool collides)
        {
            float px = cell1.px;
            float py = cell2.py;

            cell1.SetPos(px - dx, py - dy);
            Assert.AreEqual(collides, cell1.CheckBounds2CellCollision(cell2));

            cell1.SetPos(px, py - dy);
            Assert.AreEqual(collides, cell1.CheckBounds2CellCollision(cell2));

            cell1.SetPos(px + dx, py - dy);
            Assert.AreEqual(collides, cell1.CheckBounds2CellCollision(cell2));

            cell1.SetPos(px + dx, py);
            Assert.AreEqual(collides, cell1.CheckBounds2CellCollision(cell2));

            cell1.SetPos(px + dx, py + dy);
            Assert.AreEqual(collides, cell1.CheckBounds2CellCollision(cell2));

            cell1.SetPos(px, py + dy);
            Assert.AreEqual(collides, cell1.CheckBounds2CellCollision(cell2));

            cell1.SetPos(px - dx, py + dy);
            Assert.AreEqual(collides, cell1.CheckBounds2CellCollision(cell2));

            cell1.SetPos(px - dx, py);
            Assert.AreEqual(collides, cell1.CheckBounds2CellCollision(cell2));

            cell1.SetPos(px, py);
        }