예제 #1
0
 void Update()
 {
     cooldownRemaining -= Time.deltaTime;
     if (cooldownRemaining <= 0)
     {
         cooldownRemaining = 0;
     }
     if (Input.GetKeyDown(KeyCode.C))
     {
         //Calculate the power
         float power = Mathf.Pow(Mathf.Abs(Mathf.Sin(songData.songTime * Mathf.PI * songData.bpm / 120)) * ((cooldown - cooldownRemaining) / cooldown), 2);
         //Play the sound
         snareSource.volume = power;
         snareSource.Play();
         //Instantiate the projectile
         GameObject     projectile = Instantiate(projectileObject, transform.position, transform.rotation);
         SnareCollision sc         = projectile.GetComponent <SnareCollision>();
         sc.maxRange = power * maxRange;
         sc.damage   = Mathf.CeilToInt(power * maxDamage);
         projectile.transform.localScale = new Vector3(power, power, 1);
         //Start the cooldown
         cooldownRemaining = cooldown;
         //Change the sprite
         spriteRenderer.sprite = alternateSprite;
         Invoke("OnEndAnimation", Time.fixedDeltaTime * 10);
     }
 }
예제 #2
0
 void Update()
 {
     cooldownRemaining -= Time.deltaTime;
     if (cooldownRemaining <= 0)
     {
         cooldownRemaining = 0;
     }
     if (Input.GetKeyDown(KeyCode.Z))
     {
         //Calculate the power of the
         //power = Sqrt(Cos(pi * t))
         float power = Mathf.Abs(Mathf.Cos(songData.songTime * Mathf.PI * songData.bpm / 30)) * ((cooldown - cooldownRemaining) / cooldown);
         //Play the sound
         hatSource.volume = power;
         hatSource.Play();
         //Instantiate the projectiles
         if (diagonal)
         {
             foreach (Vector3 direction in diagDirections)
             {
                 GameObject proj = Instantiate(projectile, transform.position, transform.rotation);
                 proj.transform.localScale = new Vector3(0.5f * power, 0.5f * power, 1);
                 SnareCollision sc = proj.GetComponent <SnareCollision>();
                 sc.direction = direction;
                 sc.maxRange  = maxRange * power;
                 sc.damage    = Mathf.CeilToInt(maxDamage * power);
             }
         }
         else
         {
             foreach (Vector3 direction in new Vector3[] { Vector3.up, Vector3.down, Vector3.left, Vector3.right })
             {
                 GameObject proj = Instantiate(projectile, transform.position, transform.rotation);
                 proj.transform.localScale = new Vector3(0.5f * power, 0.5f * power, 1);
                 SnareCollision sc = proj.GetComponent <SnareCollision>();
                 sc.direction = direction;
                 sc.maxRange  = maxRange * power;
                 sc.damage    = Mathf.CeilToInt(maxDamage * power);
             }
         }
         diagonal = !diagonal;
         //Start the cooldown
         cooldownRemaining = cooldown;
         //Change the sprite
         spriteRenderer.sprite = alternateSprite;
         Invoke("OnEndAnimation", Time.fixedDeltaTime * 6);
     }
 }
예제 #3
0
    private void OnTriggerEnter2D(Collider2D collision)
    {
        KickCollision  kickCollision  = collision.GetComponent("KickCollision") as KickCollision;
        SnareCollision snareCollision = collision.GetComponent("SnareCollision") as SnareCollision;

        if (kickCollision != null)
        {
            health -= kickCollision.damage;
        }
        if (snareCollision != null)
        {
            health -= snareCollision.damage;
            Destroy(snareCollision.gameObject);
        }
        if (collision.gameObject.tag == "Tower")
        {
            Destroy(collision.gameObject);
        }
    }