Created
April 1, 2021 19:29
-
-
Save Jakz/4defc7dd1a59faee1c9422b5bc951c63 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
class EffectList | |
{ | |
class EffectTimer | |
{ | |
public EffectType type; | |
public float timer; | |
}; | |
private List<EffectTimer> effects; | |
public EffectList() | |
{ | |
effects = new List<EffectTimer>(); | |
} | |
public void update(float dt) | |
{ | |
foreach (EffectTimer effect in effects) | |
effect.timer -= dt; | |
effects.RemoveAll(effect => effect.timer < 0.0f); | |
} | |
public void Clear() | |
{ | |
effects.Clear(); | |
} | |
public void addEffect(EffectType type, float seconds) | |
{ | |
foreach(EffectTimer leffect in effects) | |
{ | |
if (leffect.type == type && leffect.timer < seconds) | |
{ | |
leffect.timer = seconds; | |
return; | |
} | |
} | |
EffectTimer effect = new EffectTimer(); | |
effect.type = type; | |
effect.timer = seconds; | |
effects.Add(effect); | |
} | |
public bool hasEffect(EffectType type) | |
{ | |
EffectTimer result = effects.Find(effect => effect.type == type); | |
return result != null; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment