//
//  Particle.h
//  PixelKit
//
//  Copyright (c) 2015 Cesar Parent. All rights reserved.
//

#ifndef __PixelKit__Particle__
#define __PixelKit__Particle__

#include "includes.h"
#include "SpriteNode.h"
#include "Rect.h"

namespace PixelKit
{
	class Particle : public SpriteNode
	{
	public:
		/*!
		 * @brief Creates a new Particle that will live for a certain amount of time.
		 * @param sprite Image file to use as a particle.
		 * @param clipFrame frame in the sprite sheet to use.
		 * @param duration number of frames the particle should live for
		 */
		Particle(std::string sprite, Rect<int> clipFrame, int duration);
		
		/*!
		 * @brief Particle destructor.
		 */
		virtual ~Particle();
		
		/*!
		 * @brief Update method. Update the particle's rotation, speed and position, and fades
		 * it to a fully-transparent sprite if shouldFade was set to true.
		 * @param timeInterval Time elapsed since last frames in milliseconds.
		 */
		virtual void update(int timeInterval) override;
		
		/*!
		 * @brief Parent tree delegate method. Called when the Particle has been fully removed from
		 * its parent layer.
		 */
		virtual void didExitParent() override;
		
		/*!
		 * @brief Set the particle's speed (pixels per second)
		 * @param x horizontal speed
		 * @param y vertical speed
		 */
		virtual void setSpeed(float x, float y);
		
		/*!
		 * @brief Set the particle's accelerator. The accelerator components will be added to the
		 * particle's speed (1/second).
		 * @param x Accelerator's horizontal component.
		 * @param y Accelerator's vertical component.
		 */
		virtual void setAccelerator(float x, float y);
		
		/*!
		 * @brief Set the particle's rotation speed (degrees per second).
		 * @param r Rotation speed.
		 */
		virtual void setRotationSpeed(float r);
		
		/*!
		 * @brief Wether the particle should fade to transparency or disappear brutally
		 * at the end of its lifetime
		 * @param fade Wether the particle should fade or not.
		 */
		virtual void shouldFade(bool fade);
		
	protected:
		
		Point<float> _speed;
		Point<float> _accelerator;
		float _rotationSpeed;
		int _duration;
		int _lifetime;
		bool _shouldFade;
	};
}

#endif /* defined(__PixelKit__Particle__) */
