This commit is contained in:
Crizomb 2025-06-15 19:22:33 +02:00
parent adcd6146ed
commit f30a490593
8 changed files with 93 additions and 4 deletions

View file

@ -1,12 +1,13 @@
#pragma once
#include <SFML/Graphics/Sprite.hpp>
#include <SFML/Graphics/Texture.hpp>
#include <SFML/System/Vector2.hpp>
#include <vector>
class AnimatedSprite : public sf::Sprite {
private:
std::vector<sf::Texture> frames_textures;
float time_beetwen_frames = 0.5;
float time_beetwen_frames = 0.25;
float time_without_change = 0.0;
int current_frame = 0;
@ -14,4 +15,5 @@ public:
AnimatedSprite(const std::vector<std::string> &texture_paths);
void update(float dtime);
// draw will be same as sf::Sprite
void setTimeBeetwenFrames(float new_time) { time_beetwen_frames = new_time; };
};

View file

@ -0,0 +1,32 @@
#include "AnimatedSprite.hpp"
#include <SFML/Graphics/RenderWindow.hpp>
#include <SFML/System/Vector2.hpp>
#include <string>
#include <vector>
enum CarrotState { Angry, Happy, Neutral };
class Carrot {
private:
AnimatedSprite happyAnimation;
AnimatedSprite neutralAnimation;
AnimatedSprite angryAnimation;
CarrotState carrotState;
public:
Carrot(const std::vector<std::string> &angry_paths,
const std::vector<std::string> &neutral_paths,
const std::vector<std::string> &happy_paths);
void draw(sf::RenderWindow &RenderWindow, float dtime);
void setPosition(sf::Vector2f);
void setScale(sf::Vector2f);
void changeState(CarrotState new_state);
};
static std::vector<std::string> ANGRY_PATHS = {
"media/sprites/carrot_angry_0.png", "media/sprites/carrot_angry_1.png"};
static std::vector<std::string> NEUTRAL_PATHS = {
"media/sprites/carrot_neutral_0.png", "media/sprites/carrot_neutral_1.png"};
static std::vector<std::string> HAPPY_PATHS = {
"media/sprites/carrot_happy_0.png", "media/sprites/carrot_happy_1.png"};

View file

@ -7,6 +7,7 @@
#define BOOK_GAME_HPP
#include "AudioEmitter.hpp"
#include <Carrot.hpp>
#include <GameData.hpp>
#include <SFML/Graphics.hpp>
@ -47,6 +48,7 @@ private:
int score_multiplier = 1; // number of good press without misses
sf::Sprite backGround;
Carrot carrot;
};
#endif // BOOK_GAME_HPP

View file

@ -1,6 +1,7 @@
#pragma once
#include <SFML/System/Vector2.hpp>
static constexpr unsigned int SCREEN_WIDTH = 1280;
static constexpr unsigned int SCREEN_HEIGHT = 720;
static constexpr unsigned int NOTE_PRESS_HEIGHT = SCREEN_HEIGHT * 0.8;
@ -12,9 +13,15 @@ static constexpr unsigned int NOTE_PLACE_X_POS[3] = {
SCREEN_WIDTH * 6 / 10, SCREEN_WIDTH * 7 / 10, SCREEN_WIDTH * 8 / 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);
// Texture2D seems big export I don't want to include it
namespace sf {
class Texture;
};
// created because sprite doesn't have default constructor
// Not optimal but easy to use + initialized in GameData.cpp
extern sf::Texture PLACE_HOLDER_TEXTURE;