Add on_level_up callback
parent
8b50cd53c8
commit
125e7eca1a
|
@ -11,6 +11,7 @@ static char *level_symbol = NULL;
|
||||||
static size_t level_symbol_len = 0;
|
static size_t level_symbol_len = 0;
|
||||||
static double score_timer = 0.0;
|
static double score_timer = 0.0;
|
||||||
static double level_timer = 0.0;
|
static double level_timer = 0.0;
|
||||||
|
static struct list *on_level_up = NULL;
|
||||||
|
|
||||||
static void level_up()
|
static void level_up()
|
||||||
{
|
{
|
||||||
|
@ -23,6 +24,9 @@ static void level_up()
|
||||||
get_roman_numeral(level, &level_symbol, &level_symbol_len);
|
get_roman_numeral(level, &level_symbol, &level_symbol_len);
|
||||||
|
|
||||||
level_timer = 2.0;
|
level_timer = 2.0;
|
||||||
|
|
||||||
|
for (struct list *ptr = on_level_up; ptr != NULL; ptr = ptr->next)
|
||||||
|
((void (*)(int)) ptr->element)(level);
|
||||||
}
|
}
|
||||||
|
|
||||||
void add_score(int s)
|
void add_score(int s)
|
||||||
|
@ -47,6 +51,11 @@ int get_level()
|
||||||
return level;
|
return level;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void register_on_level_up(void (*callback)(int new_level))
|
||||||
|
{
|
||||||
|
on_level_up = add_element(on_level_up, callback);
|
||||||
|
}
|
||||||
|
|
||||||
static void render_score(struct winsize ws)
|
static void render_score(struct winsize ws)
|
||||||
{
|
{
|
||||||
int bar_flash = clamp(score_timer * 255, 0, 255);
|
int bar_flash = clamp(score_timer * 255, 0, 255);
|
||||||
|
|
|
@ -4,5 +4,6 @@
|
||||||
void add_score(int s);
|
void add_score(int s);
|
||||||
int get_score();
|
int get_score();
|
||||||
int get_level();
|
int get_level();
|
||||||
|
void register_on_level_up(void (*callback)(int new_level));
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue