summaryrefslogtreecommitdiff
path: root/src/main.cpp
diff options
context:
space:
mode:
authorEkaitz Zarraga <ekaitz@elenq.tech>2022-11-17 13:00:52 +0100
committerEkaitz Zarraga <ekaitz@elenq.tech>2022-11-17 13:00:52 +0100
commitf2068ddb2fbed6c6bf6bffc3648327435886e603 (patch)
treea2325d5b9b94f61aa26deb20625c824032d9195c /src/main.cpp
parent1c2a216055a107c1ce8d9d6845be80df0e0764f4 (diff)
Add a simple resource manager
Diffstat (limited to 'src/main.cpp')
-rw-r--r--src/main.cpp21
1 files changed, 18 insertions, 3 deletions
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<gph::OneShotAnimation>(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<sf::Texture, TextureId> TextureManager;
+ TextureManager.load( TextureId::Angle1, "assets/img/Player/Player Angle 1 Sheet.png");
+
+ Unit unit = Unit(TextureManager.get(TextureId::Angle1));
renderWindow.setFramerateLimit(60);