Skip to content

Instantly share code, notes, and snippets.

@Jakz
Created April 1, 2021 19:29
Show Gist options
  • Save Jakz/4defc7dd1a59faee1c9422b5bc951c63 to your computer and use it in GitHub Desktop.
Save Jakz/4defc7dd1a59faee1c9422b5bc951c63 to your computer and use it in GitHub Desktop.
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