Skip to content

Commit

Permalink
Stressful healing, early prototype
Browse files Browse the repository at this point in the history
  • Loading branch information
justindriggers committed Mar 12, 2023
1 parent f243b20 commit bde6fdd
Show file tree
Hide file tree
Showing 24 changed files with 402 additions and 78 deletions.
4 changes: 2 additions & 2 deletions alfredo/src/appkit/AlfredoApplicationDelegate.mm
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ - (void)applicationWillFinishLaunching:(NSNotification *)notification {

- (void)applicationDidFinishLaunching:(NSNotification *)notification {
@autoreleasepool {
NSRect frame = CGRectMake(0.0, 0.0, 375.0, 667.0);
NSRect frame = CGRectMake(256.0, 256.0, 375.0, 667.0);

self.window = [[NSWindow alloc]
initWithContentRect:frame
Expand All @@ -71,7 +71,7 @@ - (void)applicationDidFinishLaunching:(NSNotification *)notification {

[self.window setContentView:view];
[self.window setTitle:@"Alfredo"];
[self.window center];
// [self.window center];
[self.window makeKeyAndOrderFront:nil];

[NSApp activateIgnoringOtherApps:YES];
Expand Down
7 changes: 6 additions & 1 deletion linguine/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,15 @@ add_library(linguine
src/renderer/Renderer.cpp
src/renderer/features/FeatureRenderer.cpp
src/systems/CameraSystem.cpp
src/systems/EnemyAttackSystem.cpp
src/systems/EnemySpawnSystem.cpp
src/systems/FallerSystem.cpp
src/systems/FpsSystem.cpp
src/systems/FriendlyAttackSystem.cpp
src/systems/GestureRecognitionSystem.cpp
src/systems/ProgressTestSystem.cpp
src/systems/HealthProgressSystem.cpp
src/systems/LivenessSystem.cpp
src/systems/PlayerControllerSystem.cpp
src/systems/RiserSystem.cpp
src/systems/RotatorSystem.cpp
src/systems/SelectionDestructionSystem.cpp
Expand Down
7 changes: 7 additions & 0 deletions linguine/src/components/Alive.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#pragma once

namespace linguine {

struct Alive {};

} // namespace linguine
7 changes: 7 additions & 0 deletions linguine/src/components/Dead.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#pragma once

namespace linguine {

struct Dead {};

} // namespace linguine
11 changes: 11 additions & 0 deletions linguine/src/components/Friendly.h
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
10 changes: 10 additions & 0 deletions linguine/src/components/Health.h
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
11 changes: 11 additions & 0 deletions linguine/src/components/Hostile.h
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
36 changes: 33 additions & 3 deletions linguine/src/scenes/ProgressPrototypeScene.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,23 @@

#include "Scene.h"

#include "components/Alive.h"
#include "components/CameraFixture.h"
#include "components/Friendly.h"
#include "components/Health.h"
#include "components/Hostile.h"
#include "components/Progressable.h"
#include "components/Selectable.h"
#include "components/Transform.h"
#include "systems/CameraSystem.h"
#include "systems/EnemyAttackSystem.h"
#include "systems/EnemySpawnSystem.h"
#include "systems/FpsSystem.h"
#include "systems/FriendlyAttackSystem.h"
#include "systems/GestureRecognitionSystem.h"
#include "systems/ProgressTestSystem.h"
#include "systems/HealthProgressSystem.h"
#include "systems/LivenessSystem.h"
#include "systems/PlayerControllerSystem.h"
#include "systems/TransformationSystem.h"

namespace linguine {
Expand All @@ -20,7 +29,12 @@ class ProgressPrototypeScene : public Scene {
: Scene(serviceLocator.get<EntityManagerFactory>().create()) {
registerSystem(std::make_unique<FpsSystem>(getEntityManager(), serviceLocator.get<Logger>()));
registerSystem(std::make_unique<GestureRecognitionSystem>(getEntityManager(), serviceLocator.get<InputManager>(), serviceLocator.get<Renderer>(), serviceLocator.get<TimeManager>()));
registerSystem(std::make_unique<ProgressTestSystem>(getEntityManager()));
registerSystem(std::make_unique<PlayerControllerSystem>(getEntityManager()));
registerSystem(std::make_unique<EnemySpawnSystem>(getEntityManager(), serviceLocator.get<Renderer>()));
registerSystem(std::make_unique<EnemyAttackSystem>(getEntityManager()));
registerSystem(std::make_unique<FriendlyAttackSystem>(getEntityManager()));
registerSystem(std::make_unique<LivenessSystem>(getEntityManager()));
registerSystem(std::make_unique<HealthProgressSystem>(getEntityManager()));
registerSystem(std::make_unique<TransformationSystem>(getEntityManager()));
registerSystem(std::make_unique<CameraSystem>(getEntityManager(), serviceLocator.get<Renderer>()));

Expand All @@ -30,8 +44,18 @@ class ProgressPrototypeScene : public Scene {
cameraEntity->add<CameraFixture>();
cameraEntity->add<Transform>();

createFriendly(renderer, glm::vec3(0.0f));
createFriendly(renderer, glm::vec3(-2.0f, 0.0f, 0.0f));
createFriendly(renderer, glm::vec3(2.0f, 0.0f, 0.0f));
}

private:
void createFriendly(Renderer& renderer, glm::vec3 location) {
auto entity = createEntity();
entity->add<Transform>();
entity->add<Friendly>();

auto transform = entity->add<Transform>();
transform->position = location;

auto progressable = entity->add<Progressable>();
progressable->feature = new ProgressFeature();
Expand All @@ -49,6 +73,12 @@ class ProgressPrototypeScene : public Scene {
selectable.setRemovalListener([selectable](const Entity e) {
selectable->renderable->destroy();
});

auto health = entity->add<Health>();
health->current = 1'000;
health->max = 1'000;

entity->add<Alive>();
}
};

Expand Down
2 changes: 1 addition & 1 deletion linguine/src/systems/CameraSystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class CameraSystem : public System {
void fixedUpdate(float fixedDeltaTime) override {}

private:
constexpr static float _height = 10.0f;
constexpr static float _height = 15.0f;

Renderer& _renderer;
};
Expand Down
41 changes: 41 additions & 0 deletions linguine/src/systems/EnemyAttackSystem.cpp
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
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

namespace linguine {

class ProgressTestSystem : public System {
class EnemyAttackSystem : public System {
public:
explicit ProgressTestSystem(EntityManager& entityManager)
explicit EnemyAttackSystem(EntityManager& entityManager)
: System(entityManager) {}

void update(float deltaTime) override;
Expand Down
50 changes: 50 additions & 0 deletions linguine/src/systems/EnemySpawnSystem.cpp
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
29 changes: 29 additions & 0 deletions linguine/src/systems/EnemySpawnSystem.h
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
41 changes: 41 additions & 0 deletions linguine/src/systems/FriendlyAttackSystem.cpp
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
17 changes: 17 additions & 0 deletions linguine/src/systems/FriendlyAttackSystem.h
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

0 comments on commit bde6fdd

Please sign in to comment.