Created
May 3, 2019 10:16
-
-
Save morukutsu/f5bbce18016599b81c4a34ad1d5708a8 to your computer and use it in GitHub Desktop.
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
// Ability system | |
// Generic class for abilities | |
class Ability { | |
public: | |
virtual void Update(float dt) = 0; | |
virtual void Launch() = 0; | |
float cooldown = 0.0f; | |
} | |
// Ability specialization | |
class FireAbility { | |
public: | |
void Update(float dt) { | |
if (cooldown > 0.0f) | |
cooldown -= dt; | |
} | |
void Launch() { | |
if (cooldown <= 0.0f) { | |
// do some crazy stuff here | |
// ... | |
// block spell usage for 2s | |
cooldown = 2.0f; | |
} | |
} | |
// manage your ability data however you want here | |
// ... | |
} | |
// Abilities update | |
class AbilityManager { | |
public: | |
void Update(float dt) { | |
// Update all abilities behaviour | |
for (auto it = abilities.begin(); it != abilities.end(); it++) | |
it.Update(dt); | |
} | |
void Register(Ability* ability) { | |
abilities.push_back(ability); | |
} | |
vector<Ability*> abilities; | |
} | |
// For every game object using an ability | |
// Ability* spell = new FireAbility(); | |
// spell.Launch(); | |
// abilityManager.Register(spell); | |
// Every frame | |
// AbilityManager.Update(dt) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment