diff --git a/assets/tiles.json b/assets/tiles.json index 4733c86..a8f7224 100644 --- a/assets/tiles.json +++ b/assets/tiles.json @@ -1,20 +1,30 @@ { - "WALL_TILE": { + "FLOOR_TILE": { + "id": "0", + "foreground": [40, 15, 125], + "background": [200, 15, 75], + "collision": false, + "display":"\u289e" + }, + "WALL_PLAIN": { + "id": 1, "foreground": [230, 20, 30], "background": [230, 20, 120], "collision": true, "display": "\ua5b8" }, - "FLOOR_TILE": { + "WALL_VINES": { + "id": 2, "foreground": [40, 15, 125], - "background": [200, 15, 75], + "background": [200, 29, 75], "collision": false, - "display":"\u289e" + "display":"\u19f0" }, - "CEILING_TILE": { - "foreground": [159, 164, 15], - "background": [199, 15, 79], - "collision": true, - "display":"\u2274" + "WALL_PILLAR": { + "id": 3, + "foreground": [40, 15, 125], + "background": [200, 29, 75], + "collision": false, + "display":"\u16de" } } diff --git a/main.cpp b/main.cpp index 7d9b05e..417bae5 100644 --- a/main.cpp +++ b/main.cpp @@ -5,18 +5,7 @@ #include #include "constants.hpp" #include "stats.hpp" - -Matrix MAP{ - {1,1,1,3,2,3,1,1,1}, - {1,0,1,0,0,0,0,0,1}, - {1,0,1,0,0,1,1,0,1}, - {3,0,0,0,0,0,0,0,3}, - {2,1,0,0,0,0,0,1,2}, - {3,0,0,1,1,1,0,0,3}, - {1,0,0,0,0,0,1,1,1}, - {1,0,0,0,0,0,0,0,1}, - {1,1,1,3,2,3,1,1,1} -}; +#include "worldbuilder.hpp" void draw_gui(sf::RenderWindow &window, sf::Text &text, Stats &stats) { sf::RectangleShape rect({SCREEN_WIDTH - RAY_VIEW_WIDTH, SCREEN_HEIGHT}); @@ -31,6 +20,38 @@ void draw_gui(sf::RenderWindow &window, sf::Text &text, Stats &stats) { window.draw(text); } +Matrix generate_map(Map& map, Point &player) { + // generate the world and make the map + WorldBuilder builder(map); + builder.generate_map(); + + bool can_place = map.place_entity(1, player); + dbc::check(can_place, "couldn't place the player"); + + auto &tiles = map.tiles(); + tiles.dump(player.x, player.y); + + auto bad_map = matrix::make(tiles.width(), tiles.height()); + + for(matrix::each_cell it(tiles.$tile_ids); it.next();) { + switch(tiles.$tile_ids[it.y][it.x]) { + case 0x289e: + bad_map[it.y][it.x] = 0; break; + case 0xa5b8: + bad_map[it.y][it.x] = 1; break; + case 0x19f0: + bad_map[it.y][it.x] = 2; break; + case 0x16de: + bad_map[it.y][it.x] = 3; break; + default: + bad_map[it.y][it.x] = 0; + } + } + + matrix::dump("CONVERTED MAP", bad_map); + return bad_map; +} + void draw_weapon(sf::RenderWindow &window, sf::Sprite &weapon, float rotation) { weapon.setPosition({SCREEN_WIDTH/2,SCREEN_HEIGHT/2}); weapon.setRotation(sf::degrees(rotation)); @@ -45,13 +66,13 @@ int main() { text.setFillColor({255,255,255}); text.setPosition({10,10}); - //ZED this should set with a function - float player_x = matrix::width(MAP) / 2; - float player_y = matrix::height(MAP) / 2; + Map map(30, 30); + Point player{0, 0}; + auto MAP = generate_map(map, player); Raycaster rayview(window, MAP, RAY_VIEW_WIDTH, RAY_VIEW_HEIGHT); rayview.set_position(RAY_VIEW_X, RAY_VIEW_Y); - rayview.position_camera(player_x, player_y); + rayview.position_camera(player.x, player.y); rayview.init_shaders(); double moveSpeed = 0.1; diff --git a/raycaster.cpp b/raycaster.cpp index 0064205..37b7ea9 100644 --- a/raycaster.cpp +++ b/raycaster.cpp @@ -240,7 +240,7 @@ void Raycaster::cast_rays() { int drawEnd = lineHeight / 2 + $height / 2 + $pitch; if(drawEnd >= $height) drawEnd = $height - 1; - auto texture = $textures.get_texture($map[mapY][mapX] - 1); + auto texture = $textures.get_surface($map[mapY][mapX] - 1); // calculate value of wallX double wallX; // where exactly the wall was hit diff --git a/texture.cpp b/texture.cpp index 15cdb1b..cb44063 100644 --- a/texture.cpp +++ b/texture.cpp @@ -39,15 +39,15 @@ void TexturePack::load_textures() { Config assets("assets/config.json"); for(string tile_path : assets["textures"]) { - images.emplace_back(load_image(tile_path)); + surfaces.emplace_back(load_image(tile_path)); } floor = load_image(assets["sprites"]["floor"]); ceiling = load_image(assets["sprites"]["ceiling"]); } -const uint32_t* TexturePack::get_texture(size_t num) { - return (const uint32_t *)images[num].getPixelsPtr(); +const uint32_t* TexturePack::get_surface(size_t num) { + return (const uint32_t *)surfaces[num].getPixelsPtr(); } Sprite &TexturePack::get_sprite(size_t sprite_num) { diff --git a/texture.hpp b/texture.hpp index bd4619d..6a968a7 100644 --- a/texture.hpp +++ b/texture.hpp @@ -19,7 +19,7 @@ struct Sprite { }; struct TexturePack { - std::vector images; + std::vector surfaces; std::vector sprites; std::unordered_map sprite_textures; sf::Image floor; @@ -30,7 +30,7 @@ struct TexturePack { void load_sprites(); sf::Image load_image(std::string filename); Sprite& get_sprite(size_t sprite_num); - const uint32_t* get_texture(size_t num); + const uint32_t* get_surface(size_t num); // this needs to go into a map place void position_sprite(double x, double y, std::string name); }; diff --git a/tilemap.cpp b/tilemap.cpp index 33bf726..8987144 100644 --- a/tilemap.cpp +++ b/tilemap.cpp @@ -45,7 +45,7 @@ void TileMap::set_tile(size_t x, size_t y, string tile_name) { void TileMap::load(matrix::Matrix &walls) { for(matrix::each_cell it{walls}; it.next();) { - string tile_name = walls[it.y][it.x] == SPACE_VALUE ? "FLOOR_TILE" : "WALL_TILE"; + string tile_name = walls[it.y][it.x] == SPACE_VALUE ? "FLOOR_TILE" : "WALL_PLAIN"; set_tile(it.x, it.y, tile_name); } } diff --git a/worldbuilder.cpp b/worldbuilder.cpp index ab31cd5..a4af291 100644 --- a/worldbuilder.cpp +++ b/worldbuilder.cpp @@ -110,10 +110,17 @@ void WorldBuilder::stylize_room(int room, string tile_name, float size) { bool placed = $map.place_entity(room, pos_out); dbc::check(placed, "failed to place style in room"); + dbc::log("FIX THE SYTLE ROOM TO VARY FLOOR OR WALL"); + tile_name = tile_name == "FLOOR_TILE" ? "WALL_PLAIN" : tile_name; + for(matrix::circle it{$map.$walls, pos_out, size}; it.next();) { for(int x = it.left; x < it.right; x++) { - if(!$map.iswall(x, it.y)) { + if($map.iswall(x, it.y)) { + // a wall tile $map.$tiles.set_tile(x, it.y, tile_name); + } else { + // a floor tile + $map.$tiles.set_tile(x, it.y, "FLOOR_TILE"); } } }