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));
        }
        public override void GameObject_ObjectCollision(GameObject sender, GameObjectCollisionEventArgs e)
        {
            GameObjectCounter obj = new GameObjectCounter();
            obj.NoClip = true;
            obj.Position = this.Position;
            SceneGraph.Add(obj);

            base.GameObject_ObjectCollision(sender, e);
        }
Exemple #3
0
        public override void GameObject_ObjectCollision(GameObject sender, GameObjectCollisionEventArgs e)
        {
            GameObjectCounter obj = new GameObjectCounter();

            obj.NoClip   = true;
            obj.Position = this.Position;
            SceneGraph.Add(obj);

            base.GameObject_ObjectCollision(sender, e);
        }
        public void SpawnAtMe_Position()
        {
            SceneGraph graph = BuildSceneGraph();
            Vector2 objPosition = new Vector2(32, 64);
            GameObjectCounter obj = new GameObjectCounter();
            obj.Position = objPosition;

            GameObject childObj = new GameObject();
            childObj.Position = new Vector2(16, 16);
            childObj.SceneGraph = graph;
            obj.AddChild(childObj);

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

            GameObjectCounter spawn = new GameObjectCounter();
            childObj.SpawnAtMe(spawn);

            graph.Update();

            Assert.That(spawn.Position, Is.EqualTo(childObj.AbsolutePosition));
            Assert.That(spawn.Position, Is.EqualTo(new Vector2(48f, 80f)));
        }
        public void Update_CollisionFired()
        {
            SceneGraph graph = BuildSceneGraph();

            GameObjectCounter obj1 = new GameObjectCounter() { NoClip = false };
            obj1.SetCollisionSize(32, 32);
            graph.Add(obj1);

            GameObjectCounter obj2 = new GameObjectCounter() { NoClip = false };
            obj2.SetCollisionSize(32, 32);
            graph.Add(obj2);

            graph.Update();

            Assert.That(GetObjectTotals(graph).CollisionTestCount, Is.EqualTo(2));
            Assert.That(GetObjectTotals(graph).CollisionCount, Is.EqualTo(2));
        }
        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));
        }
        public void Draw_SkipOffScreen()
        {
            SceneGraph graph = BuildSceneGraph();
            GameObject obj = new GameObjectCounter();
            obj.Position = new Vector2(-33f, -33f);
            graph.Add(obj);

            graph.Update();
            graph.Draw(null);

            Assert.That(GetObjectTotals(graph).DrawCount, Is.EqualTo(0));
            Assert.That(graph.NodesCulled, Is.EqualTo(1));
        }
        public void SpawnAtMe()
        {
            ISceneGraph graph = CreateSceneGraphScaffolding();
            Vector2 objPosition = new Vector2(32, 64);
            GameObjectCounter obj = new GameObjectCounter();
            obj.SceneGraph = graph;
            obj.Position = objPosition;

            GameObjectCounter spawn = new GameObjectCounter();
            obj.SpawnAtMe(spawn);

            Assert.That(graph.RootGraph.Contains(spawn));
        }
        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));
        }