talking carrot + super arguments

This commit is contained in:
Crizomb 2025-06-15 22:07:00 +02:00
parent c8787846c3
commit 8b664a26ef
6 changed files with 98 additions and 7 deletions

View file

@ -1,11 +1,19 @@
#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)
const std::vector<std::string> &happy_paths, sf::Font &mFont)
: angryAnimation(angry_paths), neutralAnimation(neutral_paths),
happyAnimation(happy_paths), carrotState(Neutral) {}
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) {
@ -24,6 +32,27 @@ void Carrot::draw(sf::RenderWindow &RenderWindow, float dtime) {
}
}
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);