Esempio n. 1
0
void
spawn_new_foes(void)
{
#if 0
	if (gc.level_tics % 50 == 0)
		spawn_random_foe();

	if (gc.level_tics % 150 == 0) {
		switch (irand(2)) {
			case 0:
				add_border_generator();
				break;
			
			case 1:
				add_circle_generator();
				break;

			default:
				break;
		}
	}
#else
	const struct level *l = levels[gc.cur_level];
	const struct list_node *ln;

	assert(inner_state.state == IS_IN_GAME);

	for (ln = l->waves[gc.cur_wave]->events->first; ln; ln = ln->next) {
		const struct event *ev = (const struct event *)ln->data;

		if (ev->time == inner_state.tics) {
			switch (ev->type) {
				case EV_CIRCLE:
					add_generator(FS_CIRCLE, ev);
					break;

				case EV_CLUSTER:
					add_generator(FS_CLUSTER, ev);
					break;

				case EV_WALL:
					add_generator(FS_BORDER, ev);
					break;

				default:
					assert(0);
			}
		}
	}
#endif
}
Esempio n. 2
0
void union_find::add_generators(vector_ge *gens, INT verbose_level)
{
	INT f_v = (verbose_level >= 1);
	INT f_vv = (verbose_level >= 2);
	INT i;

	if (f_v) {
		cout << "union_find::add_generators" << endl;
		}
	if (f_vv) {
		cout << "union_find::add_generators before:" << endl;
		print();
		}
	for (i = 0; i < gens->len; i++) {
		if (f_vv) {
			cout << "union_find::add_generators adding generator " << i << endl;
			}
		add_generator(gens->ith(i), verbose_level - 2);
		}
	if (f_vv) {
		cout << "union_find::add_generators after:" << endl;
		print();
		}
	if (f_v) {
		cout << "union_find::add_generators done" << endl;
		}
}
Esempio n. 3
0
static DskJsonValue *
create_user_update (User *user)
{
  Game *game = user->base.game;

  /* width/height in various units, rounded up */
  unsigned tile_width = (user->width + TILE_SIZE - 1) / TILE_SIZE;
  unsigned tile_height = (user->height + TILE_SIZE - 1) / TILE_SIZE;
  unsigned cell_width = (tile_width + CELL_SIZE * 2 - 2) / CELL_SIZE;
  unsigned cell_height = (tile_height + CELL_SIZE * 2 - 2) / CELL_SIZE;

  /* left/upper corner, rounded down */
  int min_tile_x = user->base.x - (tile_width+1) / 2;
  int min_tile_y = user->base.y - (tile_height+1) / 2;
  int min_cell_x = int_div (min_tile_x, CELL_SIZE);
  int min_cell_y = int_div (min_tile_y, CELL_SIZE);

  unsigned alloced = 16;
  DskJsonValue **elements = dsk_malloc (sizeof (DskJsonValue *) * alloced);
  unsigned n_elements = 0;

  unsigned x, y;

  for (x = 0; x < cell_width; x++)
    for (y = 0; y < cell_height; y++)
      {
        int ucx = x + min_cell_x;               /* un-wrapped x, y */
        int ucy = y + min_cell_y;
        int px = (ucx * CELL_SIZE - user->base.x) * TILE_SIZE + user->width / 2 - TILE_SIZE / 2;
        int py = (ucy * CELL_SIZE - user->base.y) * TILE_SIZE + user->height / 2 - TILE_SIZE / 2;
        unsigned cx, cy;
        Cell *cell;

        /* deal with wrapping (or not) */
        if (ucx < 0)
          {
            if (!game->wrap)
              continue;
            cx = ucx + game->universe_width;
          }
        else if ((unsigned) ucx >= game->universe_width)
          {
            cx = ucx;
            if (game->wrap)
              cx -= game->universe_width;
          }
        else
          cx = ucx;
        if (ucy < 0)
          {
            if (!game->wrap)
              continue;
            cy = ucy + game->universe_height;
          }
        else if ((unsigned) ucy >= game->universe_height)
          {
            cy = ucy;
            if (game->wrap)
              cy -= game->universe_height;
          }
        else
          cy = ucy;

        /* render walls */
        if (cy < game->universe_height && cx <= game->universe_width
            && game->v_walls[cx + cy * game->universe_width])
          {
            /* render vertical wall */
            add_wall (&n_elements, &elements, &alloced,
                      px, py, TILE_SIZE, TILE_SIZE * (CELL_SIZE+1));
          }
        if (cy <= game->universe_height && cx < game->universe_width
            && game->h_walls[cx + cy * game->universe_width])
          {
            /* render horizontal wall */
            add_wall (&n_elements, &elements, &alloced,
                      px, py, TILE_SIZE * (CELL_SIZE+1), TILE_SIZE);
          }
        if (cx >= game->universe_width || cy >= game->universe_height)
          continue;

        cell = game->cells + (game->universe_width * cy + cx);

        /* render bullets */
        Object *object;
        for (object = cell->objects[OBJECT_TYPE_BULLET]; object; object = object->next_in_cell)
          {
            int bx = px + (object->x - cx * CELL_SIZE) * TILE_SIZE + TILE_SIZE / 2;
            int by = py + (object->y - cy * CELL_SIZE) * TILE_SIZE + TILE_SIZE / 2;
            add_bullet (&n_elements, &elements, &alloced,
                        bx, by);
          }

        /* render dudes */
        for (object = cell->objects[OBJECT_TYPE_USER]; object; object = object->next_in_cell)
          {
            int bx = px + (object->x - cx * CELL_SIZE) * TILE_SIZE + TILE_SIZE / 2;
            int by = py + (object->y - cy * CELL_SIZE) * TILE_SIZE + TILE_SIZE / 2;
            add_user (&n_elements, &elements, &alloced,
                      bx, by, user == (User*) object);
          }

        /* render bad guys */
        for (object = cell->objects[OBJECT_TYPE_ENEMY]; object; object = object->next_in_cell)
          {
            int bx = px + (object->x - cx * CELL_SIZE) * TILE_SIZE + TILE_SIZE / 2;
            int by = py + (object->y - cy * CELL_SIZE) * TILE_SIZE + TILE_SIZE / 2;
            add_enemy (&n_elements, &elements, &alloced, bx, by);
          }

        /* render generators */
        if (cell->generator)
          {
            int bx = px + (cell->generator->x - cx * CELL_SIZE) * TILE_SIZE + TILE_SIZE;
            int by = py + (cell->generator->y - cy * CELL_SIZE) * TILE_SIZE + TILE_SIZE;
            add_generator (&n_elements, &elements, &alloced, bx, by, user->base.game->latest_update);
          }
      }
  DskJsonValue *rv;
  rv = dsk_json_value_new_array (n_elements, elements);
  dsk_free (elements);

  user->last_update = game->latest_update;
  return rv;
}