First hack to get a random gen map going.

This commit is contained in:
Zed A. Shaw 2025-01-30 13:23:12 -05:00
parent 2daa1c9bd5
commit 56d67aba28
7 changed files with 72 additions and 34 deletions

View file

@ -5,18 +5,7 @@
#include <functional>
#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;