diff --git a/src/Game.cpp b/src/Game.cpp index 97602cd..2fa0a24 100644 --- a/src/Game.cpp +++ b/src/Game.cpp @@ -8,13 +8,6 @@ using namespace std::literals::chrono_literals; -Game::~Game() -{ - for (const Arrow *arrow : arrows) { - delete arrow; - } -} - void Game::update(std::stop_token stop_token) { while (!stop_token.stop_requested()) { @@ -25,16 +18,16 @@ void Game::update(std::stop_token stop_token) player.update(); - for (Arrow *arrow : arrows) { - arrow->update(); + for (auto& arrow : arrows) { + arrow.update(); } - for (Zombo *zombo : zombos) { - zombo->update(player.x, player.y); + for (auto& zombo : zombos) { + zombo.update(player.x, player.y); } if (ticks % 1000 == 0) { - zombos.push_back(new Zombo(&renderer, 20.0, 20.0)); // doesn't work :(((( + zombos.push_back(Zombo(&renderer, 20.0, 20.0)); // doesn't work :(((( } renderer.redraw(); @@ -54,8 +47,8 @@ void Game::draw() map.draw(player.x, player.y); - for (const Arrow *arrow : arrows) { - arrow->draw(player.x, player.y); + for (const auto& arrow : arrows) { + arrow. draw(player.x, player.y); } player.draw(); @@ -117,7 +110,7 @@ void Game::run() } if (e.type == SDL_MOUSEBUTTONDOWN && e.button.button == 1) { - arrows.push_back(new Arrow(&renderer, player.x, player.y, player.angle)); + arrows.push_back(Arrow(&renderer, player.x, player.y, player.angle)); } int mouse_x, mouse_y; diff --git a/src/Game.hpp b/src/Game.hpp index c4060d9..5c77863 100644 --- a/src/Game.hpp +++ b/src/Game.hpp @@ -1,7 +1,6 @@ #ifndef GAME_HPP #define GAME_HPP -#include #include #include #include "Arrow.hpp" @@ -16,8 +15,8 @@ private: GameRenderer renderer; Player player; Map map; - std::vector arrows; - std::vector zombos; + std::vector arrows; + std::vector zombos; std::mutex game_mutex; unsigned int ticks = 0; @@ -27,8 +26,6 @@ private: public: Game() : renderer("Zombo Shooter", 800, 450), player(&renderer), map(&renderer, 40) {} - ~Game(); - void run(); void draw();