public void AddEntity()
        {
            var entity = _componentManager.CreateEntity();

            A.CallTo(() => _eventSystem.Send(A <object> ._, A <EntityAdded> ._))
            .MustHaveHappenedOnceExactly();

            Assert.That(_componentManager.GetEntity(entity.Id), Is.EqualTo(entity));
        }
Beispiel #2
0
        public Entity CreateEntity(string tag)
        {
            var entity = Entity.CreateEntity();

            _entities.Add(entity, new Dictionary <Type, IComponent>());
            AddEntityToGroupedEntities(entity, tag);

            _eventSystem?.Send(this, new EntityAdded(entity));

            return(entity);
        }
Beispiel #3
0
        public bool IsColliding(ColliderComponent dynamicCollider, float deltaTime)
        {
            dynamicCollider.CollisionInfos = Array.Empty <CollisionInfo>();

            if (dynamicCollider.CollisionType == ColliderComponent.CollisionTypes.Static)
            {
                return(false);
            }

            var colliderComponents = ColliderComponentManager.Instance.Components
                                     .Where(collider => collider.CollisionType == ColliderComponent.CollisionTypes.Static)
                                     .ToArray();

            // reset collision flag
            colliderComponents
            .ForEach(collider => collider.IsColliding = false);

            var componentsInCollision = GetOverlappingColliders(dynamicCollider, deltaTime, colliderComponents);

            var results = new List <CollisionInfo>();

            foreach (var componentInCollision in componentsInCollision)
            {
                if (!IsRectInRect(dynamicCollider.BoundingBox, dynamicCollider.GameObject.TransformComponent.Velocity, componentInCollision.BoundingBox, out var contactPoint, out var contactNormal, out var contactTime, deltaTime))
                {
                    continue;
                }

                var collisionInfo = new CollisionInfo(contactPoint, contactNormal, contactTime)
                {
                    ContactRect = componentInCollision.BoundingBox
                };
                results.Add(collisionInfo);
                componentInCollision.IsColliding = true;
                _eventSystem.Send(this, new CollisionEvent(dynamicCollider.GameObject, componentInCollision.GameObject, collisionInfo));
            }

            if (results.Any())
            {
                dynamicCollider.CollisionInfos = results.OrderBy(info => info.CollisionTime).ToArray();
                return(true);
            }

            return(false);
        }
Beispiel #4
0
        public void SubscriberGetsNotified()
        {
            var fakeSubscriber = A.Fake <Action <object, DateTime> >();

            _eventSystem.Subscribe(this, fakeSubscriber);

            var utcNow = DateTime.UtcNow;

            _eventSystem.Send(this, utcNow);

            A.CallTo(() => fakeSubscriber.Invoke(A <object> .That.IsEqualTo(this), A <DateTime> .That.IsEqualTo(utcNow)))
            .MustHaveHappenedOnceExactly();
        }
 private void Jump(GameObject gameObject)
 {
     gameObject.TransformComponent.Velocity += gameObject.GetComponent <PlayerComponent>().InitialJumpVelocity;
     AddDustEmitter(gameObject);
     _eventSystem.Send(this, new JumpEvent(gameObject));
 }