-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f243b20
commit bde6fdd
Showing
24 changed files
with
402 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#pragma once | ||
|
||
namespace linguine { | ||
|
||
struct Alive {}; | ||
|
||
} // namespace linguine |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#pragma once | ||
|
||
namespace linguine { | ||
|
||
struct Dead {}; | ||
|
||
} // namespace linguine |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#pragma once | ||
|
||
namespace linguine { | ||
|
||
struct Friendly { | ||
float attackSpeed = 1.0f; | ||
int32_t attackPower = 100; | ||
float attackTimer = 0.0f; | ||
}; | ||
|
||
} // namespace linguine |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#pragma once | ||
|
||
namespace linguine { | ||
|
||
struct Health { | ||
int32_t current{}; | ||
int32_t max{}; | ||
}; | ||
|
||
} // namespace linguine |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#pragma once | ||
|
||
namespace linguine { | ||
|
||
struct Hostile { | ||
float attackSpeed = 1.0f; | ||
int32_t attackPower = 100; | ||
float attackTimer = 0.0f; | ||
}; | ||
|
||
} // namespace linguine |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#include "EnemyAttackSystem.h" | ||
|
||
#include <random> | ||
|
||
#include <glm/common.hpp> | ||
|
||
#include "components/Alive.h" | ||
#include "components/Friendly.h" | ||
#include "components/Health.h" | ||
#include "components/Hostile.h" | ||
|
||
namespace linguine { | ||
|
||
void EnemyAttackSystem::update(float deltaTime) { | ||
auto friendlies = findEntities<Friendly, Health, Alive>()->get(); | ||
|
||
if (friendlies.empty()) { | ||
return; | ||
} | ||
|
||
auto random = std::random_device(); | ||
auto randomEntity = std::uniform_int_distribution<>(0, static_cast<int>(friendlies.size() - 1)); | ||
|
||
findEntities<Hostile, Alive>()->each([deltaTime, &friendlies, &random, &randomEntity](const Entity& entity) { | ||
auto hostile = entity.get<Hostile>(); | ||
|
||
if (hostile->attackTimer >= hostile->attackSpeed) { | ||
hostile->attackTimer -= hostile->attackSpeed; | ||
|
||
auto index = randomEntity(random); | ||
auto target = friendlies[index]; | ||
auto health = target->get<Health>(); | ||
|
||
health->current = glm::clamp<int32_t>(health->current - hostile->attackPower, 0, health->max); | ||
} | ||
|
||
hostile->attackTimer += deltaTime; | ||
}); | ||
} | ||
|
||
} // namespace linguine |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
#include "EnemySpawnSystem.h" | ||
|
||
#include "components/Alive.h" | ||
#include "components/Health.h" | ||
#include "components/Hostile.h" | ||
#include "components/Progressable.h" | ||
#include "components/Transform.h" | ||
|
||
namespace linguine { | ||
|
||
void EnemySpawnSystem::update(float deltaTime) { | ||
auto alive = findEntities<Hostile, Alive>()->get(); | ||
|
||
if (alive.empty()) { | ||
findEntities<Hostile>()->each([](Entity& entity) { | ||
entity.destroy(); | ||
}); | ||
|
||
int enemyCount = ++_wave; | ||
|
||
for (int i = 0; i < enemyCount; ++i) { | ||
createEnemy({-static_cast<float>(enemyCount - 1) / 2.0f * 1.5f + static_cast<float>(i) * 1.5f, 3.0f, 0.0f}); | ||
} | ||
} | ||
} | ||
|
||
void EnemySpawnSystem::createEnemy(glm::vec3 location) { | ||
auto enemy = createEntity(); | ||
enemy->add<Hostile>(); | ||
|
||
auto transform = enemy->add<Transform>(); | ||
transform->position = location; | ||
|
||
auto progressable = enemy->add<Progressable>(); | ||
progressable->feature = new ProgressFeature(); | ||
progressable->feature->meshType = Triangle; | ||
progressable->feature->color = glm::vec3(1.0f, 0.0f, 0.0f); | ||
progressable->renderable = _renderer.create(std::unique_ptr<ProgressFeature>(progressable->feature)); | ||
progressable.setRemovalListener([progressable](const Entity e) { | ||
progressable->renderable->destroy(); | ||
}); | ||
|
||
auto health = enemy->add<Health>(); | ||
health->current = 10'000; | ||
health->max = 10'000; | ||
|
||
enemy->add<Alive>(); | ||
} | ||
|
||
} // namespace linguine |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#pragma once | ||
|
||
#include "System.h" | ||
|
||
#include <glm/vec3.hpp> | ||
|
||
#include "renderer/Renderer.h" | ||
|
||
namespace linguine { | ||
|
||
class EnemySpawnSystem : public System { | ||
public: | ||
explicit EnemySpawnSystem(EntityManager& entityManager, | ||
Renderer& renderer) | ||
: System(entityManager), _renderer(renderer) {} | ||
|
||
void update(float deltaTime) override; | ||
|
||
void fixedUpdate(float fixedDeltaTime) override {} | ||
|
||
private: | ||
int _wave = 0; | ||
|
||
Renderer& _renderer; | ||
|
||
void createEnemy(glm::vec3 location); | ||
}; | ||
|
||
} // namespace linguine |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#include "FriendlyAttackSystem.h" | ||
|
||
#include <random> | ||
|
||
#include <glm/common.hpp> | ||
|
||
#include "components/Alive.h" | ||
#include "components/Friendly.h" | ||
#include "components/Health.h" | ||
#include "components/Hostile.h" | ||
|
||
namespace linguine { | ||
|
||
void FriendlyAttackSystem::update(float deltaTime) { | ||
auto enemies = findEntities<Hostile, Health, Alive>()->get(); | ||
|
||
if (enemies.empty()) { | ||
return; | ||
} | ||
|
||
auto random = std::random_device(); | ||
auto randomEntity = std::uniform_int_distribution<>(0, static_cast<int>(enemies.size() - 1)); | ||
|
||
findEntities<Friendly, Alive>()->each([deltaTime, &enemies, &random, &randomEntity](const Entity& entity) { | ||
auto friendly = entity.get<Friendly>(); | ||
|
||
if (friendly->attackTimer >= friendly->attackSpeed) { | ||
friendly->attackTimer -= friendly->attackSpeed; | ||
|
||
auto index = randomEntity(random); | ||
auto target = enemies[index]; | ||
auto health = target->get<Health>(); | ||
|
||
health->current = glm::clamp<int32_t>(health->current - friendly->attackPower, 0, health->max); | ||
} | ||
|
||
friendly->attackTimer += deltaTime; | ||
}); | ||
} | ||
|
||
} // namespace linguine |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#pragma once | ||
|
||
#include "System.h" | ||
|
||
namespace linguine { | ||
|
||
class FriendlyAttackSystem : public System { | ||
public: | ||
explicit FriendlyAttackSystem(EntityManager& entityManager) | ||
: System(entityManager) {} | ||
|
||
void update(float deltaTime) override; | ||
|
||
void fixedUpdate(float fixedDeltaTime) override {} | ||
}; | ||
|
||
} // namespace linguine |
Oops, something went wrong.