1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
#include "square.h"
#include "node.h"
#include <stdio.h>
#include <stdlib.h>
#include <malloc.h>
#include <stdbool.h>
Square* init_square(Node *tl, Node *tr, Node *bl, Node *br, Terrain_Type terrain, bool selected) {
Square* square;
square->node_tl = tl;
square->node_tr = tr;
square->node_bl = bl;
square->node_br = br;
square->terrain = terrain;
square->selected = selected;
return square;
}
void change_square_height(Square* square, float diff) {
square->node_tl->elevation = square->node_tl->elevation + diff;
square->node_tr->elevation = square->node_tr->elevation + diff;
square->node_bl->elevation = square->node_bl->elevation + diff;
square->node_br->elevation = square->node_br->elevation + diff;
}
void change_square_terrain(Square* square, Terrain_Type terrain) {
square->terrain = terrain;
}
// TODO: Probably a better way of storing selected square tbh
Square* find_selected_square(Square*** squares, int x, int y) {
for (int i = 0; i < x - 1; i++) {
for (int i = 0; i < x - 1; i++) {
if (squares[x][y]->selected) {
return squares[x][y];
}
}
}
return NULL;
}
float* get_terrain_color(Terrain_Type terrain) {
static float colors[6][3] = {
{0.0f, 0.0f, 0.0f}, // init
{0.0f, 0.5f, 0.0f}, // rough
{0.2f, 0.7f, 0.2f}, // fairway
{0.3f, 0.8f, 0.3f}, // green
{0.1f, 0.2f, 0.8f}, // water
{0.9f, 0.7f, 0.7f}, // sand
};
return colors[terrain];
}
|