int set_player_hp(object ob, int hp) { if(!ob) return 0; ob->set_hp(hp); ob->show_status_line(); if(hp < 1) { ob->set_hp(ob->query_max_hp()); player_death(ob); return 0; } return 1; }
int harm_player(object ob, int hp) { if(!ob) return 0; ob->add_hp(-hp); ob->show_status_line(); if(ob->query_hp()<1) { ob->set_hp(ob->query_max_hp()); player_death(ob); return 0; } return 1; }
void process_projectiles(Projectile **projs, char collision) { Projectile *proj = *projs, *del = NULL; char killed = 0; char col = 0; int action; while(proj != NULL) { action = proj->rule(proj, global.frames - proj->birthtime); if(proj->type == DeadProj && killed < 5) { killed++; action = ACTION_DESTROY; create_particle1c("flare", proj->pos, NULL, Fade, timeout, 30); create_item(proj->pos, 0, BPoint)->auto_collect = 10; } if(collision) col = collision_projectile(proj); if(col && proj->type != Particle) { Color *clr = NULL; if(proj->clr) { clr = malloc(sizeof(Color)); memcpy(clr, proj->clr, sizeof(Color)); } create_projectile_p(&global.particles, proj->tex, proj->pos, clr, DeathShrink, timeout_linear, 10, 5*cexp(proj->angle*I), 0, 0); } if(col == 1 && global.frames - abs(global.plr.recovery) >= 0) player_death(&global.plr); int e = 0; if(proj->type == Particle) { e = 300; } if(action == ACTION_DESTROY || col || creal(proj->pos) + proj->tex->w/2 + e < 0 || creal(proj->pos) - proj->tex->w/2 - e > VIEWPORT_W || cimag(proj->pos) + proj->tex->h/2 + e < 0 || cimag(proj->pos) - proj->tex->h/2 - e > VIEWPORT_H) { del = proj; proj = proj->next; delete_projectile(projs, del); if(proj == NULL) break; } else { proj = proj->next; } } }
static void feed_players(t_server *s) { t_client *tmp_c; tmp_c = s->player_list; while (tmp_c) { if (tmp_c->player_data && tmp_c->fd > -1) { if (tmp_c->player_data->bag[FOOD] == 0) player_death(s, tmp_c->player_data); else tmp_c->player_data->bag[FOOD] -= 1; } tmp_c = tmp_c->next; } }
static void life_update_by_player(void *pl) { t_player *player; t_world *world; player = (t_player *)pl; world = &g_server.world; player->alive -= g_server.info.dtime; if (player->alive <= 0) { ++world->cell[rand() % world->size].res[FOOD]; if (player->inventory[FOOD] <= 0) player_death(player); else { --(player->inventory[FOOD]); player->alive += 126; } } }
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; } } }