#include "game_particle.h"
#include "gameframe.h"
#include "game_planet.h"

GameParticle::GameParticle(Vector2f _center, float _dist, float _baseAngle, Vector2f _vel, float _ttl, ParticleType _type, GameFrame* frame)
	: GamePlanetObject(_center, _dist, _baseAngle, Object_Particle, frame)
	, vel(_vel)
	, ttl(_ttl)
	, partType(_type)
	, planet(frame->planet.get())
{
	particle = true;
	speed = _vel.x;
	speedY = _vel.y;
	pos = Vector2f(0, -200);
		
	switch (partType) {
	case Particle_Lava:
		{
			int n = rand() % 4;
			init("lava"+String::IntegerToString(n)+".png", Vector2f(0.5f, 0.5f), 3, Collision::Deadly);
			//init("lava"+String::IntegerToString(n)+".png", Vector2f(0.5f, 0.5f), 10, Collision::None);
			layer = 5;
			break;
		}

	case Particle_Smoke:
		break;
	}
}

bool GameParticle::step(float t, float at)
{
	//vel -= Vector2f(0, 20);
	if (GamePlanetObject::step(t, at)) {
		float floor = 800.0f;
		if (dist < floor) {
			dist = floor;
			speedY = -speedY*0.2f;
			ttl -= 0.2f;
		}

		speedY -= 20;

		if (at >= ttl) setAlive(false);
		return at < ttl;
	} else {
		return false;
	}
}

void GameParticle::init(String texture, Vector2f offset, float rad, Collision::Mask cType)
{
	texId = TextureManager::get(texture)->GetId();
	pivot = offset;
	colType.radius = rad;
	colType.mask = cType;
}
