aboutsummaryrefslogtreecommitdiff
path: root/game/enemy
diff options
context:
space:
mode:
authorWBoerenkamps <wrj.boerenkamps@student.avans.nl>2025-01-08 13:52:22 +0100
committerWBoerenkamps <wrj.boerenkamps@student.avans.nl>2025-01-08 13:52:22 +0100
commit1413beea3b506b15b9f0080cec29c745d1ef88da (patch)
treef09efac3543adb16ea21b1d04d2c2cd4fb181d69 /game/enemy
parent1e25ce23534c1dcc7bebfc9fe33c1b587f15643a (diff)
pooling fix
Diffstat (limited to 'game/enemy')
-rw-r--r--game/enemy/EnemyBulletPool.cpp5
-rw-r--r--game/enemy/EnemyBulletSubScene.cpp5
-rw-r--r--game/enemy/EnemyBulletSubScene.h2
-rw-r--r--game/enemy/EnemyPool.cpp5
-rw-r--r--game/enemy/EnemyScript.cpp1
-rw-r--r--game/enemy/EnemySubScene.cpp4
-rw-r--r--game/enemy/EnemySubScene.h2
7 files changed, 13 insertions, 11 deletions
diff --git a/game/enemy/EnemyBulletPool.cpp b/game/enemy/EnemyBulletPool.cpp
index 6ebd50a..63afca3 100644
--- a/game/enemy/EnemyBulletPool.cpp
+++ b/game/enemy/EnemyBulletPool.cpp
@@ -4,5 +4,8 @@ using namespace std;
void EnemyBulletPool::create_bullets(crepe::Scene & scn) {
EnemyBulletSubScene bullet;
- while(bullet.create(scn) < this->MAXIMUM_AMOUNT);
+ int amount = 0;
+ while (amount < this->MAXIMUM_AMOUNT) {
+ amount = bullet.create(scn, amount);
+ }
}
diff --git a/game/enemy/EnemyBulletSubScene.cpp b/game/enemy/EnemyBulletSubScene.cpp
index 96ea7de..4f95ce4 100644
--- a/game/enemy/EnemyBulletSubScene.cpp
+++ b/game/enemy/EnemyBulletSubScene.cpp
@@ -18,10 +18,7 @@
#include "../Random.h"
using namespace crepe;
using namespace std;
-int EnemyBulletSubScene::create(Scene & scn){
- vec2 size = {20, 20};
-
- static int counter = 0;
+int EnemyBulletSubScene::create(Scene & scn, int counter){
string unique_name = "enemy_bullet_" + to_string(counter++);
GameObject bullet = scn.new_object(unique_name.c_str(),"enemy_bullet",ENEMY_BULLET_POOL_LOCATION,0,1);
diff --git a/game/enemy/EnemyBulletSubScene.h b/game/enemy/EnemyBulletSubScene.h
index a7e30d7..ac78ad9 100644
--- a/game/enemy/EnemyBulletSubScene.h
+++ b/game/enemy/EnemyBulletSubScene.h
@@ -6,5 +6,5 @@ class Scene;
class EnemyBulletSubScene {
public:
- int create(crepe::Scene & scn);
+ int create(crepe::Scene & scn, int counter);
};
diff --git a/game/enemy/EnemyPool.cpp b/game/enemy/EnemyPool.cpp
index b5160db..50d0e6a 100644
--- a/game/enemy/EnemyPool.cpp
+++ b/game/enemy/EnemyPool.cpp
@@ -3,5 +3,8 @@
using namespace std;
void EnemyPool::create_enemies(crepe::Scene & scn) {
EnemySubScene enemy;
- while(enemy.create(scn) < this->MAXIMUM_AMOUNT);
+ int amount = 0;
+ while (amount < this->MAXIMUM_AMOUNT) {
+ amount = enemy.create(scn, amount);
+ }
}
diff --git a/game/enemy/EnemyScript.cpp b/game/enemy/EnemyScript.cpp
index 0494bbc..e87a58e 100644
--- a/game/enemy/EnemyScript.cpp
+++ b/game/enemy/EnemyScript.cpp
@@ -75,6 +75,7 @@ bool EnemyScript::spawn_enemy(const SpawnEnemyEvent& e){
ai_component.path.clear();
ai_component.make_oval_path(10, 10, vec2{x_value,random_height}, 1.5708, true);
ai_component.active = true;
+ this->last_fired = std::chrono::steady_clock::now();
return true;
}
diff --git a/game/enemy/EnemySubScene.cpp b/game/enemy/EnemySubScene.cpp
index 66aedd5..82401a1 100644
--- a/game/enemy/EnemySubScene.cpp
+++ b/game/enemy/EnemySubScene.cpp
@@ -18,10 +18,8 @@
using namespace crepe;
using namespace std;
//#TODO add sound
-int EnemySubScene::create(Scene & scn){
- vec2 size = {20, 20};
+int EnemySubScene::create(Scene & scn,int enemy_counter){
- static int enemy_counter = 0;
string unique_name = "enemy_" + to_string(enemy_counter++);
GameObject enemy = scn.new_object(unique_name.c_str(),"enemy",ENEMY_POOL_LOCATION,0,1);
diff --git a/game/enemy/EnemySubScene.h b/game/enemy/EnemySubScene.h
index a24020b..68bb9a1 100644
--- a/game/enemy/EnemySubScene.h
+++ b/game/enemy/EnemySubScene.h
@@ -6,5 +6,5 @@ class Scene;
class EnemySubScene {
public:
- int create(crepe::Scene & scn);
+ int create(crepe::Scene & scn,int enemy_counter);
};