A WIP Roguelike game by Adekto, VonBednat, Trelemar and Wuuff made for CGAJam in spring 2017
Dependencies: PokittoLib
Fork of Arcade by
mapgen.c@15:67fb7b0c1149, 2018-05-21 (annotated)
- Committer:
- Pokitto
- Date:
- Mon May 21 18:04:18 2018 +0000
- Revision:
- 15:67fb7b0c1149
- Parent:
- 10:590a26231903
Compilation working now. Get music from: https://talk.pokitto.com/t/game-columns-coffins-roguelike-updated/482
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Pokitto | 10:590a26231903 | 1 | #include <stdio.h> |
Pokitto | 10:590a26231903 | 2 | #include <stdlib.h> |
Pokitto | 10:590a26231903 | 3 | |
Pokitto | 10:590a26231903 | 4 | #define MAPSIZE 64 |
Pokitto | 10:590a26231903 | 5 | |
Pokitto | 10:590a26231903 | 6 | #define ID_FLOOR 0 |
Pokitto | 10:590a26231903 | 7 | #define ID_WALL_TOP 1 |
Pokitto | 10:590a26231903 | 8 | #define ID_WALL 2 |
Pokitto | 10:590a26231903 | 9 | #define ID_WALL_SKULL 3 |
Pokitto | 10:590a26231903 | 10 | #define ID_WALL_FLAME 4 |
Pokitto | 10:590a26231903 | 11 | #define ID_WALL_HOLE 5 |
Pokitto | 10:590a26231903 | 12 | #define ID_WALL_SHIELD 6 |
Pokitto | 10:590a26231903 | 13 | #define ID_COLUMN_TOP_SQUARE_1 7 |
Pokitto | 10:590a26231903 | 14 | #define ID_COLUMN_TOP_SQUARE_2 9 |
Pokitto | 10:590a26231903 | 15 | #define ID_COLUMN_TOP_SQUARE_3 10 |
Pokitto | 10:590a26231903 | 16 | #define ID_COLUMN_TOP_ROUND_1 11 |
Pokitto | 10:590a26231903 | 17 | #define ID_COLUMN_TOP_ROUND_2 13 |
Pokitto | 10:590a26231903 | 18 | #define ID_COLUMN_BOTTOM_SQUARE_1 8 |
Pokitto | 10:590a26231903 | 19 | #define ID_COLUMN_BOTTOM_ROUND_1 12 |
Pokitto | 10:590a26231903 | 20 | #define ID_COLUMN_BOTTOM_ROUND_2 14 |
Pokitto | 10:590a26231903 | 21 | #define ID_COFFIN_CLOSED_TOP 15 |
Pokitto | 10:590a26231903 | 22 | #define ID_COFFIN_CLOSED_BOTTOM 16 |
Pokitto | 10:590a26231903 | 23 | #define ID_COFFIN_OPEN_TOP 17 |
Pokitto | 10:590a26231903 | 24 | #define ID_COFFIN_OPEN_BOTTOM 18 |
Pokitto | 10:590a26231903 | 25 | #define ID_COBWEB 33 |
Pokitto | 10:590a26231903 | 26 | |
Pokitto | 10:590a26231903 | 27 | void mapinit(char map[][MAPSIZE], int width, int height); |
Pokitto | 10:590a26231903 | 28 | void mapgen(char map[][MAPSIZE], int mapwidth, int mapheight, int startx, int starty, int endx, int endy); |
Pokitto | 10:590a26231903 | 29 | void mapprint(char map[][MAPSIZE], int width, int height); |
Pokitto | 10:590a26231903 | 30 | |
Pokitto | 10:590a26231903 | 31 | void mapinit(char map[][MAPSIZE], int width, int height){ |
Pokitto | 10:590a26231903 | 32 | int i,j; |
Pokitto | 10:590a26231903 | 33 | |
Pokitto | 10:590a26231903 | 34 | //Fill with empty space |
Pokitto | 10:590a26231903 | 35 | for( i = 0; i < width; i++ ){ |
Pokitto | 10:590a26231903 | 36 | for( j = 0; j < height; j++ ){ |
Pokitto | 10:590a26231903 | 37 | map[j][i] = 0; |
Pokitto | 10:590a26231903 | 38 | } |
Pokitto | 10:590a26231903 | 39 | } |
Pokitto | 10:590a26231903 | 40 | //Generate walls around the edges |
Pokitto | 10:590a26231903 | 41 | for( i = 0; i < width; i++ ){ |
Pokitto | 10:590a26231903 | 42 | map[0][i] = 1; |
Pokitto | 10:590a26231903 | 43 | map[height-1][i] = 1; |
Pokitto | 10:590a26231903 | 44 | } |
Pokitto | 10:590a26231903 | 45 | for( j = 0; j < height; j++ ){ |
Pokitto | 10:590a26231903 | 46 | map[j][0] = 1; |
Pokitto | 10:590a26231903 | 47 | map[j][width-1] = 1; |
Pokitto | 10:590a26231903 | 48 | } |
Pokitto | 10:590a26231903 | 49 | } |
Pokitto | 10:590a26231903 | 50 | |
Pokitto | 10:590a26231903 | 51 | #define HORIZONTAL 0 |
Pokitto | 10:590a26231903 | 52 | #define VERTICAL 1 |
Pokitto | 10:590a26231903 | 53 | #define MIN_WIDTH 6 |
Pokitto | 10:590a26231903 | 54 | #define MIN_HEIGHT 8 |
Pokitto | 10:590a26231903 | 55 | #define HALL_CHANCE 40 |
Pokitto | 10:590a26231903 | 56 | #define MIN_HALL_WIDTH 8 |
Pokitto | 10:590a26231903 | 57 | #define MIN_HALL_HEIGHT 10 |
Pokitto | 10:590a26231903 | 58 | #define MAX_HALL_WIDTH 18 |
Pokitto | 10:590a26231903 | 59 | #define MAX_HALL_HEIGHT 20 |
Pokitto | 10:590a26231903 | 60 | #define EXTRA_DOOR 10 |
Pokitto | 10:590a26231903 | 61 | #define REM_WALL_CHANCE 25 |
Pokitto | 10:590a26231903 | 62 | #define MAX_REM_WALL 10 |
Pokitto | 10:590a26231903 | 63 | void mapgen(char map[][MAPSIZE], int mapwidth, int mapheight, int startx, int starty, int endx, int endy){ |
Pokitto | 10:590a26231903 | 64 | int i,j,orientation,position,door,door2,doorcount,hall,colspacex,colspacey,remwall; |
Pokitto | 10:590a26231903 | 65 | int width = endx-startx; |
Pokitto | 10:590a26231903 | 66 | int height = endy-starty; |
Pokitto | 10:590a26231903 | 67 | |
Pokitto | 10:590a26231903 | 68 | if( width < MIN_WIDTH && height < MIN_HEIGHT ){ |
Pokitto | 10:590a26231903 | 69 | return; |
Pokitto | 10:590a26231903 | 70 | } |
Pokitto | 10:590a26231903 | 71 | |
Pokitto | 10:590a26231903 | 72 | //Determine whether to generate a big hall with pillars or not. |
Pokitto | 10:590a26231903 | 73 | //The size of the room determines the column spacing for now |
Pokitto | 10:590a26231903 | 74 | if( width >= MIN_HALL_WIDTH && height >= MIN_HALL_HEIGHT && width < MAX_HALL_WIDTH && height < MAX_HALL_HEIGHT ){ |
Pokitto | 10:590a26231903 | 75 | hall = rand()%100;//Percent chance out of 100 |
Pokitto | 10:590a26231903 | 76 | if( HALL_CHANCE > hall ){ |
Pokitto | 10:590a26231903 | 77 | hall = rand()%3;//Choose type of hall; square columns, round columns, or coffins |
Pokitto | 10:590a26231903 | 78 | //Place room columns as densely as the room supports |
Pokitto | 10:590a26231903 | 79 | //IF you can divide the room into columns evenly |
Pokitto | 10:590a26231903 | 80 | //but make sure there is greater than one space between columns |
Pokitto | 10:590a26231903 | 81 | colspacex = width; |
Pokitto | 10:590a26231903 | 82 | if( colspacex%2 != 0 ){ |
Pokitto | 10:590a26231903 | 83 | colspacex--; |
Pokitto | 10:590a26231903 | 84 | } |
Pokitto | 10:590a26231903 | 85 | while( colspacex%2 == 0 && colspacex > 4 ) colspacex /= 2; |
Pokitto | 10:590a26231903 | 86 | colspacey = height; |
Pokitto | 10:590a26231903 | 87 | if( colspacey%4 != 0 ) |
Pokitto | 10:590a26231903 | 88 | { |
Pokitto | 10:590a26231903 | 89 | while( colspacey%4 != 0 ) colspacey++; |
Pokitto | 10:590a26231903 | 90 | } |
Pokitto | 10:590a26231903 | 91 | while( colspacey%4 == 0 && colspacey > 4 ) colspacey /= 4; |
Pokitto | 10:590a26231903 | 92 | |
Pokitto | 10:590a26231903 | 93 | for( i = startx+colspacex; i < startx + width - 1; i+=colspacex ){ |
Pokitto | 10:590a26231903 | 94 | for( j = starty+colspacey; j < starty + height - 2; j+=colspacey ){ |
Pokitto | 10:590a26231903 | 95 | if( hall == 0 ){//Square columns |
Pokitto | 10:590a26231903 | 96 | switch( rand()%3 ){ |
Pokitto | 10:590a26231903 | 97 | case 0: |
Pokitto | 10:590a26231903 | 98 | map[j][i] = ID_COLUMN_TOP_SQUARE_1; |
Pokitto | 10:590a26231903 | 99 | break; |
Pokitto | 10:590a26231903 | 100 | case 1: |
Pokitto | 10:590a26231903 | 101 | map[j][i] = ID_COLUMN_TOP_SQUARE_2; |
Pokitto | 10:590a26231903 | 102 | break; |
Pokitto | 10:590a26231903 | 103 | case 2: |
Pokitto | 10:590a26231903 | 104 | map[j][i] = ID_COLUMN_TOP_SQUARE_3; |
Pokitto | 10:590a26231903 | 105 | break; |
Pokitto | 10:590a26231903 | 106 | } |
Pokitto | 10:590a26231903 | 107 | map[j+1][i] = ID_COLUMN_BOTTOM_SQUARE_1; |
Pokitto | 10:590a26231903 | 108 | }else if( hall == 1 ){//Round columns |
Pokitto | 10:590a26231903 | 109 | switch( rand()%2 ){ |
Pokitto | 10:590a26231903 | 110 | case 0: |
Pokitto | 10:590a26231903 | 111 | map[j][i] = ID_COLUMN_TOP_ROUND_1; |
Pokitto | 10:590a26231903 | 112 | break; |
Pokitto | 10:590a26231903 | 113 | case 1: |
Pokitto | 10:590a26231903 | 114 | map[j][i] = ID_COLUMN_TOP_ROUND_2; |
Pokitto | 10:590a26231903 | 115 | break; |
Pokitto | 10:590a26231903 | 116 | } |
Pokitto | 10:590a26231903 | 117 | switch( rand()%2 ){ |
Pokitto | 10:590a26231903 | 118 | case 0: |
Pokitto | 10:590a26231903 | 119 | map[j+1][i] = ID_COLUMN_BOTTOM_ROUND_1; |
Pokitto | 10:590a26231903 | 120 | break; |
Pokitto | 10:590a26231903 | 121 | case 1: |
Pokitto | 10:590a26231903 | 122 | map[j+1][i] = ID_COLUMN_BOTTOM_ROUND_2; |
Pokitto | 10:590a26231903 | 123 | break; |
Pokitto | 10:590a26231903 | 124 | } |
Pokitto | 10:590a26231903 | 125 | }else{//Coffins |
Pokitto | 10:590a26231903 | 126 | switch( rand()%2 ){ |
Pokitto | 10:590a26231903 | 127 | case 0: |
Pokitto | 10:590a26231903 | 128 | map[j][i] = ID_COFFIN_CLOSED_TOP; |
Pokitto | 10:590a26231903 | 129 | map[j+1][i] = ID_COFFIN_CLOSED_BOTTOM; |
Pokitto | 10:590a26231903 | 130 | break; |
Pokitto | 10:590a26231903 | 131 | case 1: |
Pokitto | 10:590a26231903 | 132 | map[j][i] = ID_COFFIN_OPEN_TOP; |
Pokitto | 10:590a26231903 | 133 | map[j+1][i] = ID_COFFIN_OPEN_BOTTOM; |
Pokitto | 10:590a26231903 | 134 | break; |
Pokitto | 10:590a26231903 | 135 | } |
Pokitto | 10:590a26231903 | 136 | } |
Pokitto | 10:590a26231903 | 137 | |
Pokitto | 10:590a26231903 | 138 | } |
Pokitto | 10:590a26231903 | 139 | } |
Pokitto | 10:590a26231903 | 140 | return;//Do not subdivide; return immediately |
Pokitto | 10:590a26231903 | 141 | } |
Pokitto | 10:590a26231903 | 142 | } |
Pokitto | 10:590a26231903 | 143 | |
Pokitto | 10:590a26231903 | 144 | //Determine whether we will split the space |
Pokitto | 10:590a26231903 | 145 | //horizontally or vertically by choosing whichever |
Pokitto | 10:590a26231903 | 146 | //orientation is larger (this avoids extremely long rooms) |
Pokitto | 10:590a26231903 | 147 | if( width >= height ){ |
Pokitto | 10:590a26231903 | 148 | //If there is a door (or more than one door!) into a small room, |
Pokitto | 10:590a26231903 | 149 | //we may not be able to generate a wall in any location! |
Pokitto | 10:590a26231903 | 150 | //so abort if room is min + number of horiz door tiles |
Pokitto | 10:590a26231903 | 151 | doorcount = 0; |
Pokitto | 10:590a26231903 | 152 | for( i = startx; i < endx; i++ ){ |
Pokitto | 10:590a26231903 | 153 | if( map[starty][i] == 0 ) doorcount++; |
Pokitto | 10:590a26231903 | 154 | if( map[endy][i] == 0 ) doorcount++; |
Pokitto | 10:590a26231903 | 155 | } |
Pokitto | 10:590a26231903 | 156 | if( width < MIN_WIDTH + doorcount ){ |
Pokitto | 10:590a26231903 | 157 | return; |
Pokitto | 10:590a26231903 | 158 | } |
Pokitto | 10:590a26231903 | 159 | orientation = VERTICAL; |
Pokitto | 10:590a26231903 | 160 | //puts("Trying vertical"); |
Pokitto | 10:590a26231903 | 161 | }else{ |
Pokitto | 10:590a26231903 | 162 | //If there is a door (or more than one door!) into a small room, |
Pokitto | 10:590a26231903 | 163 | //we may not be able to generate a wall in any location! |
Pokitto | 10:590a26231903 | 164 | //so abort if room is min + number of vert door tiles |
Pokitto | 10:590a26231903 | 165 | doorcount = 0; |
Pokitto | 10:590a26231903 | 166 | for( i = starty; i < endy; i++ ){ |
Pokitto | 10:590a26231903 | 167 | if( map[i][startx] == 0 ) doorcount++; |
Pokitto | 10:590a26231903 | 168 | if( map[i][endx] == 0 ) doorcount++; |
Pokitto | 10:590a26231903 | 169 | } |
Pokitto | 10:590a26231903 | 170 | if( height < MIN_HEIGHT + doorcount ){ |
Pokitto | 10:590a26231903 | 171 | return; |
Pokitto | 10:590a26231903 | 172 | } |
Pokitto | 10:590a26231903 | 173 | orientation = HORIZONTAL; |
Pokitto | 10:590a26231903 | 174 | //puts("Trying horizontal"); |
Pokitto | 10:590a26231903 | 175 | } |
Pokitto | 10:590a26231903 | 176 | //printf("startx %d, starty %d\n",startx,starty); |
Pokitto | 10:590a26231903 | 177 | //mapprint(map,MAPSIZE,MAPSIZE); |
Pokitto | 10:590a26231903 | 178 | position = -1; |
Pokitto | 10:590a26231903 | 179 | if( orientation == HORIZONTAL ){ |
Pokitto | 10:590a26231903 | 180 | //Make sure the position is valid: |
Pokitto | 10:590a26231903 | 181 | //1. It must have generated at least one number |
Pokitto | 10:590a26231903 | 182 | //2. It must not be too close to existing walls |
Pokitto | 10:590a26231903 | 183 | //3. It must not be over a door |
Pokitto | 10:590a26231903 | 184 | while( position == -1 || position < starty + (MIN_HEIGHT/2) || position > endy - (MIN_HEIGHT/2) || map[position][startx] == 0 || map[position][endx] == 0 ){ |
Pokitto | 10:590a26231903 | 185 | position = starty + (rand()%height); |
Pokitto | 10:590a26231903 | 186 | } |
Pokitto | 10:590a26231903 | 187 | //Generate a door at a random position |
Pokitto | 10:590a26231903 | 188 | door = startx + 1 + (rand()%(width-1)); |
Pokitto | 10:590a26231903 | 189 | //Generate an extra door if wall is long enough. |
Pokitto | 10:590a26231903 | 190 | //Doors may overlap or be next to each other because such |
Pokitto | 10:590a26231903 | 191 | //doors shouldn't be a problem and it might result in interesting maps. |
Pokitto | 10:590a26231903 | 192 | //If it is not long enough set to -1 so it won't interfere |
Pokitto | 10:590a26231903 | 193 | door2 = width >= EXTRA_DOOR ? startx + 1 + (rand()%(width-1)) : -1; |
Pokitto | 10:590a26231903 | 194 | //printf("HORIZ %d\n",position); |
Pokitto | 10:590a26231903 | 195 | for( i = startx+1; i < startx + width; i++ ){ |
Pokitto | 10:590a26231903 | 196 | if( i != door && i != door2 ) |
Pokitto | 10:590a26231903 | 197 | map[position][i] = 1; |
Pokitto | 10:590a26231903 | 198 | } |
Pokitto | 10:590a26231903 | 199 | //Determine whether or not we will remove a wall. |
Pokitto | 10:590a26231903 | 200 | //We can't remove bottom and right walls because the regions beyond them |
Pokitto | 10:590a26231903 | 201 | //haven't been generated yet, so we only try to remove top and left walls. |
Pokitto | 10:590a26231903 | 202 | //If we are not on the map edges |
Pokitto | 10:590a26231903 | 203 | if( startx > 0 && endx < mapwidth-1 ){ |
Pokitto | 10:590a26231903 | 204 | //If the new space is taller than it is wide |
Pokitto | 10:590a26231903 | 205 | //and the wall is short enough |
Pokitto | 10:590a26231903 | 206 | if( /*position - starty > width &&*/ position - starty < MAX_REM_WALL ){ |
Pokitto | 10:590a26231903 | 207 | remwall = 1; |
Pokitto | 10:590a26231903 | 208 | //Check if there is no wall touching the wall we want to remove. |
Pokitto | 10:590a26231903 | 209 | //If not, we can remove the wall |
Pokitto | 10:590a26231903 | 210 | for( i = starty+1; i < position; i++ ){ |
Pokitto | 10:590a26231903 | 211 | if( map[i][startx-1] != 0 ){ |
Pokitto | 10:590a26231903 | 212 | remwall = 0; |
Pokitto | 10:590a26231903 | 213 | break; |
Pokitto | 10:590a26231903 | 214 | } |
Pokitto | 10:590a26231903 | 215 | } |
Pokitto | 10:590a26231903 | 216 | if( remwall && REM_WALL_CHANCE > (rand()%100) ){ |
Pokitto | 10:590a26231903 | 217 | for( i = starty+1; i < position; i++ ){ |
Pokitto | 10:590a26231903 | 218 | map[i][startx] = 0;//2;//Clear left side of upper half |
Pokitto | 10:590a26231903 | 219 | } |
Pokitto | 10:590a26231903 | 220 | } |
Pokitto | 10:590a26231903 | 221 | } |
Pokitto | 10:590a26231903 | 222 | //If the new space is taller than it is wide |
Pokitto | 10:590a26231903 | 223 | //and the wall is short enough |
Pokitto | 10:590a26231903 | 224 | if( /*endy - position > width &&*/ endy - position < MAX_REM_WALL ){ |
Pokitto | 10:590a26231903 | 225 | remwall = 1; |
Pokitto | 10:590a26231903 | 226 | //Check if there is no wall touching the wall we want to remove. |
Pokitto | 10:590a26231903 | 227 | //If not, we can remove the wall |
Pokitto | 10:590a26231903 | 228 | for( i = position+1; i < endy; i++ ){ |
Pokitto | 10:590a26231903 | 229 | if( map[i][startx+1] != 0 ){ |
Pokitto | 10:590a26231903 | 230 | remwall = 0; |
Pokitto | 10:590a26231903 | 231 | break; |
Pokitto | 10:590a26231903 | 232 | } |
Pokitto | 10:590a26231903 | 233 | } |
Pokitto | 10:590a26231903 | 234 | if( remwall && REM_WALL_CHANCE > (rand()%100) ){ |
Pokitto | 10:590a26231903 | 235 | for( i = position+1; i < endy; i++ ){ |
Pokitto | 10:590a26231903 | 236 | map[i][startx] = 0;//4;//Clear left side of lower half |
Pokitto | 10:590a26231903 | 237 | } |
Pokitto | 10:590a26231903 | 238 | } |
Pokitto | 10:590a26231903 | 239 | } |
Pokitto | 10:590a26231903 | 240 | } |
Pokitto | 10:590a26231903 | 241 | //Recursively call to fill the two new spaces we generated |
Pokitto | 10:590a26231903 | 242 | mapgen(map, mapwidth, mapheight, startx, starty, endx,position); |
Pokitto | 10:590a26231903 | 243 | mapgen(map, mapwidth, mapheight, startx, position, endx, endy); |
Pokitto | 10:590a26231903 | 244 | }else if( orientation == VERTICAL ){ |
Pokitto | 10:590a26231903 | 245 | //Make sure the position is valid: |
Pokitto | 10:590a26231903 | 246 | //1. It must have generated at least one number |
Pokitto | 10:590a26231903 | 247 | //2. It must not be too close to existing walls |
Pokitto | 10:590a26231903 | 248 | //3. It must not be over a door |
Pokitto | 10:590a26231903 | 249 | while( position == -1 || position < startx + (MIN_WIDTH/2) || position > endx - (MIN_WIDTH/2) || map[starty][position] == 0 || map[endy][position] == 0 ){ |
Pokitto | 10:590a26231903 | 250 | position = startx + (rand()%width); |
Pokitto | 10:590a26231903 | 251 | } |
Pokitto | 10:590a26231903 | 252 | //Generate a door at a random position |
Pokitto | 10:590a26231903 | 253 | //(allocating space for it to be 2 high) |
Pokitto | 10:590a26231903 | 254 | door = starty + 1 + (rand()%(height-2)); |
Pokitto | 10:590a26231903 | 255 | //Generate an extra door if wall is long enough. |
Pokitto | 10:590a26231903 | 256 | //Doors may overlap or be next to each other because such |
Pokitto | 10:590a26231903 | 257 | //doors shouldn't be a problem and it might result in interesting maps. |
Pokitto | 10:590a26231903 | 258 | //If it is not long enough set to -1 so it won't interfere |
Pokitto | 10:590a26231903 | 259 | door2 = height >= EXTRA_DOOR ? starty + 1 + (rand()%(height-2)) : -1; |
Pokitto | 10:590a26231903 | 260 | //printf("VERT %d\n",position); |
Pokitto | 10:590a26231903 | 261 | for( i = starty+1; i < starty + height; i++ ){ |
Pokitto | 10:590a26231903 | 262 | if( i != door && i != door+1 && i != door2 && i != door2+1 ) |
Pokitto | 10:590a26231903 | 263 | map[i][position] = 1; |
Pokitto | 10:590a26231903 | 264 | } |
Pokitto | 10:590a26231903 | 265 | //Determine whether or not we will remove a wall. |
Pokitto | 10:590a26231903 | 266 | //We can't remove bottom and right walls because the regions beyond them |
Pokitto | 10:590a26231903 | 267 | //haven't been generated yet, so we only try to remove top and left walls. |
Pokitto | 10:590a26231903 | 268 | //If we are not on the map edges |
Pokitto | 10:590a26231903 | 269 | if( starty > 0 && endy < mapheight-1 ){ |
Pokitto | 10:590a26231903 | 270 | //If the new space is wider than it is tall |
Pokitto | 10:590a26231903 | 271 | //and the wall is short enough |
Pokitto | 10:590a26231903 | 272 | if( /*position - startx > height &&*/ position - startx < MAX_REM_WALL ){ |
Pokitto | 10:590a26231903 | 273 | remwall = 1; |
Pokitto | 10:590a26231903 | 274 | //Check if there is no wall touching the wall we want to remove. |
Pokitto | 10:590a26231903 | 275 | //If not, we can remove the wall |
Pokitto | 10:590a26231903 | 276 | for( i = startx+1; i < position; i++ ){ |
Pokitto | 10:590a26231903 | 277 | if( map[starty-1][i] != 0 ){ |
Pokitto | 10:590a26231903 | 278 | remwall = 0; |
Pokitto | 10:590a26231903 | 279 | break; |
Pokitto | 10:590a26231903 | 280 | } |
Pokitto | 10:590a26231903 | 281 | } |
Pokitto | 10:590a26231903 | 282 | if( remwall && REM_WALL_CHANCE > (rand()%100) ){ |
Pokitto | 10:590a26231903 | 283 | for( i = startx+1; i < position; i++ ){ |
Pokitto | 10:590a26231903 | 284 | map[starty][i] = 0;//3;//Clear top side of left half |
Pokitto | 10:590a26231903 | 285 | } |
Pokitto | 10:590a26231903 | 286 | } |
Pokitto | 10:590a26231903 | 287 | } |
Pokitto | 10:590a26231903 | 288 | //If the new space is wider than it is tall |
Pokitto | 10:590a26231903 | 289 | //and the wall is short enough |
Pokitto | 10:590a26231903 | 290 | if( /*endx - position > height &&*/ endx - position < MAX_REM_WALL ){ |
Pokitto | 10:590a26231903 | 291 | remwall = 1; |
Pokitto | 10:590a26231903 | 292 | //Check if there is no wall touching the wall we want to remove. |
Pokitto | 10:590a26231903 | 293 | //If not, we can remove the wall |
Pokitto | 10:590a26231903 | 294 | for( i = position+1; i < endx; i++ ){ |
Pokitto | 10:590a26231903 | 295 | if( map[starty-1][i] != 0 ){ |
Pokitto | 10:590a26231903 | 296 | remwall = 0; |
Pokitto | 10:590a26231903 | 297 | break; |
Pokitto | 10:590a26231903 | 298 | } |
Pokitto | 10:590a26231903 | 299 | } |
Pokitto | 10:590a26231903 | 300 | if( remwall && REM_WALL_CHANCE > (rand()%100) ){ |
Pokitto | 10:590a26231903 | 301 | for( i = position+1; i < endx; i++ ){ |
Pokitto | 10:590a26231903 | 302 | map[starty][i] = 0;//5;//Clear top side of right half |
Pokitto | 10:590a26231903 | 303 | } |
Pokitto | 10:590a26231903 | 304 | } |
Pokitto | 10:590a26231903 | 305 | } |
Pokitto | 10:590a26231903 | 306 | } |
Pokitto | 10:590a26231903 | 307 | //Recursively call to fill the two new spaces we generated |
Pokitto | 10:590a26231903 | 308 | mapgen(map, mapwidth, mapheight, startx, starty, position,endy); |
Pokitto | 10:590a26231903 | 309 | mapgen(map, mapwidth, mapheight, position, starty, endx, endy); |
Pokitto | 10:590a26231903 | 310 | } |
Pokitto | 10:590a26231903 | 311 | } |
Pokitto | 10:590a26231903 | 312 | |
Pokitto | 10:590a26231903 | 313 | void mapprint(char map[][MAPSIZE], int width, int height){ |
Pokitto | 10:590a26231903 | 314 | int i,j; |
Pokitto | 10:590a26231903 | 315 | |
Pokitto | 10:590a26231903 | 316 | for( i = 0; i < height; i++ ){ |
Pokitto | 10:590a26231903 | 317 | for( j = 0; j < width; j++ ){ |
Pokitto | 10:590a26231903 | 318 | if( map[i][j] == 0 ){ |
Pokitto | 10:590a26231903 | 319 | printf("0"); |
Pokitto | 10:590a26231903 | 320 | }else if( map[i][j] == 1 ){ |
Pokitto | 10:590a26231903 | 321 | printf("1"); |
Pokitto | 10:590a26231903 | 322 | } |
Pokitto | 10:590a26231903 | 323 | } |
Pokitto | 10:590a26231903 | 324 | puts(""); |
Pokitto | 10:590a26231903 | 325 | } |
Pokitto | 10:590a26231903 | 326 | } |
Pokitto | 10:590a26231903 | 327 | |
Pokitto | 10:590a26231903 | 328 | void mappretty(char map[][MAPSIZE],int width, int height){ |
Pokitto | 10:590a26231903 | 329 | int i,j,v; |
Pokitto | 10:590a26231903 | 330 | for (i=0; i < height-1; i++) { |
Pokitto | 10:590a26231903 | 331 | for (j=0;j<width-1;j++){ |
Pokitto | 10:590a26231903 | 332 | if (map[i][j]==1 && map[i+1][j]==0){ |
Pokitto | 10:590a26231903 | 333 | v = rand()%25 + 3; |
Pokitto | 10:590a26231903 | 334 | //If v is any of the random wall variations |
Pokitto | 10:590a26231903 | 335 | if( v <= ID_WALL_SHIELD ){ |
Pokitto | 10:590a26231903 | 336 | map[i+1][j] = v; |
Pokitto | 10:590a26231903 | 337 | }else { |
Pokitto | 10:590a26231903 | 338 | map[i+1][j]=ID_WALL; |
Pokitto | 10:590a26231903 | 339 | } |
Pokitto | 10:590a26231903 | 340 | } |
Pokitto | 10:590a26231903 | 341 | |
Pokitto | 10:590a26231903 | 342 | if (map[i][j]==0 && map[i+1][j]==1 && map[i][j-1]==1 && rand()%10 <=1) { |
Pokitto | 10:590a26231903 | 343 | map[i][j]=ID_COBWEB; |
Pokitto | 10:590a26231903 | 344 | } |
Pokitto | 10:590a26231903 | 345 | } |
Pokitto | 10:590a26231903 | 346 | } |
Pokitto | 10:590a26231903 | 347 | } |
Pokitto | 10:590a26231903 | 348 | |
Pokitto | 10:590a26231903 | 349 | |
Pokitto | 10:590a26231903 | 350 | //char map[MAPSIZE][MAPSIZE]; |
Pokitto | 10:590a26231903 | 351 | |
Pokitto | 10:590a26231903 | 352 | /* |
Pokitto | 10:590a26231903 | 353 | int main(int argc, char** argv){ |
Pokitto | 10:590a26231903 | 354 | srand(42);//Can choose the seed to get the same map every time |
Pokitto | 10:590a26231903 | 355 | |
Pokitto | 10:590a26231903 | 356 | mapinit(map,MAPSIZE,MAPSIZE); |
Pokitto | 10:590a26231903 | 357 | mapgen(map,MAPSIZE,MAPSIZE,0,0,MAPSIZE-1,MAPSIZE-1); |
Pokitto | 10:590a26231903 | 358 | |
Pokitto | 10:590a26231903 | 359 | mapprint(map,MAPSIZE,MAPSIZE); |
Pokitto | 10:590a26231903 | 360 | } |
Pokitto | 10:590a26231903 | 361 | */ |
Pokitto | 10:590a26231903 | 362 | |
Pokitto | 10:590a26231903 | 363 | |
Pokitto | 15:67fb7b0c1149 | 364 |