diff options
author | Ekaitz Zarraga <ekaitz@elenq.tech> | 2022-11-17 17:35:05 +0100 |
---|---|---|
committer | Ekaitz Zarraga <ekaitz@elenq.tech> | 2022-11-17 17:35:05 +0100 |
commit | caa4862698f85561e08523c1c0351725a65c5faa (patch) | |
tree | 799206e6db2ec9713eda455024b18cc3dbf267b3 /src | |
parent | 82598dbaac1bc99a0a4f99833b68915ffbec0495 (diff) |
Add resource Id control class
Diffstat (limited to 'src')
-rw-r--r-- | src/main.cpp | 33 | ||||
-rw-r--r-- | src/resourceIds.h | 15 |
2 files changed, 30 insertions, 18 deletions
diff --git a/src/main.cpp b/src/main.cpp index 02697d7..45c2b3a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -6,16 +6,19 @@ #include "graphics/animation.h" #include "entity.h" #include "resourceManager.h" +#include "resourceIds.h" namespace gph = Graphics; + class Unit: Entity{ private: sf::Texture spritesheet_; public: - gph::Animation dying_animation; - gph::Animation& current_animation = dying_animation; + gph::Animation ne_shooting_animation; + gph::Animation se_shooting_animation; + gph::Animation& current_animation = ne_shooting_animation; sf::Sprite sprite; sf::Vector2f position; @@ -23,14 +26,14 @@ class Unit: Entity{ sf::Vector2f speed; - Unit(sf::Texture& spritesheet){ - spritesheet_ = spritesheet; - dying_animation = gph::Animation(spritesheet_, 14, sf::milliseconds(1400), false); - current_animation = dying_animation; + Unit(TextureManager& textures){ + ne_shooting_animation = gph::Animation(textures.get(Textures::Id::Player_NE_Shooting), 6, sf::milliseconds(100 * 6), false); + se_shooting_animation = gph::Animation(textures.get(Textures::Id::Player_SE_Shooting), 6, sf::milliseconds(100 * 6), false); + current_animation = ne_shooting_animation; position = sf::Vector2f{0,0}; speed = sf::Vector2f{0,0}; - }; + } void walk(float vx, float vy){ speed.y = vy; speed.x = vx; @@ -48,14 +51,6 @@ class Unit: Entity{ }; -enum class TextureId{ - Angle1, - Angle2, - Front, - Back, - Side -}; - int main() { sf::RenderWindow renderWindow(sf::VideoMode(640, 480), "Demo Game"); @@ -63,10 +58,11 @@ int main() sf::Event event; sf::Clock clock; - ResourceManager<sf::Texture, TextureId> TextureManager; - TextureManager.load( TextureId::Angle1, "assets/img/Player/angle1-dying.png"); + TextureManager textureManager; + textureManager.load(Textures::Id::Player_NE_Shooting, "assets/img/Player/angle2-shooting.png"); + textureManager.load(Textures::Id::Player_SE_Shooting, "assets/img/Player/angle1-shooting.png"); - Unit unit = Unit(TextureManager.get(TextureId::Angle1)); + Unit unit = Unit(textureManager); renderWindow.setFramerateLimit(60); @@ -84,6 +80,7 @@ int main() if(elapsed_time > sf::milliseconds(4000) && once){ unit.current_animation.reset(); + unit.current_animation = unit.se_shooting_animation; once = false; } diff --git a/src/resourceIds.h b/src/resourceIds.h new file mode 100644 index 0000000..9236fb6 --- /dev/null +++ b/src/resourceIds.h @@ -0,0 +1,15 @@ +#ifndef RESOURCE_IDS_H +#define RESOURCE_IDS_H + +#include "resourceManager.h" + +namespace Textures{ + enum class Id{ + Player_NE_Shooting, + Player_SE_Shooting, + }; +} + +using TextureManager = ResourceManager<sf::Texture, Textures::Id>; + +#endif // RESOURCE_IDS_H |