From bf34d835e4ea49bd4ef2e5de2b1fea2fd3c95adc Mon Sep 17 00:00:00 2001 From: Ekaitz Zarraga Date: Tue, 29 Nov 2022 18:19:25 +0100 Subject: Start to use a normal game structure: - App class that has a StateStack - StateStack - Some State definiton and a minimal TitleState to use as a template - Makefile updated accordingly - Delete old code that was there for testing --- src/main.cpp | 96 ++++-------------------------------------------------------- 1 file changed, 5 insertions(+), 91 deletions(-) (limited to 'src/main.cpp') diff --git a/src/main.cpp b/src/main.cpp index 45c2b3a..65b7d5b 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,93 +1,7 @@ -#include -#include -#include -#include +#include "app.h" -#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(); - } +int main (int argc, char* argv[]){ + App app; + app.run(); + return 0; } -- cgit v1.2.3