예제 #1
0
        public void AnyCollision_NoCollision_False()
        {
            var context     = Substitute.For <IWorldContext>();
            var target      = new PhysicSystem();
            var collidable1 = Substitute.For <ICollidable>();

            collidable1.Enabled = true;
            var t = new Transform(context)
            {
                Position = new Point(1, 1)
            };

            collidable1.Transform.Returns(t);

            var collidable2 = Substitute.For <ICollidable>();

            collidable2.Enabled = true;
            t = new Transform(context)
            {
                Position = new Point(2, 2)
            };
            collidable2.Transform.Returns(t);

            Assert.IsFalse(target.AnyCollision(collidable1));

            target.AddCollidable(collidable1);
            Assert.IsFalse(target.AnyCollision(collidable1));

            target.AddCollidable(collidable2);
            Assert.IsFalse(target.AnyCollision(collidable1));
            Assert.IsFalse(target.AnyCollision(collidable2));
        }
예제 #2
0
        public void Update_Collisions_OnCollisionCalled()
        {
            var context     = Substitute.For <IWorldContext>();
            var target      = new PhysicSystem();
            var collidable1 = Substitute.For <ICollidable>();

            collidable1.Enabled = true;
            var t = new Transform(context)
            {
                Position = new Point(1, 1)
            };

            collidable1.Transform.Returns(t);

            var collidable2 = Substitute.For <ICollidable>();

            collidable2.Enabled = true;
            t = new Transform(context)
            {
                Position = new Point(1, 1)
            };
            collidable2.Transform.Returns(t);

            var collidable3 = Substitute.For <ICollidable>();

            collidable3.Enabled = true;
            t = new Transform(context)
            {
                Position = new Point(1, 1)
            };
            collidable3.Transform.Returns(t);

            var collidable4 = Substitute.For <ICollidable>();

            collidable4.Enabled = false;

            target.AddCollidable(collidable1);
            target.AddCollidable(collidable2);
            target.AddCollidable(collidable3);
            target.AddCollidable(collidable4);

            target.Update();

            collidable1.ReceivedWithAnyArgs(2).OnCollision(null);
            collidable2.ReceivedWithAnyArgs(2).OnCollision(null);
            collidable3.ReceivedWithAnyArgs(2).OnCollision(null);
            collidable4.DidNotReceiveWithAnyArgs().OnCollision(null);
        }
예제 #3
0
        public Scene()
        {
            _physics = new PhysicSystem((uint)Enum.GetNames(typeof(CollisionLayer)).Length);
            _physics.SetLayersAsCollidableTogether(CollisionLayer.Player, CollisionLayer.Ball, CollisionResponse.OnPlayerAndBallCollide);
            _physics.SetLayersAsCollidableTogether(CollisionLayer.Player, CollisionLayer.Wall, CollisionResponse.OnPlayerHitsTheWall);
            _physics.SetLayersAsCollidableTogether(CollisionLayer.Ball, CollisionLayer.Wall, CollisionResponse.OnBallTouchWall);
            _physics.SetLayersAsCollidableTogether(CollisionLayer.Ball, CollisionLayer.GoalPlayer1, CollisionResponse.OnBallReachGoalPlayer1);
            _physics.SetLayersAsCollidableTogether(CollisionLayer.Ball, CollisionLayer.GoalPlayer2, CollisionResponse.OnBallReachGoalPlayer2);

            _systemList = new List <ISystem>
            {
                _physics,
                new ProcessMovableSystem(),
                new MatchSystem(this)
            };
        }
예제 #4
0
        public void GetCollisions_Collidables_Collisions()
        {
            var context     = Substitute.For <IWorldContext>();
            var target      = new PhysicSystem();
            var collidable1 = Substitute.For <ICollidable>();

            collidable1.Enabled = true;
            var t = new Transform(context)
            {
                Position = new Point(1, 1)
            };

            collidable1.Transform.Returns(t);

            var collidable2 = Substitute.For <ICollidable>();

            collidable2.Enabled = true;
            t = new Transform(context)
            {
                Position = new Point(1, 1)
            };
            collidable2.Transform.Returns(t);

            var collidable3 = Substitute.For <ICollidable>();

            collidable3.Enabled = true;
            t = new Transform(context)
            {
                Position = new Point(1, 1)
            };
            collidable3.Transform.Returns(t);

            var collidable4 = Substitute.For <ICollidable>();

            collidable4.Enabled = false;

            target.AddCollidable(collidable1);
            target.AddCollidable(collidable2);
            target.AddCollidable(collidable3);
            target.AddCollidable(collidable4);

            Assert.AreEqual(3, target.GetCollisions(collidable1).Count);
            Assert.AreEqual(3, target.GetCollisions(collidable2).Count);
            Assert.AreEqual(3, target.GetCollisions(collidable3).Count);;
        }
예제 #5
0
 public World(Game game) : base(game)
 {
     game.Components.Add(this);
     SpriteBatch  = new SpriteBatch(GraphicsDevice);
     PhysicSystem = new PhysicSystem();
 }