package zero1hd.rhythmbullet.entity;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Preferences;
import com.badlogic.gdx.assets.AssetManager;
import com.badlogic.gdx.audio.Sound;
import com.badlogic.gdx.utils.Array;

public class CollisionDetector {
	Array<Entity> enemies;
	Array<Entity> allies;
	
	AssetManager assets;
	Preferences prefs;
	
	private int amassedPoints;
	Sound explosionSFX;
	public CollisionDetector(Array<Entity> enemies, Array<Entity> allies, AssetManager assetManager, Preferences prefs) {
		this.enemies = enemies;
		this.allies = allies;
		assets = assetManager;
		this.prefs = prefs;
		
	}
	
	public void collisionCheck() {
		if ((enemies.size != 0) && (allies.size != 0)) {
			for (int f = 0; f < enemies.size; f++) {
				Entity enemy = enemies.get(f);
				if (enemy.getHitZone() != null) {
					for (int s = 0; s < allies.size; s++) {
						Entity ally = allies.get(s);
						if (ally.getHitZone() != null) {
							if (enemy.getHitZone().overlaps(ally.getHitZone())) {
								Gdx.app.debug("Collision Detector", "Collision between entities: " + enemy.getClass().getSimpleName() + " and " + ally.getClass().getSimpleName());
								
								enemy.collided(ally);
								ally.collided(enemy);
								
								amassedPoints += enemy.getPoints();
								break;
							}
						}
					}
				}
			}
		}
	}
	
	
	public int getAmassedPoints() {
		int amassedPoints = this.amassedPoints;
		this.amassedPoints = 0;
		return amassedPoints;
	}
}
