From 0af4ac70a7c66817fe69859e7a3a0c963645ece3 Mon Sep 17 00:00:00 2001 From: yasiupl Date: Wed, 15 Jan 2020 13:11:32 +0100 Subject: [PATCH] final edit --- app.h | 19 ------------------- entity.h | 5 ++++- game.h | 15 +++++++-------- menu.h | 3 ++- 4 files changed, 13 insertions(+), 29 deletions(-) diff --git a/app.h b/app.h index de4dd32..cd046a9 100644 --- a/app.h +++ b/app.h @@ -11,8 +11,6 @@ class App { bool active = true; bool paused = false; - std::vector overlays; - public: App(sf::RenderWindow *_window) { window = _window; @@ -31,19 +29,6 @@ class App { } } - void addOverlay(App *overlay) { - overlay->stop(); - overlays.push_back(overlay); - } - - void removeOverlay(App *overlay) { - for(int i = 0; i < (int)overlays.size(); ++i) { - if(overlay == overlays[i]){ - overlays.erase(overlays.begin()+i); - } - } - } - bool isActive() { return active; } @@ -87,10 +72,6 @@ class App { window->clear(); if(!paused) consumeInput(); this->drawFrame(); - for(int i = 0; i < (int)overlays.size(); ++i) { - overlays[i]->consumeInput(); - overlays[i]->drawFrame(); - } window->display(); if(active) loop(); } diff --git a/entity.h b/entity.h index cce5ecc..a32f1c9 100644 --- a/entity.h +++ b/entity.h @@ -63,10 +63,13 @@ class Entity { void draw(sf::RenderTarget* target) { if(active == true) { + cooldownTime = cooldownTimer.getElapsedTime() - pauseTime; animationTime = animationTimer.getElapsedTime() - pauseTime; pauseTime = pauseTime.Zero; animate(); - } else animationTimer.restart(); + } else { + animationTimer.restart(); + } target->draw(sprite); } diff --git a/game.h b/game.h index 7dcd87f..59f2a5e 100644 --- a/game.h +++ b/game.h @@ -60,6 +60,13 @@ class Game: public App { backdrop.setPosition(bbox.left, bbox.top); } + virtual ~Game() { + for(int i = 0; i < (int)renderQueue.size(); ++i) { + delete renderQueue[i]; + renderQueue.erase(renderQueue.begin() + i); + } + } + void consumeInput() { sf::Event event; @@ -118,9 +125,7 @@ class Game: public App { Menu *pause_menu = new Menu(this); pause_menu->addOption("Resume", [](App *_this, App *parent) { - //parent->removeOverlay(_this); parent->activate(); - //delete _this; }); pause_menu->addOption("Exit", [](App *_this, App *parent) @@ -137,7 +142,6 @@ class Game: public App { }); confirmation.loop(); }); - //this->addOverlay(pause_menu); pause_menu->loop(); } if (sf::Keyboard::isKeyPressed(sf::Keyboard::F1)) @@ -146,9 +150,7 @@ class Game: public App { Menu *f1_menu = new Menu(this); f1_menu->addOption("Resume", [](App *_this, App *parent) { - //parent->removeOverlay(_this); parent->activate(); - //delete _this; }); f1_menu->addOption("The premise of the game consists of"); @@ -158,7 +160,6 @@ class Game: public App { f1_menu->addOption("E shoots a missle."); f1_menu->loop(); - //this->addOverlay(f1_menu); } sf::Vector2i point = sf::Mouse::getPosition(*window); @@ -201,8 +202,6 @@ class Game: public App { }); confirmation.loop(); }); - - delete falcon; gameover_menu.loop(); } diff --git a/menu.h b/menu.h index e4d64f4..4e8e8b4 100644 --- a/menu.h +++ b/menu.h @@ -87,6 +87,7 @@ class Menu: public App { callbacks.push_back([](App *menu, App *parent) {menu->activate();}); for(int i = 0; i < (int)options.size(); ++i) { + logo.setPosition(size.x/2, (size.y/2) - options.size() * textRect.height * 2); options[i].setPosition(sf::Vector2f(size.x / 2, (size.y / 2) - (options.size() * textRect.height * 2)/2 + textRect.height * 2 * i)); } } @@ -99,7 +100,7 @@ class Menu: public App { logoTexture.setSmooth(true); logo.setTexture(logoTexture); sf::FloatRect logoRect = logo.getLocalBounds(); - logo.setOrigin(logoRect.width/2,logoRect.height/2); + logo.setOrigin(logoRect.width/2,logoRect.height); logo.setPosition(size.x/2, size.y/3); }