Minor tweaks
This commit is contained in:
parent
68d85c5eae
commit
e0d1bcad3a
5 changed files with 65 additions and 15 deletions
|
@ -21,7 +21,7 @@ local tiles = {
|
||||||
},
|
},
|
||||||
dungeon_floor = {
|
dungeon_floor = {
|
||||||
glyph = '.',
|
glyph = '.',
|
||||||
fg = {.8,.8,1,1},
|
fg = {.8,.8,.95,1},
|
||||||
bg = {.1,.1,.2,1},
|
bg = {.1,.1,.2,1},
|
||||||
passable = true,
|
passable = true,
|
||||||
opaque = false,
|
opaque = false,
|
||||||
|
@ -29,6 +29,26 @@ local tiles = {
|
||||||
description = "A stone floor",
|
description = "A stone floor",
|
||||||
tags = { "dungeon", "stone", "floor" }
|
tags = { "dungeon", "stone", "floor" }
|
||||||
},
|
},
|
||||||
|
-- dungeon_floor2 = {
|
||||||
|
-- glyph = '.',
|
||||||
|
-- fg = {.85,.85,.9,1},
|
||||||
|
-- bg = {.15,.15,.25,1},
|
||||||
|
-- passable = true,
|
||||||
|
-- opaque = false,
|
||||||
|
-- wall = false,
|
||||||
|
-- description = "A stone floor",
|
||||||
|
-- tags = { "dungeon", "stone", "floor" }
|
||||||
|
-- },
|
||||||
|
-- dungeon_floor3 = {
|
||||||
|
-- glyph = '.',
|
||||||
|
-- fg = {.75,.75,.95,1},
|
||||||
|
-- bg = {.1,.1,.25,1},
|
||||||
|
-- passable = true,
|
||||||
|
-- opaque = false,
|
||||||
|
-- wall = false,
|
||||||
|
-- description = "A stone floor",
|
||||||
|
-- tags = { "dungeon", "stone", "floor" }
|
||||||
|
-- },
|
||||||
dungeon_entrance = {
|
dungeon_entrance = {
|
||||||
glyph = '>',
|
glyph = '>',
|
||||||
fg = {.8,.8,1,1},
|
fg = {.8,.8,1,1},
|
||||||
|
@ -49,6 +69,26 @@ local tiles = {
|
||||||
description = "Stone stairs going downwards",
|
description = "Stone stairs going downwards",
|
||||||
tags = { "dungeon", "stone", "exit" }
|
tags = { "dungeon", "stone", "exit" }
|
||||||
},
|
},
|
||||||
|
-- grass = {
|
||||||
|
-- glyph = '"',
|
||||||
|
-- fg = {.4,.95,.4,1},
|
||||||
|
-- bg = {.1,.15,.2,1},
|
||||||
|
-- passable = true,
|
||||||
|
-- opaque = false,
|
||||||
|
-- wall = false,
|
||||||
|
-- description = "A patch of grass",
|
||||||
|
-- tags = { "dungeon", "floor", "grass" }
|
||||||
|
-- },
|
||||||
|
-- moss = {
|
||||||
|
-- glyph = '.',
|
||||||
|
-- fg = {.4,.95,.4,1},
|
||||||
|
-- bg = {.1,.15,.2,1},
|
||||||
|
-- passable = true,
|
||||||
|
-- opaque = false,
|
||||||
|
-- wall = false,
|
||||||
|
-- description = "A patch of moss",
|
||||||
|
-- tags = { "dungeon", "floor", "moss" }
|
||||||
|
-- },
|
||||||
}
|
}
|
||||||
|
|
||||||
local dijkstra_debug_amount = 100
|
local dijkstra_debug_amount = 100
|
||||||
|
|
|
@ -20,6 +20,10 @@ bool aabb(Room &a, Room &b) {
|
||||||
a.pos.y <= b.pos.y + b.size.y && a.pos.y + a.size.y >= b.pos.y;
|
a.pos.y <= b.pos.y + b.size.y && a.pos.y + a.size.y >= b.pos.y;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<class T> T rand_entry(std::vector<T> &vec, Rng &rng) {
|
||||||
|
return vec[rng.get_int(vec.size()-1)];
|
||||||
|
}
|
||||||
|
|
||||||
void maze_fill(Tilemap& map, int x, int y, std::string wall, std::string floor, Rng &rng) {
|
void maze_fill(Tilemap& map, int x, int y, std::string wall, std::string floor, Rng &rng) {
|
||||||
if (!map.get_tile(x, y).wall) return;
|
if (!map.get_tile(x, y).wall) return;
|
||||||
|
|
||||||
|
@ -55,7 +59,7 @@ void maze_fill(Tilemap& map, int x, int y, std::string wall, std::string floor,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!options.empty()) {
|
if (!options.empty()) {
|
||||||
stack.emplace(options.at(rng.get_int(options.size() - 1)));
|
stack.emplace(rand_entry<vec2i>(options,rng));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
stack.pop();
|
stack.pop();
|
||||||
|
@ -87,7 +91,7 @@ Tilemap generate_dungeon(unsigned int seed, int width, int height, TileSet tiles
|
||||||
// Set the whole map to walls
|
// Set the whole map to walls
|
||||||
for (int y = 0; y < height; ++y) {
|
for (int y = 0; y < height; ++y) {
|
||||||
for (int x = 0; x < width; ++x) {
|
for (int x = 0; x < width; ++x) {
|
||||||
map.set_tile(x, y, wall_tiles[rng.get_int(0, wall_tiles.size()-1)]);
|
map.set_tile(x, y, rand_entry<std::string>(wall_tiles, rng));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -115,7 +119,7 @@ Tilemap generate_dungeon(unsigned int seed, int width, int height, TileSet tiles
|
||||||
for (Room r : rooms) {
|
for (Room r : rooms) {
|
||||||
for (int x = r.pos.x+1; x < r.pos.x + r.size.x-1; x++) {
|
for (int x = r.pos.x+1; x < r.pos.x + r.size.x-1; x++) {
|
||||||
for (int y = r.pos.y+1; y < r.pos.y + r.size.y-1; y++) {
|
for (int y = r.pos.y+1; y < r.pos.y + r.size.y-1; y++) {
|
||||||
map.set_tile(x, y, floor_tiles[rng.get_int(0, floor_tiles.size() - 1)]);
|
map.set_tile(x, y, rand_entry<std::string>(floor_tiles, rng));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -133,7 +137,7 @@ Tilemap generate_dungeon(unsigned int seed, int width, int height, TileSet tiles
|
||||||
}
|
}
|
||||||
// If this tile is a wall and is completely surrounded by other walls, start generating a maze here.
|
// If this tile is a wall and is completely surrounded by other walls, start generating a maze here.
|
||||||
if (count >= 8) {
|
if (count >= 8) {
|
||||||
maze_fill(map, x, y, wall_tiles[rng.get_int(0, wall_tiles.size() - 1)], floor_tiles[rng.get_int(0, floor_tiles.size() - 1)], rng);
|
maze_fill(map, x, y, rand_entry<std::string>(wall_tiles, rng), floor_tiles[rng.get_int(0, floor_tiles.size() - 1)], rng);
|
||||||
maze_start_points.emplace_back(vec2i(x, y));
|
maze_start_points.emplace_back(vec2i(x, y));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -186,7 +190,7 @@ Tilemap generate_dungeon(unsigned int seed, int width, int height, TileSet tiles
|
||||||
|
|
||||||
int r = rng.get_int(potential_doors.size()-1);
|
int r = rng.get_int(potential_doors.size()-1);
|
||||||
vec2i pos = potential_doors.at(r);
|
vec2i pos = potential_doors.at(r);
|
||||||
map.set_tile(pos.x, pos.y, door_tiles[rng.get_int(0, door_tiles.size() - 1)]);
|
map.set_tile(pos.x, pos.y, rand_entry<std::string>(door_tiles, rng));
|
||||||
potential_doors.erase(r + potential_doors.begin());
|
potential_doors.erase(r + potential_doors.begin());
|
||||||
for (int j = potential_doors.size() - 1; j >= 0; j--) {
|
for (int j = potential_doors.size() - 1; j >= 0; j--) {
|
||||||
if ((pos - potential_doors[j]).dist() <= 4) {
|
if ((pos - potential_doors[j]).dist() <= 4) {
|
||||||
|
@ -231,11 +235,11 @@ Tilemap generate_dungeon(unsigned int seed, int width, int height, TileSet tiles
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (count == 1) {
|
if (count == 1) {
|
||||||
map.set_tile(pos.x, pos.y, wall_tiles[rng.get_int(0, wall_tiles.size() - 1)]);
|
map.set_tile(pos.x, pos.y, rand_entry<std::string>(wall_tiles, rng));
|
||||||
new_dead_ends.emplace_back(next);
|
new_dead_ends.emplace_back(next);
|
||||||
}
|
}
|
||||||
else if (count == 0) {
|
else if (count == 0) {
|
||||||
map.set_tile(pos.x, pos.y, wall_tiles[rng.get_int(0, wall_tiles.size() - 1)]);
|
map.set_tile(pos.x, pos.y, rand_entry<std::string>(wall_tiles, rng));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
dead_ends = new_dead_ends;
|
dead_ends = new_dead_ends;
|
||||||
|
|
|
@ -126,15 +126,17 @@ Gamestate *PlayState::update(double delta) {
|
||||||
}
|
}
|
||||||
if (dir != vec2i(0,0)) {
|
if (dir != vec2i(0,0)) {
|
||||||
if (!actor->move(dir.x, dir.y, &tilemap)) {
|
if (!actor->move(dir.x, dir.y, &tilemap)) {
|
||||||
vec2i heropos = actor->get_position();
|
vec2i pos = actor->get_position();
|
||||||
Actor* act = tilemap.get_actor(heropos.x + dir.x, heropos.y + dir.y);
|
auto acts = tilemap.get_actors(pos.x + dir.x, pos.y + dir.y, 0);
|
||||||
if(act == nullptr) {
|
if(acts.empty()) {
|
||||||
SDL_LogVerbose(SDL_LOG_CATEGORY_SYSTEM, "Turn aborted: invalid player action.\n");
|
SDL_LogVerbose(SDL_LOG_CATEGORY_SYSTEM, "Turn aborted: invalid player action.\n");
|
||||||
player_action = ACTION_NONE;
|
player_action = ACTION_NONE;
|
||||||
return nullptr; // unable to move and nothing to attack == abort turn
|
return nullptr; // unable to move and nothing to attack == abort turn
|
||||||
}
|
}
|
||||||
if (act->is_alive() && act->get_actor_faction() != actor->get_actor_faction()) {
|
for (Actor* a : acts) {
|
||||||
actor->attack(act);
|
if (a->is_alive() && a->get_actor_faction() != actor->get_actor_faction()) {
|
||||||
|
actor->attack(a);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -240,7 +242,8 @@ void PlayState::draw(double delta) {
|
||||||
int sprite = var->get_sprite_id();
|
int sprite = var->get_sprite_id();
|
||||||
|
|
||||||
Color fg = var->get_sprite_color()*0.35f;
|
Color fg = var->get_sprite_color()*0.35f;
|
||||||
app->renderer->draw_sprite(ascii->get_sprite(sprite), fg, black, margin.x + (offset.x + pos.x) * asciisize.x, margin.y + (offset.y + pos.y) * asciisize.y);
|
Color bg = tilemap.get_tile(pos.x, pos.y).bg;
|
||||||
|
app->renderer->draw_sprite(ascii->get_sprite(sprite), fg, bg, margin.x + (offset.x + pos.x) * asciisize.x, margin.y + (offset.y + pos.y) * asciisize.y);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -66,7 +66,7 @@ void TileSet::load_from_table(kaguya::LuaStackRef table) {
|
||||||
else {
|
else {
|
||||||
SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION, "Tileset: Missing value wall for tile: %s", key.c_str());
|
SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION, "Tileset: Missing value wall for tile: %s", key.c_str());
|
||||||
}
|
}
|
||||||
SDL_LogDebug(SDL_LOG_CATEGORY_APPLICATION, "Tileset: Added tile: %s", key.c_str());
|
//SDL_LogDebug(SDL_LOG_CATEGORY_APPLICATION, "Tileset: Added tile: %s", key.c_str());
|
||||||
tiles[key] = t;
|
tiles[key] = t;
|
||||||
if (tiles.count(key) == 0) {
|
if (tiles.count(key) == 0) {
|
||||||
SDL_LogDebug(SDL_LOG_CATEGORY_APPLICATION, "Tileset: Could not find the tile we just added?!: %s", key.c_str());
|
SDL_LogDebug(SDL_LOG_CATEGORY_APPLICATION, "Tileset: Could not find the tile we just added?!: %s", key.c_str());
|
||||||
|
|
|
@ -111,6 +111,7 @@ Actor * Tilemap::get_actor(int x, int y) {
|
||||||
std::vector<Actor*> Tilemap::get_actors(int x, int y, int range) {
|
std::vector<Actor*> Tilemap::get_actors(int x, int y, int range) {
|
||||||
std::vector<Actor*> found;
|
std::vector<Actor*> found;
|
||||||
std::vector<vec2i> neigh = get_neighbours(x, y, range);
|
std::vector<vec2i> neigh = get_neighbours(x, y, range);
|
||||||
|
neigh.emplace_back(vec2i(x,y));
|
||||||
for (Actor* ent : actors) {
|
for (Actor* ent : actors) {
|
||||||
for (vec2i pos : neigh) {
|
for (vec2i pos : neigh) {
|
||||||
vec2i apos = ent->get_position();
|
vec2i apos = ent->get_position();
|
||||||
|
@ -157,10 +158,12 @@ void Tilemap::draw(Renderer *renderer, SpriteAtlas* sprites, int x, int y, int t
|
||||||
}
|
}
|
||||||
|
|
||||||
void Tilemap::debug_print() {
|
void Tilemap::debug_print() {
|
||||||
|
/*
|
||||||
for (int y = 0; y < height; ++y) {
|
for (int y = 0; y < height; ++y) {
|
||||||
for (int x = 0; x < width; ++x) {
|
for (int x = 0; x < width; ++x) {
|
||||||
printf("\t%d", get_tile(x, y));
|
printf("\t%d", get_tile(x, y));
|
||||||
}
|
}
|
||||||
printf("\n");
|
printf("\n");
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue