#include #include #include #include #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 ne_shooting_animation; gph::Animation se_shooting_animation; gph::Animation& current_animation = ne_shooting_animation; sf::Sprite sprite; sf::Vector2f position; sf::Vector2f size; sf::Vector2f speed; 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; current_animation.reset(); // current_animation = &walking_animation; } void shoot(){ current_animation.reset(); // current_animation = &shooting_animation; } ~Unit(){}; void update(sf::Time dt){ current_animation.update( dt); } }; int main() { sf::RenderWindow renderWindow(sf::VideoMode(640, 480), "Demo Game"); sf::Event event; sf::Clock clock; 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); renderWindow.setFramerateLimit(60); sf::Time elapsed_time = sf::Time::Zero; bool once = true; while (renderWindow.isOpen()){ sf::Time dt = clock.getElapsedTime(); elapsed_time += dt; clock.restart(); while (renderWindow.pollEvent(event)){ if (event.type == sf::Event::EventType::Closed) renderWindow.close(); } if(elapsed_time > sf::milliseconds(4000) && once){ unit.current_animation.reset(); unit.current_animation = unit.se_shooting_animation; once = false; } unit.update(dt); renderWindow.clear(); renderWindow.draw(unit.current_animation); renderWindow.display(); } }