From: Elias Fleckenstein Date: Wed, 9 Jun 2021 17:48:18 +0000 (+0200) Subject: Slightly randomize fireball color X-Git-Url: https://git.lizzy.rs/?a=commitdiff_plain;h=3dcf2f7307837abaff862042aede312fff9ac905;p=dungeon_game.git Slightly randomize fireball color --- diff --git a/plugins/fireball/fireball.c b/plugins/fireball/fireball.c index 1c3eeb6..3da29a4 100644 --- a/plugins/fireball/fireball.c +++ b/plugins/fireball/fireball.c @@ -15,6 +15,10 @@ static void fireball_spawn(struct entity *self, void *data) { self->meta = malloc(sizeof(struct fireball_data)); *((struct fireball_data *) self->meta) = *((struct fireball_data *) data); + + self->color.r = clamp(self->color.r + rand() % 65 - 32, 0, 255); + self->color.g = clamp(self->color.g + rand() % 65 - 32, 0, 255); + self->color.b = clamp(self->color.b + rand() % 65 - 32, 0, 255); } static void fireball_step(struct entity *self, struct entity_step_data stepdata) diff --git a/plugins/game/game.c b/plugins/game/game.c index 3b2ad4b..6f91ca2 100644 --- a/plugins/game/game.c +++ b/plugins/game/game.c @@ -190,6 +190,11 @@ void dir_to_xy(int dir, int *x, int *y) } } +int clamp(int v, int min, int max) +{ + return v < min ? min : v > max ? max : v; +} + /* Player */ static void player_death(struct entity *self) diff --git a/plugins/game/game.h b/plugins/game/game.h index 28a7c2c..6131402 100644 --- a/plugins/game/game.h +++ b/plugins/game/game.h @@ -108,6 +108,7 @@ void mix_color(struct color *color, struct color other, double ratio); void register_air_function(struct generator_function func); void register_input_handler(unsigned char c, struct input_handler handler); void dir_to_xy(int dir, int *x, int *y); +int clamp(int v, int max, int min); struct list *add_element(struct list *list, void *element); #endif