public void OnCollide(GameObject other)
        {
            // Cancel if the enemy is currently spawning
            if (!enemy.IsSpawned)
            {
                return;
            }

            FrameworkDebug.LogCollision(DateTime.Now + ":" + DateTime.Now.Millisecond + " " + enemy.GetType().Name +
                                        " collision with " + other.GetType().Name);

            switch (other)
            {
            case AbstractEnemy _:
                // Get if there is a no overlap component
                var hasNoOverlap = other.GetComponents <CollisionComponent>().Aggregate(false, (b, component) =>
                                                                                        b || component is EnemyNoOverlapCollisionController);
                // Enemies should not overlap if the component is present
                if (hasNoOverlap)
                {
                    GetComponent <ColliderComponent>().UndoOverlap(other.GetComponent <ColliderComponent>());
                }
                break;
            }
        }
Example #2
0
        public void OnCollide(GameObject other)
        {
            // OVERKILL avoidance:
            // Avoid duplicate shots hit the enemy and when the enemy is spawning it shell not get killed
            if (!enemy.IsAlive || !enemy.IsSpawned)
            {
                return;
            }

            FrameworkDebug.LogCollision(DateTime.Now + ":" + DateTime.Now.Millisecond + " " + enemy.GetType().Name +
                                        " collision with " + other.GetType().Name);

            switch (other)
            {
            case Shot.Shot shot:
                shot.OwningPlayer.Attributes.OnEnemyKill(enemy);

                // Destroy the shot and spawn the explosion
                Scene.Current.Spawn(new EnemyExplosionParticleEmitterObject(GameObject as AbstractEnemy));
                Scene.Current.Destroy(GameObject);

                // For now, destroy also the shot (could also have an explosion like effect)
                Scene.Current.Destroy(shot);
                break;
            }
        }
        public void DetectCollisions()
        {
            var colliders = Scene.Current.GetAllComponentsInScene <ColliderComponent>();

            FrameworkDebug.LogCollision("Collsion detection objects: " + colliders.Count);
            DetectCollisions(colliders);
            InvalidateCollisionCaches(colliders);
        }
        public void OnCollide(GameObject other)
        {
            FrameworkDebug.LogCollision(DateTime.Now + ":" + DateTime.Now.Millisecond + " Shot collision with " +
                                        other.GetType().Name);

            switch (other)
            {
            case Border _:
                Scene.Current.Destroy(GameObject);
                break;
            }
        }
        public void OnCollide(GameObject other)
        {
            // Do nothing if dead
            if (!player.Attributes.IsAlive)
            {
                return;
            }

            FrameworkDebug.LogCollision(DateTime.Now + ":" + DateTime.Now.Millisecond + " Player collision with " +
                                        other.GetType().Name);

            switch (other)
            {
            // Deny going threw borders
            case Border _:
                GetComponent <ColliderComponent>().UndoOverlap(other.GetComponent <ColliderComponent>());
                break;

            // Deny going threw other players
            case Player otherPlayer:
                if (otherPlayer.Attributes.IsAlive)
                {
                    GetComponent <ColliderComponent>().UndoOverlap(other.GetComponent <ColliderComponent>(), true);
                }
                break;

            // Damage the player if it hits an enemy
            case AbstractEnemy enemy:
                if (!enemy.IsAlive || !enemy.IsSpawned)
                {
                    break;
                }
                Scene.Current.Destroy(enemy);
                player.Attributes.Damage();
                break;
            }
        }