/* erzeuge zufaelliges Labyrinth mit bestimmter Breite und Hoehe */ struct labyrinth *labyrinth_generate(int width, int height) { struct labyrinth *l; struct rectangle *r; int x, y; l = labyrinth_new(); r = rectangle_new(height, width, l->cube_cnt); random_fill_rectangle(r, 0, 0, 0); for (y = 0; y < r->height; y++) for (x = 0; x < r->width; x++) add_cube_by_type(l, get_type(&(r->cube[y][x]))); l->solution = r; return l; }
void jumpnrun_player_respawn(jumpnrun_player *self, vec2d spawn_pos) { memset(&self->base, 0, sizeof(self->base)); self->base.hitbox = rectangle_new(spawn_pos, jumpnrun_player_extents()); }
/* suche gueltiges Labyrinth */ void labyrinth_solve(struct labyrinth *l) { struct cube c; char rot, rot_count; int x_from, y_from, x_to, y_to, old_faults, i; struct rectangle *r; printf("suche %4d x %-4d Labyrinth\n", l->width, l->height); r = rectangle_new(l->height, l->width, l->cube_cnt); rectangle_fill(l, r); rot_count = -1; for (i = 0; i < l->try_count; i++) { x_from = x_to = rand() % r->width; y_from = y_to = rand() % r->height; rot = 0; if (l->rotation && rand() % 2) { rot = 1; rot_count = 1 + rand() % 3; } while (!rot && x_from == x_to && y_from == y_to && r->cube[y_from][x_from].type == r->cube[y_to][x_to].type) { x_to = rand() % r->width; y_to = rand() % r->height; } old_faults = r->faults; if (rot) { cube_rotate(&(r->cube[y_from][x_from]), rot_count); } else { c = r->cube[y_from][x_from]; r->cube[y_from][x_from] = r->cube[y_to][x_to]; r->cube[y_to][x_to] = c; } rectangle_evaluate(r, l->alley); if (r->faults == 0) { l->solution = r; return; } if (r->faults <= old_faults) continue; r->faults = old_faults; if (rot) { /* wieder zurueck drehen */ cube_rotate(&(r->cube[y_from][x_from]), 4 - rot_count); } else { /* wieder zurueck tauschen */ c = r->cube[y_from][x_from]; r->cube[y_from][x_from] = r->cube[y_to][x_to]; r->cube[y_to][x_to] = c; } } if (l->verbose) printf("Labyrinth %4d x %-4d hat noch %d Fehler\n", l->width, l->height, r->faults); rectangle_remove(r); }
void jumpnrun_enemy_despawn(jumpnrun_enemy *self) { // Despawned enemies are reset to their spawn position, so enemy_in_spawn_area will determine whether the spawn point is in the spawn area. self->base.flags &= ~(JUMPNRUN_ENEMY_SPAWNED | JUMPNRUN_ENEMY_MOVING | JUMPNRUN_MOVEABLE_DYING); self->base.hitbox = rectangle_new(self->spawn_pos, self->type->hitbox.extent); self->base.inertia = self->type->spawn_inertia; }