summaryrefslogtreecommitdiff
path: root/height-map-display/src/map
diff options
context:
space:
mode:
Diffstat (limited to 'height-map-display/src/map')
-rw-r--r--height-map-display/src/map/node.c8
-rw-r--r--height-map-display/src/map/node.h4
-rw-r--r--height-map-display/src/map/square.c17
-rw-r--r--height-map-display/src/map/square.h6
4 files changed, 33 insertions, 2 deletions
diff --git a/height-map-display/src/map/node.c b/height-map-display/src/map/node.c
index eaf2877..33d568d 100644
--- a/height-map-display/src/map/node.c
+++ b/height-map-display/src/map/node.c
@@ -18,3 +18,11 @@ void change_node_height(Node* node, float diff) {
if (node != NULL) { node->elevation = node->elevation + diff; }
}
+int* get_coords(Node* node) {
+ int *coordinate = malloc(2 * sizeof(int));
+ if (coordinate != NULL) {
+ coordinate[0] = node->x;
+ coordinate[1] = node->y;
+ }
+ return coordinate;
+}
diff --git a/height-map-display/src/map/node.h b/height-map-display/src/map/node.h
index 07054f6..03fb97c 100644
--- a/height-map-display/src/map/node.h
+++ b/height-map-display/src/map/node.h
@@ -1,14 +1,18 @@
#ifndef NODE_H
#define NODE_H
+#include <stdbool.h>
+
typedef struct Node {
int x;
int y;
float elevation;
+ bool selected;
} Node;
// TODO: get (x, y) as int arr
void change_node_height(Node* node, float diff);
+int* get_coords(Node* node);
#endif
diff --git a/height-map-display/src/map/square.c b/height-map-display/src/map/square.c
index f963fa3..54add55 100644
--- a/height-map-display/src/map/square.c
+++ b/height-map-display/src/map/square.c
@@ -4,14 +4,16 @@
#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) {
+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;
}
@@ -25,3 +27,16 @@ void change_square_height(Square* square, float 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;
+}
diff --git a/height-map-display/src/map/square.h b/height-map-display/src/map/square.h
index 2654eb5..132b43c 100644
--- a/height-map-display/src/map/square.h
+++ b/height-map-display/src/map/square.h
@@ -1,6 +1,8 @@
#ifndef SQUARE_H
#define SQUARE_H
+#include <stdbool.h>
+
#include "node.h" // Include node.h to use Node type.
// Define the Terrain_Type enum
@@ -17,12 +19,14 @@ typedef struct Square {
Node *node_tr;
Node *node_bl;
Node *node_br;
+ bool selected;
} Square;
// Function prototypes
-Square* init_square(Node *tl, Node *tr, Node *bl, Node *br, Terrain_Type terrain);
+Square* init_square(Node *tl, Node *tr, Node *bl, Node *br, Terrain_Type terrain, bool selected);
void change_square_height(Square* square, float diff);
void change_square_terrain(Square* square, Terrain_Type terrain);
+Square* find_selected_square(Square*** squares, int x, int y);
#endif