From f2068ddb2fbed6c6bf6bffc3648327435886e603 Mon Sep 17 00:00:00 2001 From: Ekaitz Zarraga Date: Thu, 17 Nov 2022 13:00:52 +0100 Subject: Add a simple resource manager --- src/main.cpp | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) (limited to 'src/main.cpp') diff --git a/src/main.cpp b/src/main.cpp index 94bf125..bd330fc 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -5,6 +5,7 @@ #include "graphics/animation.h" #include "entity.h" +#include "resourceManager.h" namespace gph = Graphics; @@ -34,8 +35,8 @@ class Unit: Entity{ sf::Vector2f speed; - Unit(){ - spritesheet_.loadFromFile("assets/img/Player/Player Angle 1 Sheet.png"); + Unit(sf::Texture& spritesheet){ + spritesheet_ = spritesheet; standing_animation = gph::Animation(spritesheet_, 6, 60, 44, 48, 0); walking_animation = gph::Animation(spritesheet_, 8, 60, 44, 48, 1); shooting_animation = gph::FlippedAnimation(spritesheet_, 6, 60, 44, 48, 2); @@ -66,16 +67,30 @@ class Unit: Entity{ sprite.setScale(8,8); sprite.setTextureRect(current_animation->next(dt)); sprite.setPosition(position.x, position.y); + sprite = sprite; } }; + +enum class TextureId{ + Angle1, + Angle2, + Front, + Back, + Side +}; + int main() { sf::RenderWindow renderWindow(sf::VideoMode(640, 480), "Demo Game"); sf::Event event; sf::Clock clock; - Unit unit; + + ResourceManager TextureManager; + TextureManager.load( TextureId::Angle1, "assets/img/Player/Player Angle 1 Sheet.png"); + + Unit unit = Unit(TextureManager.get(TextureId::Angle1)); renderWindow.setFramerateLimit(60); -- cgit v1.2.3