From 8b664a26ef8eda8e03085a4eb72ca7d877cfa36d Mon Sep 17 00:00:00 2001 From: Crizomb Date: Sun, 15 Jun 2025 22:07:00 +0200 Subject: [PATCH] talking carrot + super arguments --- SimpleGame/src/CMakeLists.txt | 2 +- SimpleGame/src/Include/Arguments.hpp | 34 ++++++++++++++++++++++++++++ SimpleGame/src/Include/Carrot.hpp | 19 +++++++++++++++- SimpleGame/src/Include/GameData.hpp | 4 ++++ SimpleGame/src/Source/Carrot.cpp | 33 +++++++++++++++++++++++++-- SimpleGame/src/Source/Game.cpp | 13 ++++++++--- 6 files changed, 98 insertions(+), 7 deletions(-) create mode 100644 SimpleGame/src/Include/Arguments.hpp diff --git a/SimpleGame/src/CMakeLists.txt b/SimpleGame/src/CMakeLists.txt index 1ab937c..d5872e8 100644 --- a/SimpleGame/src/CMakeLists.txt +++ b/SimpleGame/src/CMakeLists.txt @@ -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 diff --git a/SimpleGame/src/Include/Arguments.hpp b/SimpleGame/src/Include/Arguments.hpp new file mode 100644 index 0000000..d998259 --- /dev/null +++ b/SimpleGame/src/Include/Arguments.hpp @@ -0,0 +1,34 @@ + +// clang-format off +#pragma once +#include +#include +// Pour un projet propre, faire un parser .txt ou .json + +static std::vector 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 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 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 diff --git a/SimpleGame/src/Include/Carrot.hpp b/SimpleGame/src/Include/Carrot.hpp index 5486351..327c212 100644 --- a/SimpleGame/src/Include/Carrot.hpp +++ b/SimpleGame/src/Include/Carrot.hpp @@ -1,5 +1,8 @@ #include "AnimatedSprite.hpp" +#include +#include #include +#include #include #include #include @@ -13,15 +16,29 @@ private: AnimatedSprite angryAnimation; CarrotState carrotState; + std::vector goodArguments; + std::vector neutralArguments; + std::vector badArguments; + + sf::Text carrotText; + float timePerText = 4; + float timeBuffer = 0; + public: Carrot(const std::vector &angry_paths, const std::vector &neutral_paths, - const std::vector &happy_paths); + const std::vector &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; }; }; diff --git a/SimpleGame/src/Include/GameData.hpp b/SimpleGame/src/Include/GameData.hpp index 0fba6e0..4d9cb1e 100644 --- a/SimpleGame/src/Include/GameData.hpp +++ b/SimpleGame/src/Include/GameData.hpp @@ -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; diff --git a/SimpleGame/src/Source/Carrot.cpp b/SimpleGame/src/Source/Carrot.cpp index cc56c67..1e5ae2f 100644 --- a/SimpleGame/src/Source/Carrot.cpp +++ b/SimpleGame/src/Source/Carrot.cpp @@ -1,11 +1,19 @@ #include "Carrot.hpp" +#include "Arguments.hpp" +#include +#include #include +#include Carrot::Carrot(const std::vector &angry_paths, const std::vector &neutral_paths, - const std::vector &happy_paths) + const std::vector &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); diff --git a/SimpleGame/src/Source/Game.cpp b/SimpleGame/src/Source/Game.cpp index 41de2d4..5ded14f 100644 --- a/SimpleGame/src/Source/Game.cpp +++ b/SimpleGame/src/Source/Game.cpp @@ -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);