]> git.lizzy.rs Git - dungeon_game.git/commitdiff
Slightly randomize fireball color
authorElias Fleckenstein <eliasfleckenstein@web.de>
Wed, 9 Jun 2021 17:48:18 +0000 (19:48 +0200)
committerElias Fleckenstein <eliasfleckenstein@web.de>
Wed, 9 Jun 2021 17:48:18 +0000 (19:48 +0200)
plugins/fireball/fireball.c
plugins/game/game.c
plugins/game/game.h

index 1c3eeb6e31d6ab4a0b239de61b4d6ee883a02fe9..3da29a47d9e025a8efed27dbdbc27a74be46e147 100644 (file)
@@ -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)
index 3b2ad4b8f3333bb7f3e11933fd745a738da32234..6f91ca2dc3cbe3d559c13bffc4d26ae8c1bafda3 100644 (file)
@@ -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)
index 28a7c2cfff13ef46db5860906f6d8b7e860ec292..6131402d65ec0d31147a546747d0136dedf81a15 100644 (file)
@@ -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