3 #include "../game/game.h"
4 #include "../movement/movement.h"
6 static struct entity fireball;
15 static void fireball_spawn(struct entity *self, void *data)
17 self->meta = malloc(sizeof(struct fireball_data));
18 *((struct fireball_data *) self->meta) = *((struct fireball_data *) data);
20 self->color.r = clamp(self->color.r + rand() % 65 - 32, 0, 255);
21 self->color.g = clamp(self->color.g + rand() % 65 - 32, 0, 255);
22 self->color.b = clamp(self->color.b + rand() % 65 - 32, 0, 255);
25 static void fireball_step(struct entity *self, struct entity_step_data stepdata)
27 struct fireball_data *data = self->meta;
29 if (stepdata.visible && (data->timer -= stepdata.dtime) <= 0.0) {
31 move(self, data->vx, data->vy);
35 static void fireball_collide(struct entity *self, int x, int y)
42 static void fireball_collide_with_entity(struct entity *self, struct entity *other)
44 add_health(other, -(1 + rand() % 3));
48 static void shoot_fireball()
53 dir_to_xy(last_player_move, &vx, &vy);
55 spawn(fireball, player.x + vx, player.y + vy, & (struct fireball_data) {
62 __attribute__((constructor)) static void init()
64 fireball = (struct entity) {
68 .color = get_color("#FF6611"),
74 .collide_with_entities = true,
76 .on_step = &fireball_step,
77 .on_collide = &fireball_collide,
78 .on_collide_with_entity = &fireball_collide_with_entity,
79 .on_spawn = &fireball_spawn,
85 register_input_handler(' ', (struct input_handler) {
87 .callback = &shoot_fireball,