Files
coffee_crisis_arcade_edition/source/writer.cpp

124 lines
1.9 KiB
C++

#include "writer.h"
#include "text.h" // for Text
// Constructor
Writer::Writer(std::shared_ptr<Text> text)
: text_(text),
pos_x_(0),
pos_y_(0),
kerning_(0),
caption_(std::string()),
speed_(0),
writing_counter_(0),
index_(0),
lenght_(0),
completed_(false),
enabled_(false),
enabled_counter_(0),
finished_(false) {}
// Actualiza el objeto
void Writer::update()
{
if (enabled_)
{
if (!completed_)
{
// No completado
if (writing_counter_ > 0)
{
writing_counter_--;
}
else
{
index_++;
writing_counter_ = speed_;
}
if (index_ == lenght_)
{
completed_ = true;
}
}
else
{
// Completado
finished_ = enabled_counter_ <= 0;
if (!finished_)
{
enabled_counter_--;
}
}
}
}
// Dibuja el objeto en pantalla
void Writer::render() const
{
if (enabled_)
{
text_->write(pos_x_, pos_y_, caption_, kerning_, index_);
}
}
// Establece el valor de la variable
void Writer::setPosX(int value)
{
pos_x_ = value;
}
// Establece el valor de la variable
void Writer::setPosY(int value)
{
pos_y_ = value;
}
// Establece el valor de la variable
void Writer::setKerning(int value)
{
kerning_ = value;
}
// Establece el valor de la variable
void Writer::setCaption(const std::string &text)
{
caption_ = text;
lenght_ = text.length();
}
// Establece el valor de la variable
void Writer::setSpeed(int value)
{
speed_ = value;
writing_counter_ = value;
}
// Establece el valor de la variable
void Writer::setEnabled(bool value)
{
enabled_ = value;
}
// Obtiene el valor de la variable
bool Writer::IsEnabled() const
{
return enabled_;
}
// Establece el valor de la variable
void Writer::setFinishedCounter(int time)
{
enabled_counter_ = time;
}
// Centra la cadena de texto a un punto X
void Writer::center(int x)
{
setPosX(x - (text_->lenght(caption_, kerning_) / 2));
}
// Obtiene el valor de la variable
bool Writer::hasFinished() const
{
return finished_;
}