Skip to content

Commit 42d343b

Browse files
committed
feat(Game/boss) : add the setup to implement our second boss by creating an id that we will provide in json and use to separate the different patterns attacks, beginning by first method that will shoot wave animated bullet
1 parent 492b2c9 commit 42d343b

5 files changed

Lines changed: 82 additions & 23 deletions

File tree

assets/levels/level2.json

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@
2626
"powerup-force-pod": "assets/powerups/force_pod.png",
2727
"powerup-speed": "assets/powerups/speed.png",
2828
"powerup-shield": "assets/powerups/shield.png",
29-
"boss_dragon": "assets/boss/boss_dragon.png"
29+
"boss_2": "assets/boss/boss_2.png",
30+
"wave_attack": "assets/boss/attacks/boss 2/wave_attack.png"
3031
},
3132
"fonts": {
3233
"main": {
@@ -965,13 +966,14 @@
965966
}
966967
],
967968
"boss": {
968-
"texture": "boss_dragon",
969+
"texture": "boss_2",
969970
"position": { "x": 1000.0, "y": 200.0 },
970-
"width": 384.0,
971-
"height": 564.0,
971+
"width": 228.0,
972+
"height": 188.0,
972973
"health": 1000,
973974
"scrollSpeed": -75.0,
974-
"attackPattern": 1
975+
"attackPattern": 1,
976+
"bossId": 2
975977
},
976978
"enemies": [],
977979
"playerSpawns": [

libs/engine/include/ECS/BossAttackSystem.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ namespace RType {
2828
void CreateBossBullet(Registry& registry, float x, float y, float angle, float speed);
2929
void CreateBlackOrb(Registry& registry, Entity bossEntity, float bossX, float bossY);
3030
void CreateThirdBullet(Registry& registry, Entity bossEntity, float bossX, float bossY);
31+
32+
void CreateAnimatedOrb(Registry& registry, Entity bossEntity, float bossX, float bossY);
3133
};
3234

3335
}

libs/engine/include/ECS/LevelLoader.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ namespace RType {
5757
int health = 1000;
5858
float scrollSpeed = -300.0f;
5959
int attackPattern = 1;
60+
uint8_t bossId = 1;
6061
};
6162

