private static void Split(D2D_Destructible destructible, D2D_SplitGroup group, bool isClone)
    {
        var subX      = group.XMin;
        var subY      = group.YMin;
        var subWidth  = group.XMax - group.XMin + 1;
        var subHeight = group.YMax - group.YMin + 1;
        var subTotal  = subWidth * subHeight;
        var subAlpha  = new byte[subTotal];

        for (var i = group.Count - 1; i >= 0; i--)
        {
            var j = group.Indices[i];
            var a = group.Alphas[i];
            var x = (j % AlphaTexWidth) - subX;
            var y = (j / AlphaTexWidth) - subY;
            var s = x + y * subWidth;

            subAlpha[s] = a;
        }

        destructible.SubsetAlphaWith(subAlpha, subWidth, subHeight, subX, subY);

        // Split notification
        D2D_Helper.BroadcastMessage(destructible.transform, "OnDestructibleSplit", splitData, SendMessageOptions.DontRequireReceiver);
    }
Example #2
0
    protected virtual void OnDestructibleSplit(D2D_SplitData splitData)
    {
        // Only count this as a valid split if there is more than one child over the split min pixels, or this is smaller
        if (splitData.SolidPixelCounts[splitData.Index] < MinSplitPixels || splitData.SolidPixelThresholdTotal(MinSplitPixels) >= 2)
        {
            SplitDepth += 1;

            D2D_Helper.BroadcastMessage(transform, "OnDestructibleValidSplit", splitData, SendMessageOptions.DontRequireReceiver);
        }
    }
Example #3
0
    private void NotifyChanges(int xMin, int xMax, int yMin, int yMax)
    {
        var rect = new D2D_Rect();

        rect.XMin = xMin;
        rect.XMax = xMax;
        rect.YMin = yMin;
        rect.YMax = yMax;

        D2D_Helper.BroadcastMessage(transform, "OnAlphaTexModified", rect, SendMessageOptions.DontRequireReceiver);
    }
Example #4
0
    public void InflictDamage(float amount)
    {
        if (Age >= ActivateDelay)         // Discard damage until it's old enough
        {
            if (amount != 0.0f)
            {
                Damage += amount;

                D2D_Helper.BroadcastMessage(transform, "OnDamageInflicted", amount, SendMessageOptions.DontRequireReceiver);

                UpdateDestruction();
            }
        }
    }
Example #5
0
    protected virtual void OnCollisionEnter2D(Collision2D collision)
    {
        var damage = collision.relativeVelocity.magnitude * DamageScale;

        D2D_Helper.BroadcastMessage(collision.transform, "OnDamage", damage, SendMessageOptions.DontRequireReceiver);

        if (damage >= DamageThreshold)
        {
            if (damageable == null)
            {
                damageable = GetComponent <D2D_Damageable>();
            }

            damageable.InflictDamage(damage);
        }
    }
Example #6
0
 private void NotifyChanges()
 {
     D2D_Helper.BroadcastMessage(transform, "OnAlphaTexReplaced", SendMessageOptions.DontRequireReceiver);
 }