// // This map generator works by first creating one random rectangle in the room. This rectangle has walls. // We then create more rectangles randomly on the map and when one of these its edges touches another // edge we create another room there. // // We only draw walls on empty map places so there will be a floor area created. // #include "raylib.h" #include // For the ceil function const int screenWidth = 800; const int screenHeight = 450; static int map[100][100]; static int mapWidth = 100; static int mapHeight = 100; static int tileWidth = 100; static int tileHeight = 100; static void drawmap(); static void makemap(); static void makerect(int x,int y,int w,int h,bool force); static bool maprectcheck(int x,int y,int w,int h); static void edgeenhance(); static float edistance(float x1,float y1,float x2,float y2); int main(void) { // Initialization //-------------------------------------------------------------------------------------- InitWindow(screenWidth, screenHeight, "raylib example."); // Get the tile width and height based on the amount of tiles hor and vertical on the screen. tileWidth = ceil((float)screenWidth/(float)mapWidth); tileHeight = ceil((float)screenHeight/(float)mapHeight); makemap(); SetTargetFPS(60); // Set our game to run at 60 frames-per-second //-------------------------------------------------------------------------------------- // Main game loop while (!WindowShouldClose()) // Detect window close button or ESC key { // Update //---------------------------------------------------------------------------------- if(IsKeyReleased(KEY_SPACE)){ makemap(); } //---------------------------------------------------------------------------------- // Draw //---------------------------------------------------------------------------------- BeginDrawing(); ClearBackground((Color){20,20,20,255}); drawmap(); edgeenhance(); DrawRectangle(0,0,screenWidth,20,DARKGRAY); DrawText("Press space to generate new map.",3,0,20,WHITE); EndDrawing(); //---------------------------------------------------------------------------------- } // De-Initialization //-------------------------------------------------------------------------------------- CloseWindow(); // Close window and OpenGL context //-------------------------------------------------------------------------------------- return 0; } static void makemap(){ // Clear anything that was inside the map array. for(int y=0;y=mapWidth-10 || y<0 || y+h>=mapHeight-10)return; // if(force==false){ int edge=0; int cnt=0; bool good1=false; // Check if top is inside another rect and one below is nothing. for(int x1=x;x13)edge++; good1=false; cnt=0; // Check if bottom is inside another rect and one above is nothing. for(int x1=x;x13)edge++; good1=false; cnt=0; // Check if left side is inside another rect and one lefter is nothing. for(int y1=y;y13)edge++; good1=false; cnt=0; // Check if right side is inside another rect and one righter is nothing. for(int y1=y;y13)edge++; if(edge!=1)return; } //Draw walls for(int y1=y;y11)swx=0; } swx++; if(swx>1)swx=0; } }; static void edgeenhance(){ for(int y=0;y