3 #include "../game/game.h"
4 #include "../movement/movement.h"
13 static void fireball_spawn(struct entity *self, void *data)
15 self->meta = malloc(sizeof(struct fireball_data));
16 *((struct fireball_data *) self->meta) = *((struct fireball_data *) data);
18 self->color.r = clamp(self->color.r + rand() % 65 - 32, 0, 255);
19 self->color.g = clamp(self->color.g + rand() % 65 - 32, 0, 255);
20 self->color.b = clamp(self->color.b + rand() % 65 - 32, 0, 255);
23 static void fireball_step(struct entity *self, struct entity_step_data stepdata)
25 struct fireball_data *data = self->meta;
27 if (stepdata.visible && (data->timer -= stepdata.dtime) <= 0.0) {
29 move(self, data->vx, data->vy);
33 static void fireball_collide(struct entity *self, int x, int y)
40 static void fireball_collide_with_entity(struct entity *self, struct entity *other)
42 add_health(other, -(1 + rand() % 3));
46 static struct entity fireball_entity = {
57 .collide_with_entities = true,
59 .on_step = &fireball_step,
60 .on_collide = &fireball_collide,
61 .on_collide_with_entity = &fireball_collide_with_entity,
62 .on_spawn = &fireball_spawn,
68 static void shoot_fireball()
73 dir_to_xy(last_player_move, &vx, &vy);
75 spawn(fireball_entity, player.x + vx, player.y + vy, & (struct fireball_data) {
82 __attribute__((constructor)) static void init()
84 fireball_entity.color = get_color("#FF6611");
86 register_input_handler(' ', (struct input_handler) {
88 .callback = &shoot_fireball,