6263
struct PlayerSpawnDef {

libs/engine/src/ECS/BossAttackSystem.cpp

Lines changed: 65 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -35,33 +35,41 @@ namespace RType {
3535
}
3636

3737
if (!registry.HasComponent<BossAttack>(bossEntity) ||
38-
!registry.HasComponent<Position>(bossEntity)) {
38+
!registry.HasComponent<Position>(bossEntity) ||
39+
!registry.HasComponent<Boss>(bossEntity)) {
3940
continue;
4041
}
4142

4243
auto& attack = registry.GetComponent<BossAttack>(bossEntity);
4344
const auto& pos = registry.GetComponent<Position>(bossEntity);
45+
const auto& boss = registry.GetComponent<Boss>(bossEntity);
4446

4547
attack.timeSinceLastAttack += deltaTime;
4648

4749
if (attack.timeSinceLastAttack >= attack.attackCooldown) {
4850
attack.timeSinceLastAttack = 0.0f;
4951

50-
switch (attack.currentPattern) {
51-
case BossAttackPattern::FAN_SPRAY:
52-
CreateFanSpray(registry, bossEntity, pos.x, pos.y);
53-
attack.currentPattern = BossAttackPattern::THIRD_BULLET;
54-
break;
55-
case BossAttackPattern::THIRD_BULLET:
56-
CreateThirdBullet(registry, bossEntity, pos.x, pos.y);
57-
attack.currentPattern = BossAttackPattern::BLACK_ORB;
58-
break;
59-
case BossAttackPattern::BLACK_ORB:
60-
CreateBlackOrb(registry, bossEntity, pos.x, pos.y);
61-
attack.currentPattern = BossAttackPattern::FAN_SPRAY;
62-
break;
63-
default:
64-
break;
52+
if (boss.bossId == 1) {
53+
// Boss 1
54+
switch (attack.currentPattern) {
55+
case BossAttackPattern::FAN_SPRAY:
56+
CreateFanSpray(registry, bossEntity, pos.x, pos.y);
57+
attack.currentPattern = BossAttackPattern::THIRD_BULLET;
58+
break;
59+
case BossAttackPattern::THIRD_BULLET:
60+
CreateThirdBullet(registry, bossEntity, pos.x, pos.y);
61+
attack.currentPattern = BossAttackPattern::BLACK_ORB;
62+
break;
63+
case BossAttackPattern::BLACK_ORB:
64+
CreateBlackOrb(registry, bossEntity, pos.x, pos.y);
65+
attack.currentPattern = BossAttackPattern::FAN_SPRAY;
66+
break;
67+
default:
68+
break;
69+
}
70+
} else if (boss.bossId == 2) {
71+
// Boss 2
72+
CreateAnimatedOrb(registry, bossEntity, pos.x, pos.y);
6573
}
6674
}
6775
}
@@ -209,5 +217,46 @@ namespace RType {
209217
Core::Logger::Info("[BossAttackSystem] Created Third Bullet at ({}, {})", spawnX, spawnY);
210218
}
211219

220+
void BossAttackSystem::CreateAnimatedOrb(Registry& registry, Entity bossEntity, float bossX, float bossY) {
221+
const int orbCount = 4;
222+
const float orbSpacing = 100.0f;
223+
const float baseSpeed = 350.0f;
224+
225+
const float spawnX = bossX + 50.0f;
226+
const float startY = bossY + 50.0f;
227+
228+
for (int i = 0; i < orbCount; i++) {
229+
Entity orb = registry.CreateEntity();
230+
231+
if (registry.HasComponent<Obstacle>(orb)) {
232+
registry.RemoveComponent<Obstacle>(orb);
233+
}
234+
if (registry.HasComponent<ObstacleMetadata>(orb)) {
235+
registry.RemoveComponent<ObstacleMetadata>(orb);
236+
}
237+
238+
float orbY = startY + (i * orbSpacing);
239+
registry.AddComponent<Position>(orb, Position{spawnX, orbY});
240+
241+
float speedVariation = baseSpeed + (i * 10.0f);
242+
float angle = -M_PI + (i * 0.1f);
243+
float vx = std::cos(angle) * speedVariation;
244+
float vy = std::sin(angle) * speedVariation * 0.3f;
245+
246+
registry.AddComponent<Velocity>(orb, Velocity{vx, vy});
247+
248+
registry.AddComponent<Bullet>(orb, Bullet{bossEntity});
249+
registry.AddComponent<BossBullet>(orb, BossBullet{});
250+
registry.AddComponent<WaveAttack>(orb, WaveAttack{});
251+
252+
registry.AddComponent<CircleCollider>(orb, CircleCollider{15.0f});
253+
registry.AddComponent<CollisionLayer>(orb,
254+
CollisionLayer(CollisionLayers::ENEMY_BULLET, CollisionLayers::PLAYER));
255+
registry.AddComponent<Damage>(orb, Damage{8});
256+
}
257+
258+
Core::Logger::Info("[BossAttackSystem] Boss 2 created wave attack burst with {} orbs", orbCount);
259+
}
260+
212261
}
213262
}

libs/engine/src/ECS/LevelLoader.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ namespace RType {
159159
boss.health = bossJson.value("health", 1000);
160160
boss.scrollSpeed = bossJson.value("scrollSpeed", -300.0f);
161161
boss.attackPattern = bossJson.value("attackPattern", 1);
162+
boss.bossId = bossJson.value("bossId", static_cast<uint8_t>(1));
162163

163164
level.boss = boss;
164165
}
@@ -432,7 +433,7 @@ namespace RType {
432433

433434
Entity bossEntity = registry.CreateEntity();
434435

435-
registry.AddComponent<Boss>(bossEntity, Boss{});
436+
registry.AddComponent<Boss>(bossEntity, Boss{boss.bossId});
436437

437438
registry.AddComponent<Position>(bossEntity, Position{boss.x, boss.y});
438439

@@ -445,7 +446,11 @@ namespace RType {
445446
registry.AddComponent<Scrollable>(bossEntity, Scrollable{boss.scrollSpeed});
446447

447448
auto& bossAttack = registry.AddComponent<BossAttack>(bossEntity, BossAttack{3.0f});
448-
bossAttack.currentPattern = static_cast<BossAttackPattern>(boss.attackPattern);
449+
if (boss.bossId == 2) {
450+
bossAttack.currentPattern = BossAttackPattern::ANIMATED_ORB;
451+
} else {
452+
bossAttack.currentPattern = static_cast<BossAttackPattern>(boss.attackPattern);
453+
}
449454

450455
registry.AddComponent<DamageFlash>(bossEntity, DamageFlash{0.1f});
451456

0 commit comments

Comments
 (0)