don't use new and delete
This commit is contained in:
parent
012d021a08
commit
127b96a92f
23
src/Game.cpp
23
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;
|
||||
|
||||
@ -1,7 +1,6 @@
|
||||
#ifndef GAME_HPP
|
||||
#define GAME_HPP
|
||||
|
||||
#include <thread>
|
||||
#include <vector>
|
||||
#include <mutex>
|
||||
#include "Arrow.hpp"
|
||||
@ -16,8 +15,8 @@ private:
|
||||
GameRenderer renderer;
|
||||
Player player;
|
||||
Map map;
|
||||
std::vector<Arrow*> arrows;
|
||||
std::vector<Zombo*> zombos;
|
||||
std::vector<Arrow> arrows;
|
||||
std::vector<Zombo> 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();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user