[Added] The ability to fire bullets to the player

This commit is contained in:
Ninjaws
2024-12-13 22:04:33 +01:00
parent 88e0b7cb05
commit 55792bb954
7 changed files with 266 additions and 9 deletions
+57
View File
@@ -3,6 +3,9 @@
#include "services/Service.h"
#include "entities/Game.h"
#include "entities/PBullet.h"
#include <vector>
#include <list>
class GameService : public Service<GameService>
{
@@ -52,10 +55,64 @@ public:
// return this->game;
// }
void addPlayerBullet(PBullet bullet)
{
this->playerBullets.push_back(bullet);
}
// std::list<PBullet>& getPlayerBullets() {
// return this->playerBullets;
// }
// void removeCollidedBullets()
// {
// for (auto it = playerBullets.begin(); it != playerBullets.end(); /* no increment here */)
// {
// if (it->getHasCollided())
// {
// it = playerBullets.erase(it); // Remove element and get the next valid iterator
// }
// else
// {
// ++it; // Only increment if no removal happens
// }
// }
// }
void bulletLogic()
{
for (auto it = this->playerBullets.begin(); it != this->playerBullets.end();)
{
it->logic();
if (it->getHasCollided())
it = this->playerBullets.erase(it);
else
++it;
}
}
void drawBullets()
{
for (auto it = this->playerBullets.begin(); it != this->playerBullets.end();)
{
it->draw();
++it;
}
}
void resetGame()
{
paused = false;
gameOver = false;
// playerBullets.clear();
}
private:
bool paused = false;
bool gameOver = false;
Camera2D camera;
std::list<PBullet> playerBullets;
};
#endif