04: update map generation probabilities

This commit is contained in:
0xdeadbeer 2023-11-23 23:12:31 +01:00
parent f0f6a723b3
commit ce0f93a572
6 changed files with 57 additions and 16 deletions

View File

@ -32,8 +32,8 @@
#define CROUCH_MOVEMENT 0b00010000 #define CROUCH_MOVEMENT 0b00010000
// BS: Block Standard // BS: Block Standard
#define GRASS_BLOCK 0b10000000 #define GRASS_BLOCK 0
#define COBBLE_BLOCK 0b01000000 #define COBBLE_BLOCK 1
#define LAVA_BLOCK 0b00100000 #define LAVA_BLOCK 2
#endif #endif

View File

@ -16,13 +16,13 @@ int handle_block_creation(int id, int type, struct object ***map, int *slots) {
SDL_Texture *texture; SDL_Texture *texture;
switch (type) { switch (type) {
case 0: case GRASS_BLOCK:
texture = grass_texture; texture = grass_texture;
break; break;
case 1: case COBBLE_BLOCK:
texture = cobble_texture; texture = cobble_texture;
break; break;
case 2: case LAVA_BLOCK:
texture = lava_texture; texture = lava_texture;
break; break;
default: default:

View File

@ -9,8 +9,8 @@
#include "defs.h" #include "defs.h"
#define DEBUG 1 #define DEBUG 1
#define MAP_WIDTH 100 #define MAP_WIDTH 25
#define MAP_HEIGHT 100 #define MAP_HEIGHT 25
int original_width = 1000; int original_width = 1000;
int original_height = 480; int original_height = 480;

View File

@ -29,8 +29,8 @@
#define MOVEMENT_SPEED 10 #define MOVEMENT_SPEED 10
// BS: Block Standard // BS: Block Standard
#define GRASS_BLOCK 1 #define GRASS_BLOCK 0
#define COBBLE_BLOCK 2 #define COBBLE_BLOCK 1
#define LAVA_BLOCK 3 #define LAVA_BLOCK 2
#endif #endif

View File

@ -11,8 +11,8 @@
#define DEBUG 0x0010 #define DEBUG 0x0010
#define PORT 9080 #define PORT 9080
#define MAP_WIDTH 100 #define MAP_WIDTH 25
#define MAP_HEIGHT 100 #define MAP_HEIGHT 25
struct connection **connections_map; struct connection **connections_map;
int connections_map_size = 0; int connections_map_size = 0;

View File

@ -1,6 +1,11 @@
#include <stdlib.h> #include <stdlib.h>
#include "defs.h"
#include "structs.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 *generate_map(int width, int height) {
struct map *new_map = (struct map *) calloc(1, sizeof(struct map)); struct map *new_map = (struct map *) calloc(1, sizeof(struct map));
if (new_map == NULL) 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 y = 0; y < height; y++) {
for (int x = 0; x < width; x++) { for (int x = 0; x < width; x++) {
double scale = ((double) rand() / RAND_MAX);
int block = scale * 3;
int index = (y*width)+x; 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
} }
} }