Laser *create_laser(complex pos, float time, float deathtime, Color *color, LaserPosRule prule, LaserLogicRule lrule, complex a0, complex a1, complex a2, complex a3) { Laser *l = create_element((void **)&global.lasers, sizeof(Laser)); l->birthtime = global.frames; l->timespan = time; l->deathtime = deathtime; l->pos = pos; l->color = color; l->args[0] = a0; l->args[1] = a1; l->args[2] = a2; l->args[3] = a3; l->prule = prule; l->lrule = lrule; l->shader = NULL; l->collision_step = 5; l->width = 10; l->speed = 1; l->timeshift = 0; if(l->lrule) l->lrule(l, EVENT_BIRTH); l->prule(l, EVENT_BIRTH); return l; }
void _delete_laser(void **lasers, void *laser) { Laser *l = laser; if(l->lrule) l->lrule(l, EVENT_DEATH); if(l->color) free(l->color); del_ref(laser); delete_element(lasers, laser); }
void process_lasers(void) { Laser *laser = global.lasers, *del = NULL; while(laser != NULL) { if(collision_laser_curve(laser)) player_death(&global.plr); if(laser->lrule) laser->lrule(laser, global.frames - laser->birthtime); if(global.frames - laser->birthtime > laser->deathtime + laser->timespan*laser->speed) { del = laser; laser = laser->next; _delete_laser((void **)&global.lasers, del); if(laser == NULL) break; } else { laser = laser->next; } } }