finished the bulk of game
This commit is contained in:
18
src/map.cc
18
src/map.cc
@ -1,9 +1,10 @@
|
||||
#include "map.h"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include "constants.h"
|
||||
|
||||
game_map::game_map(character *player, RNG *rng, const feature enabled_features):
|
||||
enabled_features{enabled_features} {
|
||||
map.reserve(MAP_HEIGHT * MAP_WIDTH);
|
||||
@ -25,7 +26,6 @@ game_map::game_map(character *player, RNG *rng, const feature enabled_features):
|
||||
|
||||
gen_path(layer_data, rng);
|
||||
|
||||
|
||||
rooms_tile_list.reserve(room_data.size());
|
||||
|
||||
for (size_t i = 0; i < room_data.size(); ++i)
|
||||
@ -41,7 +41,7 @@ game_map::game_map(character *player, RNG *rng, const feature enabled_features):
|
||||
rooms_tile_list.shrink_to_fit();
|
||||
|
||||
int player_room = rng->rand_under(room_data.size());
|
||||
player->set_position(rng->get_rand_in_vector(rooms_tile_list[player_room]));
|
||||
player->set_pos(rng->get_rand_in_vector(rooms_tile_list[player_room]));
|
||||
|
||||
gen_stairs(player_room, rng);
|
||||
}
|
||||
@ -96,7 +96,7 @@ game_map::game_map(character *player, const std::string &map_data,
|
||||
room_data.push_back({0, 0, 0, 0});
|
||||
|
||||
int player_room = rng->rand_under(room_data.size());
|
||||
player->set_position(rng->get_rand_in_vector(rooms_tile_list[player_room]));
|
||||
player->set_pos(rng->get_rand_in_vector(rooms_tile_list[player_room]));
|
||||
|
||||
gen_stairs(player_room, rng);
|
||||
|
||||
@ -277,7 +277,7 @@ std::vector<game_map::room> game_map::distr_rooms(RNG *rng,
|
||||
if (l == r) {
|
||||
result.push_back({
|
||||
0, rng->rand_under(ACTUAL_MAP_WIDTH -
|
||||
room_dims[l].first.x + 1),
|
||||
room_dims[l].first.x + 1),
|
||||
room_dims[l].first.x,
|
||||
room_dims[l].first.y, {0, 0}, {0, 0}});
|
||||
continue;
|
||||
@ -557,3 +557,11 @@ bool game_map::hit_room(const position &a, const room &r) {
|
||||
return a.y >= r.top - 1 && a.y <= r.top + r.height &&
|
||||
a.x >= r.left - 1 && a.x <= r.left + r.width;
|
||||
}
|
||||
|
||||
position game_map::remap_index(const int idx) const {
|
||||
return {idx % MAP_WIDTH, idx / MAP_WIDTH};
|
||||
}
|
||||
|
||||
int game_map::remap_position(const position &pos) const {
|
||||
return pos.y * MAP_WIDTH + pos.x;
|
||||
}
|
||||
|
Reference in New Issue
Block a user