//void Update()
    //{
    //    setIntegrity(integrity);
    //}

    void OnCollisionEnter2D(Collision2D coll)
    {
        HardMaterial hm = coll.gameObject.GetComponent <HardMaterial>();

        if (hm != null)
        {
            float hitHardness = hm.hardness / hardness * coll.relativeVelocity.magnitude;
            addIntegrity(-1 * hitHardness);
            float hitPercentage = hitHardness * 100 / maxIntegrity;
            for (int i = crackSounds.Count - 1; i >= 0; i--)
            {
                float crackThreshold = 100 / (crackSprites.Count + 1 - i) - 20;
                if (i == 0)
                {
                    crackThreshold = MINIMUM_CRACKSOUND_THRESHOLD;
                }
                if (hitPercentage > crackThreshold)
                {
                    AudioSource.PlayClipAtPoint(crackSounds[i], coll.contacts[0].point, hitPercentage / 400 + 0.75f);
                    break;
                }
            }
        }
        else
        {
            GameObject  other = coll.gameObject;
            Rigidbody2D rb2d  = other.GetComponent <Rigidbody2D>();
            if (rb2d != null)
            {
                float force = rb2d.velocity.magnitude * rb2d.mass;
                checkForce(force);
            }
        }
    }
Beispiel #2
0
    public bool explodesAtAll        = true; //false = doesn't do anything

    // Use this for initialization
    void Start()
    {
        cc2D = GetComponent <CircleCollider2D>();
        fta  = GetComponent <ForceTeleportAbility>();
        HardMaterial hm = GetComponent <HardMaterial>();

        hm.shattered += destroyed;
    }
 // Use this for initialization
 void Start()
 {
     rb2d           = GetComponent <Rigidbody2D>();
     hm             = GetComponent <HardMaterial>();
     groundCollider = GetComponent <BoxCollider2D>();
     gravity        = GetComponent <GravityAccepter>();
     direction      = Utility.PerpendicularLeft(transform.up).normalized;
     player         = GameManager.getPlayerObject();
 }
Beispiel #4
0
    public override void processHoldGesture(Vector2 pos, float holdTime, bool finished)
    {
        float range = maxRange * holdTime * GestureManager.holdTimeScaleRecip / maxHoldTime;

        if (range > maxRange)
        {
            range = maxRange;
        }
        if (finished)
        {
            Collider2D[] hitColliders = Physics2D.OverlapCircleAll(pos, range);
            for (int i = 0; i < hitColliders.Length; i++)
            {
                Rigidbody2D orb2d = hitColliders[i].gameObject.GetComponent <Rigidbody2D>();
                if (orb2d != null)
                {
                    Utility.AddWeightedExplosionForce(orb2d, forceAmount, pos, range);
                }
                else
                {
                    HardMaterial hm = hitColliders[i].gameObject.GetComponent <HardMaterial>();
                    if (hm != null)
                    {
                        float force = forceAmount * (range - Utility.distanceToObject(pos, hitColliders[i].gameObject)) / Time.fixedDeltaTime;
                        hm.checkForce(force);
                    }
                    ShieldBubbleController sbc = hitColliders[i].gameObject.GetComponent <ShieldBubbleController>();
                    if (sbc != null)
                    {
                        float force = forceAmount * (range - Utility.distanceToObject(pos, hitColliders[i].gameObject)) / Time.fixedDeltaTime;
                        sbc.checkForce(force);
                    }
                }
            }
            showExplosionEffect(pos, range * 2);
            AudioSource.PlayClipAtPoint(forceTeleportSound, pos);
            Destroy(frii);
            frii = null;
            particleController.activateTeleportParticleSystem(false);
        }
        else
        {
            if (frii == null)
            {
                frii = Instantiate(forceRangeIndicator);
                friu = frii.GetComponent <TeleportRangeIndicatorUpdater>();
                frii.GetComponent <SpriteRenderer>().enabled = false;
            }
            frii.transform.position = (Vector2)pos;
            friu.setRange(range);
            //Particle effects
            particleController.activateTeleportParticleSystem(true, effectColor, pos, range);
        }
    }
 // Use this for initialization
 void Start()
 {
     rb2d          = GetComponent <Rigidbody2D>();
     pc2d          = GetComponent <PolygonCollider2D>();
     gravity       = GetComponent <GravityAccepter>();
     mainCamCtr    = Camera.main.GetComponent <CameraController>();
     gm            = GameObject.FindGameObjectWithTag("GestureManager").GetComponent <GestureManager>();
     halfWidth     = GetComponent <SpriteRenderer>().bounds.extents.magnitude;
     hm            = GetComponent <HardMaterial>();
     hm.shattered += shattered;
     fta           = GetComponent <ForceTeleportAbility>();
     wca           = GetComponent <WallClimbAbility>();
     sba           = GetComponent <ShieldBubbleAbility>();
     teleportRangeParticalController = teleportRangeParticalObject.GetComponent <ParticleSystemController>();
 }
Beispiel #6
0
 public void trigger()
 {
     if (chargesLeft > 0)
     {
         fta.processHoldGesture(transform.position, chargeTime, true);
         chargeTime = 0;
         setChargesLeft(chargesLeft - 1);
     }
     else
     {
         if (destroyedOnLastCharge)
         {
             HardMaterial hm = GetComponent <HardMaterial>();
             hm.addIntegrity(-hm.maxIntegrity);
         }
     }
 }