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;
|
using namespace std::literals::chrono_literals;
|
||||||
|
|
||||||
Game::~Game()
|
|
||||||
{
|
|
||||||
for (const Arrow *arrow : arrows) {
|
|
||||||
delete arrow;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void Game::update(std::stop_token stop_token)
|
void Game::update(std::stop_token stop_token)
|
||||||
{
|
{
|
||||||
while (!stop_token.stop_requested()) {
|
while (!stop_token.stop_requested()) {
|
||||||
@ -25,16 +18,16 @@ void Game::update(std::stop_token stop_token)
|
|||||||
|
|
||||||
player.update();
|
player.update();
|
||||||
|
|
||||||
for (Arrow *arrow : arrows) {
|
for (auto& arrow : arrows) {
|
||||||
arrow->update();
|
arrow.update();
|
||||||
}
|
}
|
||||||
|
|
||||||
for (Zombo *zombo : zombos) {
|
for (auto& zombo : zombos) {
|
||||||
zombo->update(player.x, player.y);
|
zombo.update(player.x, player.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ticks % 1000 == 0) {
|
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();
|
renderer.redraw();
|
||||||
@ -54,8 +47,8 @@ void Game::draw()
|
|||||||
|
|
||||||
map.draw(player.x, player.y);
|
map.draw(player.x, player.y);
|
||||||
|
|
||||||
for (const Arrow *arrow : arrows) {
|
for (const auto& arrow : arrows) {
|
||||||
arrow->draw(player.x, player.y);
|
arrow. draw(player.x, player.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
player.draw();
|
player.draw();
|
||||||
@ -117,7 +110,7 @@ void Game::run()
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (e.type == SDL_MOUSEBUTTONDOWN && e.button.button == 1) {
|
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;
|
int mouse_x, mouse_y;
|
||||||
|
|||||||
@ -1,7 +1,6 @@
|
|||||||
#ifndef GAME_HPP
|
#ifndef GAME_HPP
|
||||||
#define GAME_HPP
|
#define GAME_HPP
|
||||||
|
|
||||||
#include <thread>
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
#include "Arrow.hpp"
|
#include "Arrow.hpp"
|
||||||
@ -16,8 +15,8 @@ private:
|
|||||||
GameRenderer renderer;
|
GameRenderer renderer;
|
||||||
Player player;
|
Player player;
|
||||||
Map map;
|
Map map;
|
||||||
std::vector<Arrow*> arrows;
|
std::vector<Arrow> arrows;
|
||||||
std::vector<Zombo*> zombos;
|
std::vector<Zombo> zombos;
|
||||||
|
|
||||||
std::mutex game_mutex;
|
std::mutex game_mutex;
|
||||||
unsigned int ticks = 0;
|
unsigned int ticks = 0;
|
||||||
@ -27,8 +26,6 @@ private:
|
|||||||
public:
|
public:
|
||||||
Game() : renderer("Zombo Shooter", 800, 450), player(&renderer), map(&renderer, 40) {}
|
Game() : renderer("Zombo Shooter", 800, 450), player(&renderer), map(&renderer, 40) {}
|
||||||
|
|
||||||
~Game();
|
|
||||||
|
|
||||||
void run();
|
void run();
|
||||||
|
|
||||||
void draw();
|
void draw();
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user