diff options
author | Ekaitz Zarraga <ekaitz@elenq.tech> | 2022-11-29 18:19:25 +0100 |
---|---|---|
committer | Ekaitz Zarraga <ekaitz@elenq.tech> | 2022-11-29 18:19:25 +0100 |
commit | bf34d835e4ea49bd4ef2e5de2b1fea2fd3c95adc (patch) | |
tree | b1970daefeb7a6a8f406c83126de49c3b928484e /src/main.cpp | |
parent | cbf859a37aa6b16db7e53cf75405cda720617392 (diff) |
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
Diffstat (limited to 'src/main.cpp')
-rw-r--r-- | src/main.cpp | 96 |
1 files changed, 5 insertions, 91 deletions
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<SFML/Graphics.hpp> -#include<vector> -#include<cstdio> -#include<cmath> +#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; } |