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

@ -18,7 +18,7 @@ AnimatedSprite::AnimatedSprite(const std::vector<std::string> &texture_paths)
}
assert(frames_textures.size() > 0);
// setTexture is frome Sprite
setTexture(frames_textures[0]);
setTexture(frames_textures[0], true);
};
void AnimatedSprite::update(float dtime) {

View file

@ -0,0 +1,39 @@
#include "Carrot.hpp"
#include <SFML/System/Vector2.hpp>
Carrot::Carrot(const std::vector<std::string> &angry_paths,
const std::vector<std::string> &neutral_paths,
const std::vector<std::string> &happy_paths)
: angryAnimation(angry_paths), neutralAnimation(neutral_paths),
happyAnimation(happy_paths), carrotState(Neutral) {}
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::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; };

View file

@ -18,7 +18,9 @@
const sf::Time Game::TimePerFrame = sf::seconds(1.f / 60.f);
sf::Texture bgTexture;
Game::Game() : backGround(PLACE_HOLDER_TEXTURE) {
Game::Game()
: backGround(PLACE_HOLDER_TEXTURE),
carrot(ANGRY_PATHS, NEUTRAL_PATHS, HAPPY_PATHS) {
assert(mFont.openFromFile("media/Sansation.ttf"));
mStatisticsText.setPosition({5.f, 5.f});
mStatisticsText.setCharacterSize(10);
@ -52,6 +54,9 @@ Game::Game() : backGround(PLACE_HOLDER_TEXTURE) {
float sx = backGround.getTexture().getSize().x;
float sy = backGround.getTexture().getSize().y;
backGround.setScale(sf::Vector2f(SCREEN_WIDTH / sx, SCREEN_HEIGHT / sy));
carrot.setPosition(CARROT_POS);
carrot.setScale(sf::Vector2f(5, 5));
}
void generateTilePatternAndMusic(AudioEmitter &audio_emitter) {
@ -124,7 +129,8 @@ void Game::render() {
mWindow.draw(leftPressZone);
mWindow.draw(middlePressZone);
mWindow.draw(rightPressZone);
if (!NoteTile::update(1.0 / 60, mWindow))
carrot.draw(mWindow, TimePerFrame.asSeconds());
if (!NoteTile::update(TimePerFrame.asSeconds(), mWindow))
update_scores(false);
mWindow.draw(mStatisticsText);
mWindow.draw(ScoreText);