Beispiel #1
0
void jump_flood(ivec2* nearests, unsigned width, unsigned height) {
	unsigned max_step = highest_power_of_two(max(width, height));
	for (unsigned step = max_step; step > 0; step /= 2) {
		for (unsigned y = 0; y < height; y++)
		for (unsigned x = 0; x < width;  x++) {
			ivec2* nearest = nearests + get_index(x, y, width);
			unsigned d_2 = dist_2(x, y, *nearest);

			ivec2 new_nearest;
			unsigned new_d_2;
			for (unsigned n = 0; n < NEIGHBOR_COUNT; n++) {
				int nx = x + off_x[n] * step;
				int ny = y + off_y[n] * step;
				if (!is_in_bounds(nx, ny, width, height)) {
					continue;
				}

				new_nearest = nearests[get_index(
					nx,
					ny,
					width
				)];
				new_d_2 = dist_2(x, y, new_nearest);

				if (new_d_2 < d_2) {
					d_2 = new_d_2;
					*nearest = new_nearest;
				}
			}
		}
	}
}
Beispiel #2
0
    hex_grid_cell_t& hex_grid_t::cell_at(ivec2 hex_coord)
    {
        ASSERT(is_in_bounds(hex_coord), "Asking for a cell that is out of bounds");

        auto chunk_coord = chunk_coord_from_hex_coord(hex_coord);
        hex_grid_chunk_t& chunk = chunks[chunk_coord.x][chunk_coord.y];

        ivec2 local_hex_coord = hex_coord - (chunk_coord * ivec2(new_chunk_width, new_chunk_height));
        return chunk.cell_at_local_coord(local_hex_coord);
    }
/**
* player_search(uint16 curx, uint16 cury)
*
* @brief
* @param curx
* @param cury
* @return void
*/
void player_search(uint16 curx, uint16 cury)
{
	buffer_t buffer;

	if(is_in_bounds()){
		clear_buffer(&buffer);
		add_opcode(&buffer, CSEARCH);
		add_buffer(&buffer, &tempdata()->curx, SIZE8);
		add_buffer(&buffer, &tempdata()->cury, SIZE8);
		socketsend(&buffer);
	}
}
Beispiel #4
0
std::unique_ptr<State> PlayingState::update()
{
	handle_input();
	_snake.update();

	if (_snake.head() == _food) {
		_snake.eat();
		position_food();
	} else if (_snake.is_in_body(_snake.head()) || !is_in_bounds(_snake.head())) {
		_complete = true;
	}

	if (_complete)
		return std::unique_ptr<YouDeadState>(new YouDeadState(State::_width, State::_height));

	return std::unique_ptr<PlayingState>(new PlayingState(*this));
}
void ae::Screen_buffer::put_char(int x, int y, char val) {
  if (!is_in_bounds(x, y))
    return;
  screen_output->print_char_at(x, y, val);
}