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

@ -26,7 +26,7 @@ add_executable(simpleGame
Source/NoteTile.cpp Include/NoteTile.hpp Include/NotePlaceEnum.hpp
Source/TilePattern.cpp Include/TilePattern.hpp
Source/AnimatedSprite.cpp Include/AnimatedSprite.hpp
Source/Carrot.cpp Include/Carrot.hpp
Source/Carrot.cpp Include/Carrot.hpp Include/Arguments.hpp
)
target_include_directories(simpleGame PRIVATE

View file

@ -0,0 +1,34 @@
// clang-format off
#pragma once
#include <string>
#include <vector>
// Pour un projet propre, faire un parser .txt ou .json
static std::vector<std::string> BAD_ARGUMENTS = {
"JE HAIS LES BROCOLLIS,\nFUCK L'AGRICULTURE",
"L'agriculture c'est\nun truc de bobo vegan",
"Agriculture = nature = bio\n paix et amour.",
"Les tracteurs c'est cool!\nJ'ai pas raison la team ?",
"De tout temps l'homme...",
"Pas d'agriculture, pas de frites...",
"Sans l'Agriculture, pas de C++\nAttends du coup c'est bien ou pas ??",
"Y'a pas de bonheur sans beurre",
};
static std::vector<std::string> NEUTRAL_ARGUMENTS = {
"L'agriculture a permis les villages,\ndonc c'est un progres, non?",
"Ok y'a des guerres pour les terres,\nmais ca fait parti du jeu",
"Au moins, maintenant on peut\nmanger des fraises en hiver",
"C'est vrai qu'on est plus nombreux,\nmais plus on est nombreux plus on rit",
"Ok mais sans ble, pas de biere,\npas de pain, la vie est triste"};
static std::vector<std::string> GOOD_ARGUMENTS = {
"On est passe de la liberte nomade\n a l'esclavage des recoltes",
"Avant l'agricultre on bossait 4h par jour.\nMaintenant ? 40h/semaine",
"L'Agriculture a permis la naissances\ndes sciences, des arts et de l'ecriture",
"La revolution agricole,\nc'est aussi la revolution des inegalites.",
"Sans agriculture,\npas de retraite pour Mr Simatic !",
};
// clang-format on

View file

@ -1,5 +1,8 @@
#include "AnimatedSprite.hpp"
#include <SFML/Graphics/Color.hpp>
#include <SFML/Graphics/Font.hpp>
#include <SFML/Graphics/RenderWindow.hpp>
#include <SFML/Graphics/Text.hpp>
#include <SFML/System/Vector2.hpp>
#include <string>
#include <vector>
@ -13,15 +16,29 @@ private:
AnimatedSprite angryAnimation;
CarrotState carrotState;
std::vector<std::string> goodArguments;
std::vector<std::string> neutralArguments;
std::vector<std::string> badArguments;
sf::Text carrotText;
float timePerText = 4;
float timeBuffer = 0;
public:
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);
void draw(sf::RenderWindow &RenderWindow, float dtime);
void setPosition(sf::Vector2f);
// clang-format off
void setTextPosition(sf::Vector2f textPos) {carrotText.setPosition(textPos);};
void setTextCharacterSize(unsigned int chrSize) {carrotText.setCharacterSize(chrSize);}
void setTextFillColor(sf::Color textColor){carrotText.setFillColor(textColor);};
// clang-format on
void setScale(sf::Vector2f);
void changeState(CarrotState new_state);
void handleText(sf::RenderWindow &RenderWindow, float dtime);
CarrotState getState() const { return carrotState; };
};

View file

@ -17,6 +17,10 @@ static constexpr unsigned int FLOWER_SIZE = SCREEN_WIDTH * 0.05;
static const sf::Vector2f CARROT_POS =
sf::Vector2f(SCREEN_WIDTH * 9 / 20, SCREEN_HEIGHT * 0.4);
static const sf::Vector2f CARROT_TEXT_POS = sf::Vector2f(
CARROT_POS.x + SCREEN_WIDTH * 0.05f, CARROT_POS.y - SCREEN_HEIGHT * 0.2f);
/*CARROT_POS + sf::Vector2f(0, -SCREEN_HEIGHT * 0.4);*/
// Texture2D seems big export I don't want to include it
namespace sf {
class Texture;

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);

View file

@ -20,7 +20,7 @@ sf::Texture bgTexture;
Game::Game()
: backGround(PLACE_HOLDER_TEXTURE),
carrot(ANGRY_PATHS, NEUTRAL_PATHS, HAPPY_PATHS) {
carrot(ANGRY_PATHS, NEUTRAL_PATHS, HAPPY_PATHS, mFont) {
assert(mFont.openFromFile("media/Sansation.ttf"));
mStatisticsText.setPosition({5.f, 5.f});
mStatisticsText.setCharacterSize(10);
@ -57,6 +57,10 @@ Game::Game()
carrot.setPosition(CARROT_POS);
carrot.setScale(sf::Vector2f(5, 5));
carrot.setTextPosition(CARROT_TEXT_POS);
carrot.setTextCharacterSize(30);
carrot.setTextFillColor(sf::Color::Black);
}
void generateTilePatternAndMusic(AudioEmitter &audio_emitter) {
@ -129,7 +133,10 @@ void Game::render() {
mWindow.draw(leftPressZone);
mWindow.draw(middlePressZone);
mWindow.draw(rightPressZone);
carrot.draw(mWindow, TimePerFrame.asSeconds());
carrot.handleText(mWindow, TimePerFrame.asSeconds());
if (!NoteTile::update(TimePerFrame.asSeconds(), mWindow))
update_scores(false);
mWindow.draw(mStatisticsText);
@ -158,9 +165,9 @@ void Game::update_scores(bool good_action) {
ScoreMultiplierText.setString(
std::format("ScoreMultiplier = {}", score_multiplier));
if (score_multiplier < 5) {
if (score_multiplier < 15) {
carrot.changeState(Angry);
} else if (score_multiplier < 10) {
} else if (score_multiplier < 35) {
carrot.changeState(Neutral);
} else {
carrot.changeState(Happy);