eco2d/code/game/source/world/blocks.c

68 lines
1.3 KiB
C
Raw Normal View History

2021-05-12 15:50:30 +00:00
#define ZPL_PICO
2021-05-04 17:41:30 +00:00
#include "zpl.h"
2021-05-12 16:28:39 +00:00
#include "world/world.h"
2021-05-04 17:41:30 +00:00
#include "world/blocks.h"
2021-05-12 15:50:30 +00:00
#include "raylib.h"
2021-05-04 17:41:30 +00:00
#define BLOCKS_COUNT (sizeof(blocks)/sizeof(block))
typedef struct {
char *name;
uint32_t flags;
uint32_t kind;
uint32_t biome;
char symbol;
2021-05-12 15:50:30 +00:00
// NOTE(zaklaus): viewer data
Image img;
2021-05-04 17:41:30 +00:00
} block;
#include "blocks_list.c"
2021-05-12 16:28:39 +00:00
int32_t blocks_setup(void) {
for (uint32_t i=0; i<BLOCKS_COUNT; i++) {
block *b = &blocks[i];
// TODO(zaklaus): introduce texgen
b->img = GenImageColor(WORLD_BLOCK_SIZE, WORLD_BLOCK_SIZE, RAYWHITE);
2021-05-12 16:28:39 +00:00
}
return 0;
}
void blocks_destroy(void) {
for (uint32_t i=0; i<BLOCKS_COUNT; i++) {
UnloadImage(blocks[i].img);
2021-05-12 16:28:39 +00:00
}
}
2021-05-04 17:41:30 +00:00
uint8_t blocks_find(uint32_t biome, uint32_t kind) {
2021-05-12 15:50:30 +00:00
for (uint32_t i=0; i<BLOCKS_COUNT; i++) {
2021-05-04 17:41:30 +00:00
if (blocks[i].biome == biome && blocks[i].kind == kind)
return i;
}
return BLOCK_INVALID;
}
char *blocks_get_name(uint8_t id) {
return blocks[id].name;
}
char blocks_get_symbol(uint8_t id) {
return blocks[id].symbol;
}
uint32_t blocks_get_flags(uint8_t id) {
return blocks[id].flags;
}
uint32_t blocks_get_biome(uint8_t id) {
return blocks[id].biome;
}
uint32_t blocks_get_kind(uint8_t id) {
return blocks[id].kind;
}
2021-05-12 16:28:39 +00:00
void *blocks_get_img(uint8_t id) {
return (void*)&blocks[id].img;
2021-05-12 16:28:39 +00:00
}