package game.obj;

import openfl.media.SoundTransform;

class Coin extends AnimSprite {
	public function new(?x:Float, ?y:Float) {
		super('assets/sprites/coin.aseprite', x, y);

		aseprite.currentFrame = Math.floor(Math.random() * aseprite.frames.length);
		aseprite.play();
	}

	override function update(delta:Float) {
		if (distance != null && distance < 0.4) {
			Game.current.playSound('assets/sound/coin.ogg', new SoundTransform(0.5));
			Game.current.map.collectedCoins++;
			Game.current.updateCoinsHUD();

			raycaster.removeSprite(this);

			if (Game.current.map.collectedCoins == Game.current.map.numCoins) {
				Game.current.end();
			}
		}

		super.update(delta);
	}
}
