48 lines
1.3 KiB
C++
48 lines
1.3 KiB
C++
#include "level.hpp"
|
|
#include "game/components.hpp"
|
|
|
|
#include <random>
|
|
|
|
namespace trb::game {
|
|
components::wall_definition generate_random_wall() {
|
|
static std::mt19937 engine{std::random_device{}()};
|
|
|
|
std::uniform_int_distribution<std::size_t> count_dist(0, 4);
|
|
std::uniform_int_distribution<int> binary_dist(0, 1);
|
|
|
|
auto def = components::wall_definition{
|
|
.wall_count = count_dist(engine),
|
|
.type = static_cast<components::wall_type>(binary_dist(engine)),
|
|
};
|
|
|
|
for (std::size_t i = 0; i < def.wall_count; ++i) {
|
|
def.heights[i] = static_cast<components::wall_height>(binary_dist(engine));
|
|
}
|
|
|
|
return def;
|
|
}
|
|
|
|
void level::create_wall_at(glm::uvec2 tile) {
|
|
const auto wall_entity = entities.create();
|
|
|
|
entities.emplace<components::tile_position>(wall_entity,
|
|
components::tile_position{tile});
|
|
entities.emplace<components::wall_definition>(wall_entity,
|
|
generate_random_wall());
|
|
}
|
|
|
|
level::level() {
|
|
// for (int x = 0; x < 22; x++) {
|
|
// for (int y = 0; y < 16; y++) {
|
|
create_wall_at({0, 0});
|
|
create_wall_at({11, 8});
|
|
//}
|
|
//}
|
|
}
|
|
|
|
entt::basic_registry<std::uint32_t> *level::get_entities() { return &entities; }
|
|
|
|
glm::uvec2 level::get_bounds() const noexcept { return {WIDTH, HEIGHT}; }
|
|
|
|
} // namespace trb::game
|