protected override void OnUpdate()
        {
            if (0 == m_Receivers.Length || 0 == m_Shots.Length)
            {
                return;
            }

            var settings = TwoStickBootstrap.Settings;

            for (int pi = 0; pi < m_Receivers.Length; ++pi)
            {
                float damage                 = 0.0f;
                float collisionRadius        = GetCollisionRadius(settings, m_Receivers.Faction[pi].Value);
                float collisionRadiusSquared = collisionRadius * collisionRadius;

                float2       receiverPos     = m_Receivers.Position[pi].Value;
                Faction.Type receiverFaction = m_Receivers.Faction[pi].Value;

                for (int si = 0; si < m_Shots.Length; ++si)
                {
                    if (m_Shots.Faction[si].Value != receiverFaction)
                    {
                        float2 shotPos     = m_Shots.Position[si].Value;
                        float2 delta       = shotPos - receiverPos;
                        float  distSquared = math.dot(delta, delta);
                        if (distSquared <= collisionRadiusSquared)
                        {
                            var shot = m_Shots.Shot[si];

                            damage += shot.Energy;

                            // Set the shot's time to live to zero, so it will be collected by the shot destroy system
                            shot.TimeToLive = 0.0f;
                        }
                    }
                }

                var h = m_Receivers.Health[pi];
                h.Value = math.max(h.Value - damage, 0.0f);
            }
        }
Esempio n. 2
0
        protected override void OnUpdate()
        {
            if (0 == m_Receivers.Length || 0 == m_Shots.Length)
            {
                return;
            }

            var settings = TwoStickBootstrap.Settings;

            for (int pIndex = 0; pIndex < m_Receivers.Length; ++pIndex)
            {
                float damage = 0.0f;

                Faction.Type receiverFaction = m_Receivers.Faction[pIndex].Value;
                float2       receiverPos     = m_Receivers.Position[pIndex].Value;

                float collisionRadius        = GetCollisionRadius(settings, receiverFaction);
                float collisionRadiusSquared = collisionRadius * collisionRadius;

                for (int sIndex = 0; sIndex < m_Shots.Length; sIndex++)
                {
                    if (m_Shots.Faction[sIndex].Value != receiverFaction)
                    {
                        float2 shotPos     = m_Shots.Position[sIndex].Value;
                        float2 delta       = shotPos - receiverPos;
                        float  distSquared = math.dot(delta, delta);

                        if (distSquared <= collisionRadiusSquared)
                        {
                            var shot = m_Shots.Shot[sIndex];
                            damage         += shot.Energy;
                            shot.TimeToLive = 0.0f;
                        }
                    }
                }
                var h = m_Receivers.Health[pIndex];
                h.Value = math.max(h.Value - damage, 0.0f);
            }
        }
 static float GetCollisionRadius(TwoStickExampleSettings settings, Faction.Type faction)
 {
     // This simply picks the collision radius based on whether the receiver is the player or not.
     // In a real game, this would be much more sophisticated, perhaps with a CollisionRadius component.
     return(faction == Faction.Type.Player ? settings.playerCollisionRadius : settings.enemyCollisionRadius);
 }