From 7b69993881c326c5048fcc67728b0c1683fe9281 Mon Sep 17 00:00:00 2001 From: Maximilian Giller Date: Sat, 10 Jun 2023 20:46:52 +0200 Subject: [PATCH] Concept with texture cutout --- CMakeLists.txt | 30 +++---- assets/grass_plus.png | Bin 0 -> 18930 bytes src/config.h | 2 +- src/game/level/level_loader.cpp | 17 ++-- src/game/level/level_loader.hpp | 2 +- src/game/player/player.hpp | 2 +- src/main.cpp | 2 +- src/sprites/{ => basic}/animated_sprite.cpp | 4 +- src/sprites/{ => basic}/animated_sprite.hpp | 2 +- src/sprites/{ => basic}/single_sprite.cpp | 14 ++++ src/sprites/{ => basic}/single_sprite.hpp | 6 +- src/sprites/{ => basic}/sprite.hpp | 0 src/sprites/{ => basic}/sprite_factory.cpp | 79 +++++++++++-------- src/sprites/{ => basic}/sprite_factory.hpp | 4 +- src/sprites/{ => basic}/sprite_sheet.cpp | 31 ++++---- src/sprites/{ => basic}/sprite_sheet.hpp | 5 +- src/sprites/basic/texture_cutout.hpp | 15 ++++ src/sprites/{ => basic}/texture_manager.cpp | 2 +- src/sprites/{ => basic}/texture_manager.hpp | 0 src/sprites/{ => basic}/versatile_sprite.cpp | 2 +- src/sprites/{ => basic}/versatile_sprite.hpp | 2 +- src/sprites/ground_sprite.cpp | 66 ++++++++++++++++ src/sprites/ground_sprite.hpp | 30 +++++++ src/texture_config.h | 10 ++- 24 files changed, 242 insertions(+), 85 deletions(-) create mode 100644 assets/grass_plus.png rename src/sprites/{ => basic}/animated_sprite.cpp (94%) rename src/sprites/{ => basic}/animated_sprite.hpp (95%) rename src/sprites/{ => basic}/single_sprite.cpp (75%) rename src/sprites/{ => basic}/single_sprite.hpp (74%) rename src/sprites/{ => basic}/sprite.hpp (100%) rename src/sprites/{ => basic}/sprite_factory.cpp (74%) rename src/sprites/{ => basic}/sprite_factory.hpp (78%) rename src/sprites/{ => basic}/sprite_sheet.cpp (58%) rename src/sprites/{ => basic}/sprite_sheet.hpp (76%) create mode 100644 src/sprites/basic/texture_cutout.hpp rename src/sprites/{ => basic}/texture_manager.cpp (97%) rename src/sprites/{ => basic}/texture_manager.hpp (100%) rename src/sprites/{ => basic}/versatile_sprite.cpp (97%) rename src/sprites/{ => basic}/versatile_sprite.hpp (94%) create mode 100644 src/sprites/ground_sprite.cpp create mode 100644 src/sprites/ground_sprite.hpp diff --git a/CMakeLists.txt b/CMakeLists.txt index fa8c037..0301471 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -58,23 +58,23 @@ set(SOURCES src/game/camera/tracking_view_options.hpp src/game/collectables/environment_collectable.cpp src/game/collectables/environment_collectable.hpp - src/sprites/texture_manager.cpp - src/sprites/texture_manager.hpp - src/sprites/sprite_sheet.cpp - src/sprites/sprite_sheet.hpp - src/sprites/animated_sprite.cpp - src/sprites/animated_sprite.hpp - src/sprites/single_sprite.cpp - src/sprites/single_sprite.hpp + src/sprites/basic/texture_manager.cpp + src/sprites/basic/texture_manager.hpp + src/sprites/basic/sprite_sheet.cpp + src/sprites/basic/sprite_sheet.hpp + src/sprites/basic/animated_sprite.cpp + src/sprites/basic/animated_sprite.hpp + src/sprites/basic/single_sprite.cpp + src/sprites/basic/single_sprite.hpp src/texture_config.h src/sprites/configs/sprite_config.hpp src/sprites/configs/sheet_config.hpp src/sprites/configs/animation_config.hpp - src/sprites/versatile_sprite.cpp - src/sprites/versatile_sprite.hpp - src/sprites/sprite.hpp - src/sprites/sprite_factory.cpp - src/sprites/sprite_factory.hpp + src/sprites/basic/versatile_sprite.cpp + src/sprites/basic/versatile_sprite.hpp + src/sprites/basic/sprite.hpp + src/sprites/basic/sprite_factory.cpp + src/sprites/basic/sprite_factory.hpp src/input_config.h src/game/input/button_config.hpp src/game/input/game_action.hpp @@ -88,7 +88,9 @@ set(SOURCES src/game/level/level_config.hpp src/game/level/level_loader.cpp src/game/level/level_loader.hpp - src/levels.hpp) + src/levels.hpp + src/sprites/ground_sprite.cpp + src/sprites/ground_sprite.hpp src/sprites/basic/texture_cutout.hpp) set(PHYSICS_00_SOURCES src/prototypes/physics_00.cpp) diff --git a/assets/grass_plus.png b/assets/grass_plus.png new file mode 100644 index 0000000000000000000000000000000000000000..2b6fb6a3ff78a66f8661c61a7029bc257b67a18e GIT binary patch literal 18930 zcma&O1ymeO(?7b4`z|g4b{BUG5G+V=4=%waKp+Xh-C-ABTmmF`0t5}g-IhS`AW3jb zaCf{nsF%Cn3r9_v+m_2n z25R#g>2Zk2K7hcuxfLa3EHoS=wTl{)e|MhV|6W}BU0B-f_&Q5g)tyH~lY)j%ok7=$ z#V&`-b(r7(Uf27+JO4iV;fA94Cw@gA25oHy4NeB`$DE?N4`mWHjoMz=+*i7OThH!C z*M!SMS4$6Y|Nr-oU3-TD0DuBi73B1Na@NhAGk$)lEUsWzEmi$FJZxH8s@bnK)4X|q z-=%Ja$)Ylt>^b4z5hr9zo4(`I7)kvIuc?p!yQr3JeHyd$!C@=$W61dlFfZuB#P3>I zllk_bjy2+BHDl>gFfQ<2P*e@%qGsTyQ_B6jMXjH`Z?7HSc6HBSk~n@%!a`)Mh69Aa zP!Se_h$l~87d|4R$0BTtUr=!c^IQdQL0`LfS_V#f{1bO zr~@(#fD8q~uvPs5u<9b^e~6MbknRM<5hokY`0cdwh0r=NHMZP%i~7u|)De;9)h-{4 zrNZ>;wLOS8RRuBQ+ zgNnZMzx0j3bPP;zI;KN`ZcF$gBLOGR^~1V4^SSVp)4_nXu0iEmO%nUxq6SG~spY3b z4N5@+fZF;c($o5#2fq3FTHz3;HZ8F!H%B`q4^p2xPz{x>-S;ta8gQ*RCP~R{vH_Ni zo+0TC&xIc_Y6#abA@4E%N7L5_RtiLnHzHLgM0`EAz$}JYuH+ zO2P^R{um>dlBDO>!tAG&@qCs+!LdkfrRaBzsI|I3-Ryd--M>+J%AANU;Ihg+-VED^cfU&re+y z!?U?=abA>7y(qRSV~@pRAFm7jk;IvqjbiFj)o^+5Wk*o5Fo?#j|LD0)*Y@*Y6R#c_ zd%3I>NZ^m+yik4xoErnrvm~H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h index d81ccd7..be32834 100644 --- a/src/config.h +++ b/src/config.h @@ -20,7 +20,7 @@ // Graphic settings #define ISOMETRIC_SKEW 0.3f #define MOVEMENT_SKEW sf::Vector2f(1.f, 1/ISOMETRIC_SKEW/2.f) -#define WORLD_TO_ISO_SCALE 50.0f // 50.f +#define WORLD_TO_ISO_SCALE 10.0f // 50.f // Tracking view defaults #define DEF_TV_FREE_MOVE_THRESHOLD 0.f diff --git a/src/game/level/level_loader.cpp b/src/game/level/level_loader.cpp index e81b2bf..7ba7b1f 100644 --- a/src/game/level/level_loader.cpp +++ b/src/game/level/level_loader.cpp @@ -4,24 +4,29 @@ #include "../../debug/grid_debug_layer.h" #include "../player/player_spawner.hpp" #include "../../levels.hpp" +#include "../../sprites/ground_sprite.hpp" +#include "../../texture_config.h" -void LevelLoader::loadLevel(LevelConfig levelConfig) +void LevelLoader::loadLevel(const LevelConfig& levelConfig) { - Game::getInstance()->clearGameObjects(); + auto game = Game::getInstance(); + game->clearGameObjects(); LOG(INFO) << "Loading level '" << levelConfig.name << "' ..."; - Game::getInstance()->setLevel(levelConfig); + game->setLevel(levelConfig); MapSimulation::getInstance()->resetMap(levelConfig.worldMapSize); // Add basic game objects + game->addGameObject(new GroundSprite(GROUND_SKIN, levelConfig.worldMapSize)); + game->addGameObject(new TrackingView()); + game->addGameObject(new PlayerSpawner(levelConfig.playerSpawnPoints)); + if (DEVELOPER_MODE) { - Game::getInstance()->addGameObject(new GridDebugLayer(0, 50, 0, 50)); + game->addGameObject(new GridDebugLayer(0, 50, 0, 50)); } - Game::getInstance()->addGameObject(new TrackingView()); - Game::getInstance()->addGameObject(new PlayerSpawner(levelConfig.playerSpawnPoints)); LOG(INFO) << "Finished loading level '" << levelConfig.name << "'."; } diff --git a/src/game/level/level_loader.hpp b/src/game/level/level_loader.hpp index 8a62374..e1e8172 100644 --- a/src/game/level/level_loader.hpp +++ b/src/game/level/level_loader.hpp @@ -8,7 +8,7 @@ class LevelLoader { public: - static void loadLevel(LevelConfig levelConfig); + static void loadLevel(const LevelConfig& levelConfig); static void loadLevel(const std::string &levelName); }; diff --git a/src/game/player/player.hpp b/src/game/player/player.hpp index b08eea5..8c73046 100644 --- a/src/game/player/player.hpp +++ b/src/game/player/player.hpp @@ -3,7 +3,7 @@ #include "../game_object.h" #include "../camera/ITrackable.h" -#include "../../sprites/versatile_sprite.hpp" +#include "../../sprites/basic/versatile_sprite.hpp" #include "../input/input_identity.h" #include "../../config.h" diff --git a/src/main.cpp b/src/main.cpp index 99b8eaf..309fed6 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4,7 +4,7 @@ #include "debug/grid_debug_layer.h" #include "game/camera/tracking_view.h" #include "game/player/player_spawner.hpp" -#include "sprites/texture_manager.hpp" +#include "sprites/basic/texture_manager.hpp" #include "texture_config.h" #include "game/level/level_loader.hpp" #include "levels.hpp" diff --git a/src/sprites/animated_sprite.cpp b/src/sprites/basic/animated_sprite.cpp similarity index 94% rename from src/sprites/animated_sprite.cpp rename to src/sprites/basic/animated_sprite.cpp index e890e98..249d527 100644 --- a/src/sprites/animated_sprite.cpp +++ b/src/sprites/basic/animated_sprite.cpp @@ -1,6 +1,6 @@ #include "animated_sprite.hpp" -#include "../config.h" -#include "../logging/easylogging++.h" +#include "../../config.h" +#include "../../logging/easylogging++.h" AnimatedSprite::AnimatedSprite(const std::vector &sprites, const sf::Vector2f &size) { diff --git a/src/sprites/animated_sprite.hpp b/src/sprites/basic/animated_sprite.hpp similarity index 95% rename from src/sprites/animated_sprite.hpp rename to src/sprites/basic/animated_sprite.hpp index 5357499..cdca7a9 100644 --- a/src/sprites/animated_sprite.hpp +++ b/src/sprites/basic/animated_sprite.hpp @@ -3,7 +3,7 @@ #include -#include "../game/game_object.h" +#include "../../game/game_object.h" #include "sprite.hpp" class AnimatedSprite : public GameObject, public Sprite diff --git a/src/sprites/single_sprite.cpp b/src/sprites/basic/single_sprite.cpp similarity index 75% rename from src/sprites/single_sprite.cpp rename to src/sprites/basic/single_sprite.cpp index 94c5a34..8282455 100644 --- a/src/sprites/single_sprite.cpp +++ b/src/sprites/basic/single_sprite.cpp @@ -15,6 +15,15 @@ SingleSprite::SingleSprite(const std::shared_ptr &texture, const sf setSize(size); } +SingleSprite::SingleSprite(const std::shared_ptr &texture, const sf::Vector2f &size) +{ + sprite = sf::Sprite(); + sprite.setTexture(*texture->texture); + sprite.setTextureRect(texture->cutout); + + setSize(size); +} + void SingleSprite::draw(sf::RenderWindow *window) { sprite.setPosition(coordinates->isometric().toScreen()); @@ -37,3 +46,8 @@ sf::Vector2f SingleSprite::getSize() const auto textureSize = sprite.getTextureRect(); return {textureSize.width * sprite.getScale().x, textureSize.height * sprite.getScale().y}; } + +sf::Sprite SingleSprite::getSprite() const +{ + return sprite; +} diff --git a/src/sprites/single_sprite.hpp b/src/sprites/basic/single_sprite.hpp similarity index 74% rename from src/sprites/single_sprite.hpp rename to src/sprites/basic/single_sprite.hpp index 9757bcc..ccab91a 100644 --- a/src/sprites/single_sprite.hpp +++ b/src/sprites/basic/single_sprite.hpp @@ -3,14 +3,16 @@ #include -#include "../game/game_object.h" +#include "../../game/game_object.h" #include "sprite.hpp" +#include "texture_cutout.hpp" class SingleSprite : public GameObject, public Sprite { public: SingleSprite(const sf::Sprite &sprite, const sf::Vector2f &size = sf::Vector2f(0, 0)); + SingleSprite(const std::shared_ptr &texture, const sf::Vector2f &size = sf::Vector2f(0, 0)); SingleSprite(const std::shared_ptr &texture, const sf::Vector2f &size = sf::Vector2f(0, 0)); void draw(sf::RenderWindow *window) override; @@ -19,6 +21,8 @@ public: sf::Vector2f getSize() const override; + sf::Sprite getSprite() const; + private: sf::Sprite sprite; }; diff --git a/src/sprites/sprite.hpp b/src/sprites/basic/sprite.hpp similarity index 100% rename from src/sprites/sprite.hpp rename to src/sprites/basic/sprite.hpp diff --git a/src/sprites/sprite_factory.cpp b/src/sprites/basic/sprite_factory.cpp similarity index 74% rename from src/sprites/sprite_factory.cpp rename to src/sprites/basic/sprite_factory.cpp index 551d9c4..c1fdb0a 100644 --- a/src/sprites/sprite_factory.cpp +++ b/src/sprites/basic/sprite_factory.cpp @@ -1,47 +1,17 @@ #include "sprite_factory.hpp" -#include "../texture_config.h" +#include "../../texture_config.h" #include "texture_manager.hpp" std::shared_ptr SpriteFactory::createSingleSprite(const std::string& name, sf::Vector2f size) { - // Get sprite config - auto sprite_config = all_sprites.find(name); - - if (sprite_config == all_sprites.end()) + auto texture = createTextureForSprite(name); + if (texture == nullptr) { - LOG(ERROR) << "Sprite " << name << " not found. Could not create single sprite."; + LOG(ERROR) << "Texture for sprite " << name << " not found. Could not create single sprite."; return nullptr; } - // Construct sprite - auto config = sprite_config->second; - - // Construct simply from texture - if (!config.isFromSheet) - { - auto texture = TextureManager::getInstance()->getTexture(config.resourceName); - if (texture == nullptr) - { - LOG(ERROR) << "Texture " << config.resourceName << " not found. Could not create single sprite."; - return nullptr; - } - - LOG(INFO) << "Creating single sprite from texture " << config.resourceName; - return std::make_shared(texture, size); - } - - // Construct from sheet - auto sheet = createSheet(config.resourceName); - if (sheet == nullptr) - { - LOG(ERROR) << "Sheet " << config.resourceName << " not found. Could not create single sprite."; - return nullptr; - } - - LOG(INFO) << "Creating single sprite from sheet " << config.resourceName; - auto sprite = sheet->getSprite(config.sheetIndex); - sprite->setSize(size); - return sprite; + return std::make_shared(texture->texture, size); } std::shared_ptr SpriteFactory::createAnimatedSprite(const std::string& name, sf::Vector2f size) @@ -95,3 +65,42 @@ std::shared_ptr SpriteFactory::createSheet(const std::string& name) LOG(INFO) << "Creating sheet " << name; return std::make_shared(texture, config.columns, config.rows); } + +std::shared_ptr SpriteFactory::createTextureForSprite(const std::string &spriteName) +{ + // Get sprite config + auto sprite_config = all_sprites.find(spriteName); + + if (sprite_config == all_sprites.end()) + { + LOG(ERROR) << "Sprite " << spriteName << " not found. Could not create sprite texture cutout."; + return nullptr; + } + + // Construct sprite + auto config = sprite_config->second; + + // Construct simply from texture + if (!config.isFromSheet) + { + auto texture = TextureManager::getInstance()->getTexture(config.resourceName); + if (texture == nullptr) + { + LOG(ERROR) << "Texture " << config.resourceName << " not found. Could not create sprite texture cutout."; + return nullptr; + } + + return std::make_shared(texture); + } + + // Construct from sheet + auto sheet = createSheet(config.resourceName); + if (sheet == nullptr) + { + LOG(ERROR) << "Sheet " << config.resourceName << " not found. Could not create sprite texture cutout."; + return nullptr; + } + + LOG(INFO) << "Creating sprite texture cutout from sheet " << config.resourceName; + return sheet->getTextureCutout(config.sheetIndex); +} diff --git a/src/sprites/sprite_factory.hpp b/src/sprites/basic/sprite_factory.hpp similarity index 78% rename from src/sprites/sprite_factory.hpp rename to src/sprites/basic/sprite_factory.hpp index b6f55ad..43ce290 100644 --- a/src/sprites/sprite_factory.hpp +++ b/src/sprites/basic/sprite_factory.hpp @@ -7,7 +7,8 @@ #include "single_sprite.hpp" #include "animated_sprite.hpp" #include "sprite_sheet.hpp" -#include "../logging/easylogging++.h" +#include "../../logging/easylogging++.h" +#include "texture_cutout.hpp" class SpriteFactory { @@ -15,6 +16,7 @@ public: static std::shared_ptr createSingleSprite(const std::string& name, sf::Vector2f size = sf::Vector2f(0, 0)); static std::shared_ptr createAnimatedSprite(const std::string& name, sf::Vector2f size = sf::Vector2f(0, 0)); static std::shared_ptr createSheet(const std::string& name); + static std::shared_ptr createTextureForSprite(const std::string& spriteName); }; diff --git a/src/sprites/sprite_sheet.cpp b/src/sprites/basic/sprite_sheet.cpp similarity index 58% rename from src/sprites/sprite_sheet.cpp rename to src/sprites/basic/sprite_sheet.cpp index ef2c308..eafca5b 100644 --- a/src/sprites/sprite_sheet.cpp +++ b/src/sprites/basic/sprite_sheet.cpp @@ -1,37 +1,31 @@ #include "sprite_sheet.hpp" #include "single_sprite.hpp" -SpriteSheet::SpriteSheet(const std::shared_ptr& texture, int columns, int rows) +SpriteSheet::SpriteSheet(const std::shared_ptr &texture, int columns, int rows) { // Extract sprites from texture - sprites = std::vector(); + textureCutouts = {}; int spriteWidth = texture->getSize().x / columns; int spriteHeight = texture->getSize().y / rows; for (int y = 0; y < rows; y++) { for (int x = 0; x < columns; x++) { - sf::Sprite sprite; - sprite.setTexture(*texture); - sprite.setTextureRect(sf::IntRect(x * spriteWidth, y * spriteHeight, spriteWidth, spriteHeight)); - sprites.push_back(sprite); + auto rect = sf::IntRect(x * spriteWidth, y * spriteHeight, spriteWidth, spriteHeight); + std::shared_ptr cutout = std::make_shared(texture, rect); + textureCutouts.push_back(cutout); } } } std::shared_ptr SpriteSheet::getSprite(int sequenceIndex) const { - if (sequenceIndex < 0 || sequenceIndex >= sprites.size()) - { - throw std::runtime_error("Invalid sequence index"); - } - auto sprite = sprites[sequenceIndex]; - return std::make_shared(sprite); + return std::make_shared(getTextureCutout(sequenceIndex)); } std::shared_ptr SpriteSheet::getAnimation(int startingSequenceIndex, int numberOfFrames) const { - if (startingSequenceIndex < 0 || startingSequenceIndex + numberOfFrames > sprites.size()) + if (startingSequenceIndex < 0 || startingSequenceIndex + numberOfFrames > textureCutouts.size()) { throw std::runtime_error("Invalid starting sequence index"); } @@ -43,7 +37,16 @@ std::shared_ptr SpriteSheet::getAnimation(int startingSequenceIn std::vector animation = std::vector(); for (int i = 0; i < numberOfFrames; i++) { - animation.push_back(sprites[startingSequenceIndex + i]); + animation.push_back(getSprite(startingSequenceIndex + i)->getSprite()); } return std::make_shared(animation); } + +std::shared_ptr SpriteSheet::getTextureCutout(int sequenceIndex) const +{ + if (sequenceIndex < 0 || sequenceIndex >= textureCutouts.size()) + { + throw std::runtime_error("Invalid sequence index"); + } + return textureCutouts[sequenceIndex]; +} diff --git a/src/sprites/sprite_sheet.hpp b/src/sprites/basic/sprite_sheet.hpp similarity index 76% rename from src/sprites/sprite_sheet.hpp rename to src/sprites/basic/sprite_sheet.hpp index ff4b0f9..b3f40e6 100644 --- a/src/sprites/sprite_sheet.hpp +++ b/src/sprites/basic/sprite_sheet.hpp @@ -7,6 +7,7 @@ #include #include "animated_sprite.hpp" #include "single_sprite.hpp" +#include "texture_cutout.hpp" class SpriteSheet { @@ -17,8 +18,10 @@ public: std::shared_ptr getAnimation(int startingSequenceIndex, int numberOfFrames) const; + std::shared_ptr getTextureCutout(int sequenceIndex) const; + private: - std::vector sprites; + std::vector> textureCutouts; }; diff --git a/src/sprites/basic/texture_cutout.hpp b/src/sprites/basic/texture_cutout.hpp new file mode 100644 index 0000000..1435702 --- /dev/null +++ b/src/sprites/basic/texture_cutout.hpp @@ -0,0 +1,15 @@ +#ifndef HOLESOME_TEXTURE_CUTOUT_HPP +#define HOLESOME_TEXTURE_CUTOUT_HPP + +#include +#include +#include + +struct TextureCutout { + std::shared_ptr texture; + sf::IntRect cutout; + + TextureCutout(std::shared_ptr texture, sf::IntRect cutout = {}) : texture(std::move(texture)), cutout(cutout) {} +}; + +#endif //HOLESOME_TEXTURE_CUTOUT_HPP diff --git a/src/sprites/texture_manager.cpp b/src/sprites/basic/texture_manager.cpp similarity index 97% rename from src/sprites/texture_manager.cpp rename to src/sprites/basic/texture_manager.cpp index 7b4afbd..2620e97 100644 --- a/src/sprites/texture_manager.cpp +++ b/src/sprites/basic/texture_manager.cpp @@ -1,5 +1,5 @@ #include "texture_manager.hpp" -#include "../logging/easylogging++.h" +#include "../../logging/easylogging++.h" std::shared_ptr TextureManager::getInstance() { diff --git a/src/sprites/texture_manager.hpp b/src/sprites/basic/texture_manager.hpp similarity index 100% rename from src/sprites/texture_manager.hpp rename to src/sprites/basic/texture_manager.hpp diff --git a/src/sprites/versatile_sprite.cpp b/src/sprites/basic/versatile_sprite.cpp similarity index 97% rename from src/sprites/versatile_sprite.cpp rename to src/sprites/basic/versatile_sprite.cpp index 02b4a18..1401efa 100644 --- a/src/sprites/versatile_sprite.cpp +++ b/src/sprites/basic/versatile_sprite.cpp @@ -1,6 +1,6 @@ #include "versatile_sprite.hpp" #include "sprite_factory.hpp" -#include "../texture_config.h" +#include "../../texture_config.h" VersatileSprite::VersatileSprite(const std::string &name, sf::Vector2f size) { diff --git a/src/sprites/versatile_sprite.hpp b/src/sprites/basic/versatile_sprite.hpp similarity index 94% rename from src/sprites/versatile_sprite.hpp rename to src/sprites/basic/versatile_sprite.hpp index 7c97978..6c877c7 100644 --- a/src/sprites/versatile_sprite.hpp +++ b/src/sprites/basic/versatile_sprite.hpp @@ -5,7 +5,7 @@ #include #include #include "sprite.hpp" -#include "../game/game_object.h" +#include "../../game/game_object.h" #include "single_sprite.hpp" #include "animated_sprite.hpp" diff --git a/src/sprites/ground_sprite.cpp b/src/sprites/ground_sprite.cpp new file mode 100644 index 0000000..96192fe --- /dev/null +++ b/src/sprites/ground_sprite.cpp @@ -0,0 +1,66 @@ +#include +#include "ground_sprite.hpp" +#include "basic/sprite_factory.hpp" +#include "../config.h" + +GroundSprite::GroundSprite(const std::string &name, sf::Vector2f worldMapSize) +{ + this->worldMapSize = worldMapSize; + + constructGroundShape(); + + // Set Texture + auto texture = SpriteFactory::createTextureForSprite(name); + if (texture == nullptr) + { + LOG(ERROR) << "Texture " << name << " not found. Using simple fill color as fallback."; + groundShape.setFillColor(sf::Color::Green); + } else + { + setTexture(texture); + } +} + +void GroundSprite::setSize(const sf::Vector2f &size) +{ + worldMapSize = size; +} + +sf::Vector2f GroundSprite::getSize() const +{ + return worldMapSize; +} + +void GroundSprite::constructGroundShape() +{ + groundShape = sf::ConvexShape(); + groundShape.setPointCount(4); + + // Transform corners from world to iso space + sf::Vector2f left = CoordinateTransformer::worldToIsometric({0, worldMapSize.x}).toScreen(); + sf::Vector2f top = CoordinateTransformer::worldToIsometric(worldMapSize).toScreen(); + sf::Vector2f right = CoordinateTransformer::worldToIsometric({worldMapSize.y, 0}).toScreen(); + + groundShape.setPoint(0, {0, 0}); + groundShape.setPoint(1, left); + groundShape.setPoint(2, top); + groundShape.setPoint(3, right); +} + +void GroundSprite::draw(sf::RenderWindow *window) +{ + window->draw(groundShape); +} + +void GroundSprite::setTexture(const std::shared_ptr &textureCutout) +{ + auto texture = textureCutout->texture.get(); + texture->setRepeated(true); + + groundShape.setTexture(texture); + groundShape.setTextureRect(textureCutout->cutout); + + // Set scale + float scale = 1 / WORLD_TO_ISO_SCALE; + groundShape.scale(scale, scale / ISOMETRIC_SKEW); +} diff --git a/src/sprites/ground_sprite.hpp b/src/sprites/ground_sprite.hpp new file mode 100644 index 0000000..7e6b464 --- /dev/null +++ b/src/sprites/ground_sprite.hpp @@ -0,0 +1,30 @@ +#ifndef HOLESOME_GROUND_SPRITE_HPP +#define HOLESOME_GROUND_SPRITE_HPP + + +#include "basic/sprite.hpp" +#include "../game/game_object.h" +#include "basic/texture_cutout.hpp" + +class GroundSprite : public Sprite, public GameObject +{ +public: + GroundSprite(const std::string& name, sf::Vector2f worldMapSize); + + void setSize(const sf::Vector2f &size) override; + + sf::Vector2f getSize() const override; + + void draw(sf::RenderWindow *window) override; + +private: + sf::Vector2f worldMapSize; + sf::ConvexShape groundShape; + + void constructGroundShape(); + + void setTexture(const std::shared_ptr &textureCutout); +}; + + +#endif //HOLESOME_GROUND_SPRITE_HPP diff --git a/src/texture_config.h b/src/texture_config.h index 872ba00..568fea9 100644 --- a/src/texture_config.h +++ b/src/texture_config.h @@ -8,6 +8,7 @@ #include "sprites/configs/sprite_config.hpp" #define PLAYER_SKIN "ring" +#define GROUND_SKIN "simple_grass" /** * All textures used in the game. @@ -17,7 +18,8 @@ std::map const all_textures = { {"numbers", "assets/numbers.png"}, {"64", "assets/64.png"}, {"edge", "assets/edge.png"}, - {"ring", "assets/ring.png"} + {"ring", "assets/ring.png"}, + {"grasses", "assets/grass_plus.png"} }; /** @@ -25,7 +27,8 @@ std::map const all_textures = { * The key is the name of the sheet, the value is the sheet config. */ std::map const all_sheets = { - {"numbers", SheetConfig("numbers", 4, 2)} + {"numbers", SheetConfig("numbers", 4, 2)}, + {"grasses", SheetConfig("grasses", 25, 14)} }; /** @@ -43,7 +46,8 @@ std::map const all_animations = { std::map const all_sprites = { {"64", SpriteConfig("64")}, {"edge", SpriteConfig("edge")}, - {"ring", SpriteConfig("ring")} + {"ring", SpriteConfig("ring")}, + {"simple_grass", SpriteConfig("grasses", 58)} }; #endif //HOLESOME_TEXTURE_CONFIG_H