Skip to content

Commit

Permalink
final edit
Browse files Browse the repository at this point in the history
  • Loading branch information
yasiupl committed Jan 15, 2020
1 parent 485ecea commit 0af4ac7
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 29 deletions.
19 changes: 0 additions & 19 deletions app.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ class App {
bool active = true;
bool paused = false;

std::vector<App*> overlays;

public:
App(sf::RenderWindow *_window) {
window = _window;
Expand All @@ -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;
}
Expand Down Expand Up @@ -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();
}
Expand Down
5 changes: 4 additions & 1 deletion entity.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
15 changes: 7 additions & 8 deletions game.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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)
Expand All @@ -137,7 +142,6 @@ class Game: public App {
});
confirmation.loop();
});
//this->addOverlay(pause_menu);
pause_menu->loop();
}
if (sf::Keyboard::isKeyPressed(sf::Keyboard::F1))
Expand All @@ -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");
Expand All @@ -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);
Expand Down Expand Up @@ -201,8 +202,6 @@ class Game: public App {
});
confirmation.loop();
});

delete falcon;
gameover_menu.loop();

}
Expand Down
3 changes: 2 additions & 1 deletion menu.h
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}
Expand All @@ -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);
}

Expand Down

0 comments on commit 0af4ac7

Please sign in to comment.