File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -136,12 +136,20 @@ add_executable(GAME_APPLICATION
136136 src/common/components/free-camera-controller.cpp
137137 src/common/components/movement.cpp
138138
139+ src/game/components/collider.cpp
140+ src/game/components/enemy.cpp
141+ src/game/components/health.cpp
142+ src/game/components/player.cpp
143+ src/game/game-registration.cpp
144+
139145 src/common/systems/forward-renderer.cpp
140146)
141147
142148target_include_directories (GAME_APPLICATION
143149 PRIVATE
150+ src
144151 src/common
152+ src/game
145153 src/states
146154)
147155
Original file line number Diff line number Diff line change 1+ #include " collider.hpp"
2+
3+ namespace gameplay {
4+
5+ namespace {
6+
7+ ColliderShape parseColliderShape (const std::string& value, ColliderShape fallback) {
8+ if (value == " Sphere" ) return ColliderShape::Sphere;
9+ if (value == " Capsule" ) return ColliderShape::Capsule;
10+ return fallback;
11+ }
12+
13+ } // namespace
14+
15+ void ColliderComponent::deserialize (const nlohmann::json& data) {
16+ if (!data.is_object ()) return ;
17+ shape = parseColliderShape (data.value (" shape" , std::string (" Sphere" )), shape);
18+ layer = data.value (" layer" , layer);
19+ radius = data.value (" radius" , radius);
20+ height = data.value (" height" , height);
21+ isTrigger = data.value (" isTrigger" , isTrigger);
22+ }
23+
24+ } // namespace gameplay
Original file line number Diff line number Diff line change 1+ #pragma once
2+
3+ #include < ecs/component.hpp>
4+
5+ namespace gameplay {
6+
7+ enum class ColliderShape { Sphere, Capsule };
8+
9+ class ColliderComponent : public our ::Component {
10+ public:
11+ ColliderShape shape = ColliderShape::Sphere;
12+ std::string layer = " default" ;
13+ float radius = 0 .5f ;
14+ float height = 1 .0f ;
15+ bool isTrigger = false ;
16+
17+ static std::string getID () {
18+ return " Collider" ;
19+ }
20+
21+ void deserialize (const nlohmann::json& data) override ;
22+ };
23+
24+ } // namespace gameplay
Original file line number Diff line number Diff line change 1+ #include " enemy.hpp"
2+
3+ namespace gameplay {
4+
5+ namespace {
6+
7+ EnemyType parseEnemyType (const std::string& type, EnemyType fallback) {
8+ if (type == " Brute" ) return EnemyType::Brute;
9+ if (type == " Charger" ) return EnemyType::Charger;
10+ if (type == " Flyer" ) return EnemyType::Flyer;
11+ return fallback;
12+ }
13+
14+ } // namespace
15+
16+ void EnemyComponent::deserialize (const nlohmann::json& data) {
17+ if (!data.is_object ()) return ;
18+ type = parseEnemyType (data.value (" enemyType" , std::string (" Brute" )), type);
19+ moveSpeed = data.value (" moveSpeed" , moveSpeed);
20+ acceleration = data.value (" acceleration" , acceleration);
21+ turnSpeed = data.value (" turnSpeed" , turnSpeed);
22+ aggroRange = data.value (" aggroRange" , aggroRange);
23+ attackRange = data.value (" attackRange" , attackRange);
24+ separationRadius = data.value (" separationRadius" , separationRadius);
25+ preferredDistance = data.value (" preferredDistance" , preferredDistance);
26+ scoreValue = data.value (" scoreValue" , scoreValue);
27+ }
28+
29+ } // namespace gameplay
Original file line number Diff line number Diff line change 1+ #pragma once
2+
3+ #include < ecs/component.hpp>
4+
5+ namespace gameplay {
6+
7+ enum class EnemyType { Brute, Charger, Flyer };
8+
9+ class EnemyComponent : public our ::Component {
10+ public:
11+ EnemyType type = EnemyType::Brute;
12+ float moveSpeed = 2 .0f ;
13+ float acceleration = 8 .0f ;
14+ float turnSpeed = 6 .0f ;
15+ float aggroRange = 15 .0f ;
16+ float attackRange = 1 .5f ;
17+ float separationRadius = 1 .0f ;
18+ float preferredDistance = 4 .0f ;
19+ int scoreValue = 100 ;
20+
21+ static std::string getID () {
22+ return " Enemy" ;
23+ }
24+
25+ void deserialize (const nlohmann::json& data) override ;
26+ };
27+
28+ } // namespace gameplay
Original file line number Diff line number Diff line change 1+ #include " health.hpp"
2+
3+ namespace gameplay {
4+
5+ void HealthComponent::deserialize (const nlohmann::json& data) {
6+ if (!data.is_object ()) return ;
7+ maxHealth = data.value (" maxHealth" , maxHealth);
8+ currentHealth = data.contains (" currentHealth" ) ? data[" currentHealth" ].get <float >() : maxHealth;
9+ invulnerabilityTimer = data.value (" invulnerabilityTimer" , invulnerabilityTimer);
10+ isDead = data.value (" isDead" , isDead);
11+ }
12+
13+ } // namespace gameplay
Original file line number Diff line number Diff line change 1+ #pragma once
2+
3+ #include < ecs/component.hpp>
4+
5+ namespace gameplay {
6+
7+ class HealthComponent : public our ::Component {
8+ public:
9+ float maxHealth = 100 .0f ;
10+ float currentHealth = 100 .0f ;
11+ float invulnerabilityTimer = 0 .0f ;
12+ bool isDead = false ;
13+
14+ static std::string getID () {
15+ return " Health" ;
16+ }
17+
18+ void deserialize (const nlohmann::json& data) override ;
19+ };
20+
21+ } // namespace gameplay
Original file line number Diff line number Diff line change 1+ #include " player.hpp"
2+
3+ namespace gameplay {
4+
5+ void PlayerComponent::deserialize (const nlohmann::json& data) {
6+ if (!data.is_object ()) return ;
7+ radius = data.value (" radius" , radius);
8+ height = data.value (" height" , height);
9+ }
10+
11+ } // namespace gameplay
Original file line number Diff line number Diff line change 1+ #pragma once
2+
3+ #include < ecs/component.hpp>
4+
5+ namespace gameplay {
6+
7+ class PlayerComponent : public our ::Component {
8+ public:
9+ float radius = 0 .5f ;
10+ float height = 1 .8f ;
11+
12+ static std::string getID () {
13+ return " Player" ;
14+ }
15+
16+ void deserialize (const nlohmann::json& data) override ;
17+ };
18+
19+ } // namespace gameplay
Original file line number Diff line number Diff line change 1+ #include " game-registration.hpp"
2+
3+ #include < ecs/component-registry.hpp>
4+
5+ #include " components/collider.hpp"
6+ #include " components/enemy.hpp"
7+ #include " components/health.hpp"
8+ #include " components/player.hpp"
9+
10+ namespace gameplay {
11+
12+ void registerGameComponents () {
13+ static bool initialized = false ;
14+ if (initialized) return ;
15+
16+ our::ComponentRegistry::registerType<ColliderComponent>();
17+ our::ComponentRegistry::registerType<EnemyComponent>();
18+ our::ComponentRegistry::registerType<HealthComponent>();
19+ our::ComponentRegistry::registerType<PlayerComponent>();
20+
21+ initialized = true ;
22+ }
23+
24+ } // namespace gameplay
You can’t perform that action at this time.
0 commit comments