//
// Explosion.cpp
//

// Engine includes.
#include "LogManager.h"
#include "ResourceManager.h"
#include "WorldManager.h"

// Game includes.
#include "Explosion.h"
#include "game.h"
#include "util.h"

// Constructor - needs name/label of the Sprite and where to spawn.
Explosion::Explosion(std::string name, df::Vector where) {

  setSolidness(df::SPECTRAL);
  setVisible(false);
  setType(name + " - Explosion");

  if (setSprite(name) != 0)
    LM.writeLog("Explosion::Explosion(): Error! Unable to find sprite: %s",
                name.c_str());
  else {
    int idx = getAnimation().getIndex();
    df::explode(getAnimation().getSprite(), idx, where,
                EXPLOSION_AGE, EXPLOSION_SPEED, EXPLOSION_ROTATE);
  }

  // Play "splat" sound.
  std::string sound = "splat-" + std::to_string(rand()%6 + 1);
  play_sound(sound);
  
  WM.markForDelete(this);
}
