示例#1
0
        public void CalculateTransforms_BeforeCollisionCheck()
        {
            SceneGraph graph = BuildSceneGraph();
            Vector2 parentPosition = new Vector2(32, 64);
            GameObject obj = new GameObject();
            obj.Position = parentPosition;
            obj.NoClip = false;
            obj.SetCollisionSize(16, 16);

            Vector2 childPosition = new Vector2(96, 128);
            GameObject childObj = new GameObject();
            childObj.Position = childPosition;
            childObj.NoClip = false;
            childObj.SetCollisionSize(16, 16);

            obj.AddChild(childObj);

            GameObjectCounter collisionObj = new GameObjectCounter();
            collisionObj.Position = parentPosition + childPosition;
            collisionObj.NoClip = false;
            collisionObj.SetCollisionSize(16, 16);

            graph.Add(obj);
            graph.Add(collisionObj);
            graph.Update();

            Assert.That(collisionObj.Stats.CollisionCount, Is.EqualTo(1));
        }
示例#2
0
        public void LockToMap_OnlyFirstLevelNodes()
        {
            SceneGraph graph = BuildSceneGraph();
            GameObject obj = new GameObject();
            obj.NoClip = false;
            obj.Position = new Vector2(32, 32);
            obj.SetCollisionSize(16, 16);
            graph.Add(obj);

            Vector2 offScreenPosition = new Vector2(-300, -300);
            GameObject offScreen = new GameObject();
            offScreen.NoClip = false;
            offScreen.Position = offScreenPosition;
            offScreen.SetCollisionSize(16, 16);

            obj.AddChild(offScreen);

            graph.Update();

            Assert.That(offScreen.AbsolutePosition, Is.EqualTo(offScreenPosition + obj.Position));
            Assert.That(offScreen.Position, Is.EqualTo(offScreenPosition));
        }
示例#3
0
        public void LockToMap_BeforeCollisionCheck()
        {
            SceneGraph graph = BuildSceneGraph();
            GameObjectCounter obj = new GameObjectCounter();
            obj.NoClip = false;
            obj.Position = new Vector2(0, 0);
            obj.SetCollisionSize(16, 16);
            graph.Add(obj);

            GameObject offScreen = new GameObject();
            offScreen.NoClip = false;
            offScreen.Position = new Vector2(-32, -32);
            offScreen.SetCollisionSize(16, 16);
            graph.Add(offScreen);

            //LockToMap should be called before collision checking
            graph.Update();

            Assert.That(obj.Stats.CollisionCount, Is.EqualTo(1));
        }
示例#4
0
        public void SetCollisionSize()
        {
            GameObject obj = new GameObject();
            obj.Position = new Vector2(32, 64);
            obj.SetCollisionSize(32, 32);

            Rectangle expected = new Rectangle(32, 64, 32, 32);
            Assert.That(obj.CollisionBounds == expected);
        }
示例#5
0
        public void Intersects_False()
        {
            GameObject obj1 = new GameObject() { NoClip = false };
            obj1.SetCollisionSize(32, 32);
            obj1.Position = new Vector2(128f, 128f);
            GameObject obj2 = new GameObject() { NoClip = false };
            obj2.SetCollisionSize(32, 32);
            obj2.Position = new Vector2(32f, 32f);

            Assert.That(!obj1.Intersects(obj2));
            Assert.That(!obj2.Intersects(obj1));
        }
示例#6
0
        public void Intersects_CallOnCollision()
        {
            GameObjectCounter obj1 = new GameObjectCounter() { NoClip = false };
            obj1.SetCollisionSize(32, 32);
            GameObject obj2 = new GameObject() { NoClip = false };
            obj2.SetCollisionSize(32, 32);

            obj1.OnObjectCollision(obj2);

            Assert.That(obj1.Stats.CollisionCount, Is.EqualTo(1));
        }
示例#7
0
        public void Intersects()
        {
            GameObject obj1 = new GameObject() { NoClip = false };
            obj1.SetCollisionSize(32, 32);
            GameObject obj2 = new GameObject() { NoClip = false };
            obj2.SetCollisionSize(32, 32);

            Assert.That(obj1.Intersects(obj2));
            Assert.That(obj2.Intersects(obj1));
        }