// // Wave Function Collapse - sort of... // // I barely understand how this works. It has taken me a number of tries and a whack load of hours // top get to this current point. The tutorials and explanations on the internet are not that clear and easy // to understand. // // In the example here I have a number of tiles. I pick a random tile from the valid ones and place it on the grid. // I then fix the neighbour tiles to fit this current position. Connected/unconnected. I keep placing random tiles // for a x amount of times. // There is a array that contains a list of all possible tiles. There are functions that check if a position on the grid // has connections to another position on the grid. This is used to unflag the tiles that are on the list to get // selected(one random) as a tile to be placed. // note: the array(x,y,slot) has one slot for every possible tile. when tile x,y has no left sided connection then // the array position on the left of that one will have all right sided connection tiles unflagged. // // The MAX_TILES is the amount of tiles that I have created to create the map with. I check the middle top/left/right/bottom // tile value to see if there is a connection(1). Experiment with making different tiles. // // I might(should) add comments to the code later. // #include "raylib.h" #define MAP_WIDTH 10 #define MAP_HEIGHT 10 #define MAX_TILES 15 static void newmap(void); static void resetmap(void); static bool domainhasleftsidedconnections(int x,int y); static bool domainhasrightsidedconnections(int x,int y); static bool domainhastopsidedconnections(int x,int y); static bool domainhasbottomsidedconnections(int x,int y); static void removeleftsidedconnections(int x,int y); static void removerightsidedconnections(int x,int y); static void removetopsidedconnections(int x,int y); static void removebottomsidedconnections(int x,int y); static void setrandomtile(int x,int y); static void updatedomain(int x,int y); static void finishmap(void); static int tile[3][3][MAX_TILES] = {0}; static int map[MAP_WIDTH][MAP_HEIGHT][MAX_TILES] = {0}; static int tilemap[MAP_WIDTH][MAP_HEIGHT] = {0}; int main(void) { // Initialization //-------------------------------------------------------------------------------------- const int screenWidth = 800; const int screenHeight = 450; InitWindow(screenWidth, screenHeight, "raylib example."); int tile1[3][3] = { {0,1,0}, {0,1,0}, {0,1,0}}; int tile2[3][3] = { {0,0,0}, {1,1,1}, {0,0,0}}; int tile3[3][3] = { {1,1,1}, {1,1,1}, {1,1,1}}; int tile4[3][3] = { {0,1,0}, {1,1,1}, {0,1,0}}; int tile5[3][3] = { {0,1,0}, {1,1,0}, {0,0,0}}; int tile6[3][3] = { {0,1,0}, {0,1,1}, {0,0,0}}; int tile7[3][3] = { {0,0,0}, {1,1,0}, {0,1,0}}; int tile8[3][3] = { {0,0,0}, {0,1,1}, {0,1,0}}; int tile9[3][3] = { {0,1,0}, {1,1,1}, {0,0,0}}; int tile10[3][3] = { {0,1,0}, {0,1,1}, {0,1,0}}; int tile11[3][3] = { {0,0,0}, {1,1,1}, {0,1,0}}; int tile12[3][3] = { {0,1,0}, {1,1,0}, {0,1,0}}; int tile13[3][3] = { {1,1,0}, {1,1,0}, {1,1,0}}; int tile14[3][3] = { {0,1,1}, {0,1,1}, {0,1,1}}; int tile15[3][3] = { {0,0,0}, {1,1,1}, {1,1,1}}; // int tile[3][3][4] = {0}; for(int i=0;i-1){ tilemap[x][y] = i; } } }} }; void resetmap(){ for(int y=0;y=MAP_WIDTH || y>=MAP_HEIGHT)return false; for(int i=0;i=MAP_WIDTH || y>=MAP_HEIGHT)return false; for(int i=0;i=MAP_WIDTH || y>=MAP_HEIGHT)return false; for(int i=0;i=MAP_WIDTH || y>=MAP_HEIGHT)return false; for(int i=0;i=MAP_WIDTH || y>=MAP_HEIGHT)return false; for(int i=0;i=MAP_WIDTH || y>=MAP_HEIGHT)return false; for(int i=0;i=MAP_WIDTH || y>=MAP_HEIGHT)return false; for(int i=0;i=MAP_WIDTH || y>=MAP_HEIGHT)return false; for(int i=0;i-1){ for(int i=0;i500)exitloop=true; } updatedomain(x-1,y); updatedomain(x+1,y); updatedomain(x,y-1); updatedomain(x,y+1); }; void updatedomain(int x,int y){ if(x<0 || y<0 || x>=MAP_WIDTH || y>=MAP_HEIGHT)return; for(int i=0;i