2023-11-23 18:58:37 +00:00
|
|
|
#include <SDL2/SDL.h>
|
|
|
|
#include "defs.h"
|
|
|
|
#include "structs.h"
|
|
|
|
#include "format.h"
|
|
|
|
|
|
|
|
extern SDL_Texture *grass_texture;
|
|
|
|
extern SDL_Texture *cobble_texture;
|
|
|
|
extern SDL_Texture *lava_texture;
|
|
|
|
extern struct object *create_object(SDL_Texture *texture, int scale, int resolution);
|
|
|
|
|
|
|
|
int handle_block_creation(int id, int type, struct object ***map, int *slots) {
|
|
|
|
(*slots)++;
|
|
|
|
*map = realloc(*map, sizeof(struct object *)*(*slots));
|
|
|
|
if (*map == NULL)
|
|
|
|
return MEMERR;
|
|
|
|
|
|
|
|
SDL_Texture *texture;
|
|
|
|
switch (type) {
|
2023-11-23 22:12:31 +00:00
|
|
|
case GRASS_BLOCK:
|
2023-11-23 18:58:37 +00:00
|
|
|
texture = grass_texture;
|
|
|
|
break;
|
2023-11-23 22:12:31 +00:00
|
|
|
case COBBLE_BLOCK:
|
2023-11-23 18:58:37 +00:00
|
|
|
texture = cobble_texture;
|
|
|
|
break;
|
2023-11-23 22:12:31 +00:00
|
|
|
case LAVA_BLOCK:
|
2023-11-23 18:58:37 +00:00
|
|
|
texture = lava_texture;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
texture = grass_texture;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct object *new_block = create_object(texture, 1, 32);
|
|
|
|
if (new_block == NULL)
|
|
|
|
return MEMERR;
|
|
|
|
|
|
|
|
(*map)[id] = new_block;
|
|
|
|
|
|
|
|
return STDOK;
|
|
|
|
}
|