refactor: re-organize code

This commit is contained in:
2024-01-09 16:21:57 +01:00
parent 8d542b6484
commit 15c745d7c0
14 changed files with 126 additions and 146 deletions
+9 -44
View File
@@ -1,51 +1,16 @@
#include "main.h";
using namespace std;
#include <iostream>
#include "GameManager.h"
int main()
{
RenderWindow window(VideoMode(SCREEN_SIZE, SCREEN_SIZE), "Space Invader", Style::Titlebar | Style::Close);
window.setFramerateLimit(60);
window.setVerticalSyncEnabled(true);
cout << "Starting game..." << endl;
GameManager gameManager;
Player player(SCREEN_SIZE);
vector<RectangleShape> lasers;
Inputs inputs(player, lasers);
while (window.isOpen())
{
Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
{
window.close();
}
}
// Handle user's inputs
inputs.HandleInputs();
window.clear(Color::Black);
// Draw everything
window.draw(player.getShape());
for (vector<RectangleShape>::iterator it = lasers.begin(); it < lasers.end();) {
window.draw(*it);
it->move(0, -5);
if (it->getPosition().y < -it->getScale().y) {
it = lasers.erase(it);
}
else {
lasers[distance(lasers.begin(), it)] = *it;
++it;
}
}
// Display window
window.display();
}
cout << "Game started." << endl;
gameManager.run();
return 0;
}