]> git.lizzy.rs Git - shadowclad.git/blob - level.c
Only render axis indicator on the positive side of that axis
[shadowclad.git] / level.c
1 #include <GL/gl.h>
2 #include <stdlib.h>
3
4 #include "level.h"
5 #include "tga.h"
6
7 const GLuint BLOCK_EMPTY = 0x000000FF;
8 const GLuint BLOCK_WALL01 = 0xFF0000FF;
9
10 TGAimage* level_image = NULL;
11
12 Block** blocks;
13 const int block_count = 1;
14
15 void init_blocks() {
16         blocks = realloc(blocks, sizeof(Block*) * block_count);
17         
18         Lib3dsFile* model_file;
19         
20         model_file = lib3ds_file_load("assets/wall01.3ds");
21         Block* wall01block = malloc(sizeof(Block));
22         (*wall01block).type = BLOCK_WALL01;
23         (*wall01block).mesh = (*model_file).meshes[0];
24         (*wall01block).materials = (*model_file).materials;
25         (*wall01block).material_count = (*model_file).nmaterials;
26         (*wall01block).obstacle = 1;
27         
28         blocks[0] = wall01block;
29 }
30
31 Block* get_block_at(GLushort x, GLushort y) {
32         if (level_image == NULL) {
33                 return NULL;
34         }
35         GLuint block_type = ((GLuint*) (*level_image).bytes)[x * (*level_image).header.image_width + y];
36         Block* result = NULL;
37         for (int i = 0; i < block_count; ++i) {
38                 if ((*blocks[i]).type == block_type) {
39                         result = blocks[i];
40                 }
41         }
42         return result;
43 }
44
45 void set_level_image(TGAimage* image) {
46         level_image = image;
47 }