using UnityEngine;
using System.Collections;


[RequireComponent(typeof(BoxCollider2D))]
public class Colliders : MonoBehaviour
{

	RideWave band;

	void Start() {
		band = GetComponent<RideWave>();
	}

	void OnTriggerEnter2D(Collider2D col)
	{
		//MALUS
		if (col.gameObject.CompareTag("Obstacle"))
		{
			Malus malus = col.GetComponent<Malus>();
			if(!band.shieldAcitve) {
				malus.MalusKillOne(1);

				AudioSource effects = malus.gameObject.GetComponent<AudioSource>();
				effects.Play();
				band.killComponent();
			}
			malus.gameObject.GetComponent<SpriteRenderer>().enabled = false;
			malus.gameObject.GetComponent<BoxCollider2D>().enabled = false;
		}
		if (col.gameObject.CompareTag("LessPoints")) {
			Malus malus = col.GetComponent<Malus>();
			band.scoreMalus += malus.MalusLessPoints();
			AudioSource effects = malus.gameObject.GetComponent<AudioSource>();
			effects.Play();
			malus.gameObject.GetComponent<SpriteRenderer>().enabled = false;
			malus.gameObject.GetComponent<BoxCollider2D>().enabled = false;
		}
		if (col.gameObject.CompareTag("SlowMotion")) {
			Malus malus = col.GetComponent<Malus>();
			band.malusJump = malus.MalusNoJump();
			StartCoroutine(band.coolDownNoJump(malus.noJumpSecs));
			AudioSource effects = malus.gameObject.GetComponent<AudioSource>();
			effects.Play();
			malus.gameObject.GetComponent<SpriteRenderer>().enabled = false;
			malus.gameObject.GetComponent<BoxCollider2D>().enabled = false;
		}

		if (col.gameObject.CompareTag("CameraShake")) {
			Malus malus = col.GetComponent<Malus>();
			Camera.main.GetComponent<CameraControl>().shakeCamera(malus.shakePwr, malus.shakeDur);
			AudioSource effects = malus.gameObject.GetComponent<AudioSource>();
			effects.Play();
			malus.gameObject.GetComponent<SpriteRenderer>().enabled = false;
			malus.gameObject.GetComponent<BoxCollider2D>().enabled = false;
		}


		//BONUS
		if(col.CompareTag("AddPoints")) {
			Bonus bonus = col.GetComponent<Bonus>();
			band.scoreMalus -= bonus.BonusAddPoints();
			AudioSource effects = bonus.gameObject.GetComponent<AudioSource>();
			effects.Play();
			bonus.gameObject.GetComponent<SpriteRenderer>().enabled = false;
			bonus.gameObject.GetComponent<BoxCollider2D>().enabled = false;
		}
			
		if(col.CompareTag("PowerJump")) {
			Bonus bonus = col.GetComponent<Bonus>();
			band.jumpBoost = bonus.BonusPowerJump();
			StartCoroutine(band.coolDownJumpBoost(bonus.powerJumpCoolDown));
			AudioSource effects = bonus.gameObject.GetComponent<AudioSource>();
			effects.Play();
			bonus.gameObject.GetComponent<SpriteRenderer>().enabled = false;
			bonus.gameObject.GetComponent<BoxCollider2D>().enabled = false;
			//GameObject.Destroy(col.gameObject);
		}
			
		if(col.CompareTag("Multiplier")) {
			Bonus bonus = col.GetComponent<Bonus>();
			band.scoreMultiplier += bonus.BonusMultiplier();
			StartCoroutine(band.coolScoreMultiPlier(bonus.multiplierCoolDown));
			bonus.gameObject.GetComponent<SpriteRenderer>().enabled = false;
			bonus.gameObject.GetComponent<BoxCollider2D>().enabled = false;
		}

		if(col.CompareTag("Shield")) {
			Bonus bonus = col.GetComponent<Bonus>();
			band.shieldAcitve = true;
			StartCoroutine(band.removeShieldAfter(bonus.shieldCooldown));
			bonus.gameObject.GetComponent<SpriteRenderer>().enabled = false;
			bonus.gameObject.GetComponent<BoxCollider2D>().enabled = false;
		}
	}
}
