#include "Kicker.hpp"
#include <logic/Logic.hpp>

Kicker::Mesh::Mesh() : CylinderMesh(
  0x10,
  1,
  true
) {
  setColor(
    Color(Color::White) /= 2
  ).scale(
    1,
    0.125,
    1
  ).randomize(
    Vector(
      0,
      0.125
    )
  ).centralize().setLight();
  center = getVertex(Vector::Zero);
  setCenterColor();
}

Mesh& Kicker::Mesh::setCenterColor(const double f) {
  *center = Color(Color::Cyan) /= (
    1 + std::abs(f)
  );
  return *this;
}

const bool Kicker::isStatic() const {
  return true;
}

const Mesh& Kicker::getMesh() const {
  return mesh;
}

Object& Kicker::simulate(const Time dt) {
  if (
    isActive()
  ) {
    mesh.setCenterColor(
      sin(
        Logic::get()->getTimer() * Math::PI
      )
    );
  }
  return MeshObject::simulate(dt);
}

Kicker::Kicker(const double kickMaxYFactor) : kickSpeedY(
  sqrt(
    2 * std::abs(Logic::g.y) * Graphics::get()->R * kickMaxYFactor
  )
) {
}
