RythmGame/SimpleGame/src/Source/Carrot.cpp

68 lines
1.9 KiB
C++

#include "Carrot.hpp"
#include "Arguments.hpp"
#include <SFML/Graphics/Font.hpp>
#include <SFML/Graphics/RenderWindow.hpp>
#include <SFML/System/Vector2.hpp>
#include <cstdlib>
Carrot::Carrot(const std::vector<std::string> &angry_paths,
const std::vector<std::string> &neutral_paths,
const std::vector<std::string> &happy_paths, sf::Font &mFont)
: angryAnimation(angry_paths), neutralAnimation(neutral_paths),
happyAnimation(happy_paths), carrotState(Angry), carrotText(mFont) {
goodArguments = GOOD_ARGUMENTS;
neutralArguments = NEUTRAL_ARGUMENTS;
badArguments = BAD_ARGUMENTS;
}
void Carrot::draw(sf::RenderWindow &RenderWindow, float dtime) {
switch (carrotState) {
case Angry:
RenderWindow.draw(angryAnimation);
angryAnimation.update(dtime);
break;
case Neutral:
RenderWindow.draw(neutralAnimation);
neutralAnimation.update(dtime);
break;
case Happy:
RenderWindow.draw(happyAnimation);
happyAnimation.update(dtime);
break;
}
}
void Carrot::handleText(sf::RenderWindow &renderWindow, float dtime) {
renderWindow.draw(carrotText);
timeBuffer += dtime;
if (timeBuffer < timePerText)
return;
timeBuffer = 0;
int random = rand();
switch (carrotState) {
case Angry:
carrotText.setString(badArguments[random % badArguments.size()]);
break;
case Neutral:
carrotText.setString(neutralArguments[random % neutralArguments.size()]);
break;
case Happy:
carrotText.setString(goodArguments[random % goodArguments.size()]);
break;
}
}
void Carrot::setPosition(sf::Vector2f new_pos) {
angryAnimation.setPosition(new_pos);
neutralAnimation.setPosition(new_pos);
happyAnimation.setPosition(new_pos);
}
void Carrot::setScale(sf::Vector2f new_scale) {
angryAnimation.setScale(new_scale);
neutralAnimation.setScale(new_scale);
happyAnimation.setScale(new_scale);
}
void Carrot::changeState(CarrotState new_state) { carrotState = new_state; };