// // Pattern map generator. // #define MAX_POINT 124 #include "raylib.h" #include enum flag{UP,DOWN,LEFT,RIGHT}; static int screenWidth = 800; static int screenHeight = 450; static int mapWidth=100; static int mapHeight=100; static float tileWidth; static float tileHeight; static int map[512][512]; typedef struct point{ bool active; Vector2 position; }point; static point arr_point[MAX_POINT]; static void generate(void); // generate the map. static void makenice(); // add walls. int main(void) { // Initialization //-------------------------------------------------------------------------------------- tileWidth = abs((float)screenWidth/(float)mapWidth); tileHeight = abs((float)screenHeight/(float)mapHeight); InitWindow(screenWidth, screenHeight, "raylib example."); generate(); makenice(); SetTargetFPS(60); // Set our game to run at 60 frames-per-second //--------------------------------+------------------------------------------------------ static int time=0; // Main game loop while (!WindowShouldClose()) // Detect window close button or ESC key { // Update //---------------------------------------------------------------------------------- if(IsKeyReleased(KEY_SPACE)){ generate(); makenice(); } time++; if(time>100){ time=0; generate(); makenice(); } //---------------------------------------------------------------------------------- // Draw //---------------------------------------------------------------------------------- BeginDrawing(); ClearBackground(RAYWHITE); // Draw the map for(int y=0;ymapWidth-6)x-=7; break; case LEFT: x-=7; if(x<6)x+=7; break; case UP: y-=7; if(y<6)y+=7; break; case DOWN: y+=7; if(ymapWidth-1 || y2>mapHeight-1)continue; map[x2][y2]=1; }} } for(int i=0;ix1){ while(x1mapWidth-1 || y1>mapHeight-1)continue; map[x1][y1]=2; } } if(x1>x2){ while(x1>x2){ x1--; if(x1<0 || y1<0 || x1>mapWidth-1 || y1>mapHeight-1)continue; map[x1][y1]=2; } } if(y2>y1){ while(y1mapWidth-1 || y1>mapHeight-1)continue; map[x1][y1]=2; } } if(y1>y2){ while(y1>y2){ y1--; if(x1<0 || y1<0 || x1>mapWidth-1 || y1>mapHeight-1)continue; map[x1][y1]=2; } } } } void makenice(){ // add walls to rooms for(int y=1;y0)map[x][y]=3; } } // add walls to halls. for(int y=1;y0)map[x][y]=3; } } } // turn door lines into floor for(int y=1;y0){ top=y; ex=true; break; } } if(ex)break; } //find left most int left=0; for(int x=0;x0){ left=x; ex=true; break; } } if(ex)break; } // Copy map into buffer map from where it begins on the map top and left // and then copy this all back to the main map. int m2[200][200]; for(int y=0;y0;x--){ bool ex=false; for(int y=0;y0){ right = x; ex=true; break; } } if(ex)break; } // find most bottom part int bottom=0; for(int y=mapHeight-1;y>0;y--){ bool ex=false; for(int x=0;x0){ bottom = y; ex=true; break; } } if(ex)break; } mapWidth = right+1; mapHeight = bottom+1; tileWidth = abs((float)screenWidth/(float)mapWidth); tileHeight = abs((float)screenHeight/(float)mapHeight); }