diff --git a/04-map/client/src/defs.h b/04-map/client/src/defs.h index 4b92daf..8723634 100644 --- a/04-map/client/src/defs.h +++ b/04-map/client/src/defs.h @@ -32,8 +32,8 @@ #define CROUCH_MOVEMENT 0b00010000 // BS: Block Standard -#define GRASS_BLOCK 0b10000000 -#define COBBLE_BLOCK 0b01000000 -#define LAVA_BLOCK 0b00100000 +#define GRASS_BLOCK 0 +#define COBBLE_BLOCK 1 +#define LAVA_BLOCK 2 #endif diff --git a/04-map/client/src/format.c b/04-map/client/src/format.c index bf250e7..c921936 100644 --- a/04-map/client/src/format.c +++ b/04-map/client/src/format.c @@ -16,13 +16,13 @@ int handle_block_creation(int id, int type, struct object ***map, int *slots) { SDL_Texture *texture; switch (type) { - case 0: + case GRASS_BLOCK: texture = grass_texture; break; - case 1: + case COBBLE_BLOCK: texture = cobble_texture; break; - case 2: + case LAVA_BLOCK: texture = lava_texture; break; default: diff --git a/04-map/client/src/main.c b/04-map/client/src/main.c index 0aeeedd..b79c1ee 100644 --- a/04-map/client/src/main.c +++ b/04-map/client/src/main.c @@ -9,8 +9,8 @@ #include "defs.h" #define DEBUG 1 -#define MAP_WIDTH 100 -#define MAP_HEIGHT 100 +#define MAP_WIDTH 25 +#define MAP_HEIGHT 25 int original_width = 1000; int original_height = 480; diff --git a/04-map/server/src/defs.h b/04-map/server/src/defs.h index fedd149..53a5d5c 100644 --- a/04-map/server/src/defs.h +++ b/04-map/server/src/defs.h @@ -29,8 +29,8 @@ #define MOVEMENT_SPEED 10 // BS: Block Standard -#define GRASS_BLOCK 1 -#define COBBLE_BLOCK 2 -#define LAVA_BLOCK 3 +#define GRASS_BLOCK 0 +#define COBBLE_BLOCK 1 +#define LAVA_BLOCK 2 #endif diff --git a/04-map/server/src/main.c b/04-map/server/src/main.c index c6af2f2..513bddb 100644 --- a/04-map/server/src/main.c +++ b/04-map/server/src/main.c @@ -11,8 +11,8 @@ #define DEBUG 0x0010 #define PORT 9080 -#define MAP_WIDTH 100 -#define MAP_HEIGHT 100 +#define MAP_WIDTH 25 +#define MAP_HEIGHT 25 struct connection **connections_map; int connections_map_size = 0; diff --git a/04-map/server/src/map.c b/04-map/server/src/map.c index b5911e7..db6359f 100644 --- a/04-map/server/src/map.c +++ b/04-map/server/src/map.c @@ -1,6 +1,11 @@ #include +#include "defs.h" #include "structs.h" +const int grass_probability = 6; +const int cobble_probability = 8; +const int lava_probability = 10; + struct map *generate_map(int width, int height) { struct map *new_map = (struct map *) calloc(1, sizeof(struct map)); if (new_map == NULL) @@ -16,10 +21,46 @@ struct map *generate_map(int width, int height) { for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { - double scale = ((double) rand() / RAND_MAX); - int block = scale * 3; int index = (y*width)+x; - map_blocks[index] = block; + + if (x == 0) { + map_blocks[index] = COBBLE_BLOCK; + continue; + } + + if (y == 0) { + map_blocks[index] = COBBLE_BLOCK; + continue; + } + + if (x == width-1) { + map_blocks[index] = COBBLE_BLOCK; + continue; + } + + if (y == height-1) { + map_blocks[index] = COBBLE_BLOCK; + continue; + } + + int scale = rand() % 10; + + if (scale <= grass_probability) { + map_blocks[index] = GRASS_BLOCK; + continue; + } + + if (scale <= cobble_probability) { + map_blocks[index] = COBBLE_BLOCK; + continue; + } + + if (scale <= lava_probability) { + map_blocks[index] = LAVA_BLOCK; + continue; + } + + map_blocks[index] = GRASS_BLOCK; // paranoid developer } }