Exemplo n.º 1
0
        void OnCollision(SEntityEvent arg)
        {
            if (arg._event != EEntityEvent.ENTITY_EVENT_COLLISION)
            {
                Logger.LogError("Event passed into OnCollision was not a Collision.");
                return;
            }

            // As the only attached Entity event is the collision event, get physics of the collision.
            var collision = arg.GetEventPhysCollision();

            // Retrieve both entities which are part of the collision.
            var entOne = Env.EntitySystem.GetEntityFromPhysics(collision.GetFirstEntity());
            var entTwo = Env.EntitySystem.GetEntityFromPhysics(collision.GetSecondEntity());

            if (entOne == null || entTwo == null)
            {
                return;
            }

            IEntity collider;

            if (entOne.GetId() == GameObject.Id)
            {
                collider = entTwo;
            }
            else
            {
                collider = entOne;
            }

            OnCollide?.Invoke(new CollisionEvent(collision, collider));
        }
        void OnCollision(SEntityEvent arg)
        {
            if (arg._event != EEntityEvent.ENTITY_EVENT_COLLISION)
            {
                return;
            }

            // As the only attached Entity event is the collision event, get physics of the collision.
            var collision = arg.GetEventPhysCollision();

            // Retrieve both entities which are part of the collision.
            var entOne = Global.gEnv.pEntitySystem.GetEntityFromPhysics(collision.GetFirstEntity());
            var entTwo = Global.gEnv.pEntitySystem.GetEntityFromPhysics(collision.GetSecondEntity());

            IEntity collider = null;

            if (entOne != null && entTwo != null)
            {
                if (entOne.GetId() == Entity.Id)
                {
                    collider = entTwo;
                }
                else
                {
                    collider = entOne;
                }
            }

            OnCollide?.Invoke(new CollisionEvent(this, collision, collider));
        }
Exemplo n.º 3
0
        public void OnCollisionEnter(Collision other)
        {
            var towerMB = other.collider.GetComponent <TowerElementMonoBehaviour>();

            if (towerMB)
            {
                OnCollide.Invoke(towerMB);
            }
        }
Exemplo n.º 4
0
        private void OnTriggerEnter2D(Collider2D collision)
        {
            GameObject obj = collision.gameObject;

            if (obj.CompareTag(tags.ToString()))
            {
                OnCollide?.Invoke(obj);
            }
        }
Exemplo n.º 5
0
    private void OnCollisionEnter2D(Collision2D other)
    {
        if (!other.gameObject.CompareTag("BrickAndGround"))
        {
            return;
        }

        OnCollide?.Invoke(this);
    }
Exemplo n.º 6
0
        public void Update(int ticks)
        {
            _xTicks += ticks;
            _yTicks += ticks;


            while (_xTicks >= XRate || _yTicks >= YRate)
            {
                int dX = 0;
                int dY = 0;
                if (_xTicks >= XRate)
                {
                    dX       = XSign;
                    _xTicks -= XRate;
                }

                if (_yTicks >= YRate)
                {
                    dY       = YSign;
                    _yTicks -= YRate;
                }

                Coord newPos = Parent.Position + new Coord(dX, dY);
                if (Parent.CurrentMap?.GetEntity <IGameObject>(newPos, Parent.CurrentMap.LayerMasker.Mask(Parent.Layer)) is IGameObject collideWith)
                {
                    OnCollide?.Invoke(collideWith);
                    _destroyOnCollide?.DoDamage(new Damage(int.MaxValue));
                    break;
                }

                if (!Parent.CurrentMap?.WalkabilityView[newPos] ?? false)
                {
                    OnCollide?.Invoke(Parent.CurrentMap.GetObject(newPos));
                    _destroyOnCollide?.DoDamage(new Damage(int.MaxValue));
                    break;
                }

                Parent.Position = newPos;
            }
        }
Exemplo n.º 7
0
 public void RegisterCollide(OnCollide c)
 {
     collides += c;
 }
Exemplo n.º 8
0
 private void OnControllerColliderHit(ControllerColliderHit hit)
 {
     OnCollide?.Invoke(this.gameObject);
 }
Exemplo n.º 9
0
 public void CollideWith(Collider collider) => OnCollide?.Invoke(collider);
Exemplo n.º 10
0
 public void Collide(Entity other)
 {
     OnCollide?.Invoke(this, other);
 }