/*
 * Fireworks.cpp
 *
 *  Created on: 2009-07-13
 *      Author: wasyl
 */

#include "Fireworks.h"

#include <allegro5/allegro.h>
#include <allegro5/a5_primitives.h>

#include "../prep/res/Resources.h"
#include "../misc/Controls.h"
#include "../prep/misc/Vector2D.h"
#include "../misc/Physics.h"
#include "../prep/misc/Random.h"
#include "Level.h"
#include "Game.h"
#include "Particle.h"

Fireworks::Fireworks()
{
	Resources::load(mSound, "media/land.wav");
	mWorld = NULL;
}

Fireworks::~Fireworks()
{
}

void Fireworks::update(double dt)
{
	if (!randomInt(0,50))
	{
		al_play_sample(mSound, 1.2, 0.5, 1.0, ALLEGRO_PLAYMODE_ONCE, NULL);
		for (int i = 0; i < 60; i++)
		{
			float dir = randomFloat(0.0,6.28);
			float pow = randomFloat(215.0, 265.0);
			Particle *p = new Particle(
					"media/glow.png",
					mPos + Vec(randomFloat(-5.0, 5.0), randomFloat(-5.0, 5.0)),
					Vec(std::sin(dir) * pow, std::cos(dir) * pow), 0.4, 0.1, ALLEGRO_ONE);
			mWorld->add(p);
		}
	}
}
