aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorElias Fleckenstein <eliasfleckenstein@web.de>2021-06-09 19:48:18 +0200
committerElias Fleckenstein <eliasfleckenstein@web.de>2021-06-09 19:48:18 +0200
commit3dcf2f7307837abaff862042aede312fff9ac905 (patch)
treeca0b1f31a98d39db9b07ea7e5bf4f3104d191d89
parent043c0a4c0ef016e3b49816d582cdf7227f6d3450 (diff)
downloaddungeon_game-3dcf2f7307837abaff862042aede312fff9ac905.tar.xz
Slightly randomize fireball color
-rw-r--r--plugins/fireball/fireball.c4
-rw-r--r--plugins/game/game.c5
-rw-r--r--plugins/game/game.h1
3 files changed, 10 insertions, 0 deletions
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