[Added] Start of enemies

This commit is contained in:
Ninjaws
2024-12-16 22:27:06 +01:00
parent 5af531a08b
commit e8c78770b5
17 changed files with 580 additions and 101 deletions
+17 -1
View File
@@ -6,13 +6,16 @@
#include "services/MapService.h"
#include "entities/Vector2i.h"
#include "entities/Crate.h"
#include "entities/PBullet.h"
#include "entities/Jelly.h"
#include "entities/AmmoPack.h"
#include "entities/HealthPack.h"
#include "entities/Powerup.h"
#include "entities/Flag.h"
#include <vector>
/**
* Service that manages the collectables (jellies), consumables (Ammo, health, powerups), and the finish flag
*/
class CollectableService : public Service<CollectableService>
{
public:
@@ -23,6 +26,7 @@ public:
initAmmoPacks();
initHealthPacks();
initPowerups();
initFlag();
}
void collectableLogic()
@@ -32,6 +36,7 @@ public:
ammoPackLogic();
healthPackLogic();
powerupLogic();
flag.logic();
}
void drawCollectables()
@@ -41,6 +46,7 @@ public:
drawAmmoPacks();
drawHealthpacks();
drawPowerups();
flag.draw();
}
std::vector<Crate> &getCrates()
@@ -62,6 +68,10 @@ public:
return this->powerUps;
}
Flag& getFlag() {
return this->flag;
}
int getMaxAmountOfJellies()
{
return this->amountOfCrates;
@@ -82,6 +92,7 @@ private:
std::vector<HealthPack> healthPacks;
std::vector<Jelly> jellies;
std::vector<Powerup> powerUps;
Flag flag;
void initCrates()
{
@@ -146,6 +157,11 @@ private:
powerUps[0].getObject().setPosition({41.0f * tileSize+8, 10.0f * tileSize-25});
}
void initFlag() {
int tileSize = MapService::getInstance().getMap().getTileSize();
this->flag = Flag({118.0f*tileSize-tileSize/2.0f, 3.0f * tileSize-8});
}
void crateLogic()
{
for (auto it = crates.begin(); it != crates.end();)
+67
View File
@@ -0,0 +1,67 @@
#ifndef ENEMY_SERVICE_H
#define ENEMY_SERVICE_H
#include "raylib.h"
#include "services/Service.h"
#include "services/AssetService.h"
#include "entities/Enemy.h"
#include <optional>
class EnemyService : public Service<EnemyService>
{
public:
void initEnemies()
{
this->enemies.clear();
const int AMNT_OF_ENEMIES = 8;
int tileSize = MapService::getInstance().getMap().getTileSize();
for (int i = 0; i < AMNT_OF_ENEMIES; i++)
{
enemies.push_back(Enemy());
}
this->enemies[0].getObject().setPosition({31.0f * tileSize, 15.0f * tileSize});
this->enemies[1].getObject().setPosition({51.0f * tileSize, 10.0f * tileSize});
this->enemies[2].getObject().setPosition({56.0f * tileSize, 5.0f * tileSize});
this->enemies[3].getObject().setPosition({78.0f * tileSize, 10.0f * tileSize});
this->enemies[4].getObject().setPosition({82.0f * tileSize, 15.0f * tileSize});
this->enemies[5].getObject().setPosition({88.0f * tileSize, 4.0f * tileSize});
this->enemies[6].getObject().setPosition({98.0f * tileSize, 11.0f * tileSize});
this->enemies[7].getObject().setPosition({103.0f * tileSize, 15.0f * tileSize});
}
void enemyLogic()
{
for (auto it = enemies.begin(); it != enemies.end();)
{
auto &enemy = *it;
if (enemy.getObject().getPosition().y < 0)
{
it = enemies.erase(it);
}
else
{
enemy.logic();
++it;
}
}
}
void drawEnemies()
{
for (int i = 0; i < enemies.size(); i++)
{
enemies[i].draw();
}
}
std::vector<Enemy> &getEnemies()
{
return this->enemies;
}
protected:
private:
std::vector<Enemy> enemies;
};
#endif
-19
View File
@@ -58,25 +58,6 @@ public:
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();)