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.c20
-rw-r--r--height-map-display/src/map/node.h13
-rw-r--r--height-map-display/src/map/square.c21
-rw-r--r--height-map-display/src/map/square.h24
4 files changed, 78 insertions, 0 deletions
diff --git a/height-map-display/src/map/node.c b/height-map-display/src/map/node.c
new file mode 100644
index 0000000..eaf2877
--- /dev/null
+++ b/height-map-display/src/map/node.c
@@ -0,0 +1,20 @@
+#include "node.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <malloc.h>
+
+Node* create_node(int x, int y, float elevation) {
+ Node* node = (Node*)malloc(sizeof(Node));
+ if (node != NULL) {
+ node->x = x;
+ node->y = y;
+ node->elevation = elevation;
+ }
+ return node;
+}
+
+void change_node_height(Node* node, float diff) {
+ if (node != NULL) { node->elevation = node->elevation + diff; }
+}
+
diff --git a/height-map-display/src/map/node.h b/height-map-display/src/map/node.h
new file mode 100644
index 0000000..d12accf
--- /dev/null
+++ b/height-map-display/src/map/node.h
@@ -0,0 +1,13 @@
+#ifndef NODE_H
+#define NODE_H
+
+typedef struct Node {
+ int x;
+ int y;
+ float elevation;
+} Node;
+
+void change_node_height(Node* node, float diff);
+
+#endif
+
diff --git a/height-map-display/src/map/square.c b/height-map-display/src/map/square.c
new file mode 100644
index 0000000..707f8b7
--- /dev/null
+++ b/height-map-display/src/map/square.c
@@ -0,0 +1,21 @@
+#include "square.h"
+#include "node.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <malloc.h>
+
+Square* init_square(Node *nodes[4], Terrain_Type terrain) {
+ Square* square;
+ for (int i; i < 4; i++) {
+ square->nodes[i] = nodes[i];
+ }
+ square->terrain = terrain;
+ return square;
+}
+
+void change_square_height(Square* square, float diff) {
+ for (int i; i < 4; i++) {
+ square->nodes[i]->elevation = square->nodes[i]->elevation + diff;
+ }
+}
diff --git a/height-map-display/src/map/square.h b/height-map-display/src/map/square.h
new file mode 100644
index 0000000..d40e7d1
--- /dev/null
+++ b/height-map-display/src/map/square.h
@@ -0,0 +1,24 @@
+#ifndef SQUARE_H
+#define SQUARE_H
+
+#include "node.h" // Include node.h to use Node type.
+
+// Define the Terrain_Type enum
+typedef enum {
+ TERRAIN_FAIRWAY,
+ TERRAIN_ROUGH,
+ TERRAIN_GREEN,
+} Terrain_Type;
+
+// Define the Square struct
+typedef struct Square {
+ Terrain_Type terrain;
+ Node *nodes[4]; // Array of Node pointers
+} Square;
+
+// Function prototypes
+Square* init_square(Node *nodes[4], Terrain_Type terrain);
+void change_square_height(Square* square, float diff);
+
+#endif
+