summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorilotterytea <iltsu@alright.party>2025-01-13 15:20:37 +0500
committerilotterytea <iltsu@alright.party>2025-01-13 15:20:37 +0500
commitd5cc4f654fc50502c9e4f9ebbe310b9158d5b0a4 (patch)
tree2b09459978721db5484c6e14dbbdb6f1ad9ccdeb /src
parent0a87b324c3bec9d7304e183072e1b5e42c4dc144 (diff)
feat: level struct and basic functions for initialization (wip)
Diffstat (limited to 'src')
-rw-r--r--src/level.c51
-rw-r--r--src/level.h9
-rw-r--r--src/main.c10
3 files changed, 69 insertions, 1 deletions
diff --git a/src/level.c b/src/level.c
new file mode 100644
index 0000000..fbe6260
--- /dev/null
+++ b/src/level.c
@@ -0,0 +1,51 @@
+#include "level.h"
+
+#include <stdlib.h>
+
+#include "raylib.h"
+
+Level *SE_CreateLevel(int width, int height) {
+ Level *level = malloc(sizeof(Level) + sizeof(Vector3) * width * height);
+
+ int i = 0;
+
+ for (int x = 0; x < width; x++) {
+ for (int y = 0; y < height; y++) {
+ Vector3 *v = malloc(sizeof(Vector3));
+ v->x = x * 10;
+ v->y = y * 10;
+ v->z = 0;
+ level->vectors[i] = v;
+ i++;
+ }
+ }
+
+ level->width = width;
+ level->height = height;
+
+ return level;
+}
+
+void SE_RenderLevel(Level *level) {
+ int cell_size = 10;
+
+ for (int x = 0; x < level->width; x++) {
+ for (int y = 0; y < level->height; y++) {
+ DrawRectangleLines(cell_size * x, cell_size * y, cell_size, cell_size,
+ LIGHTGRAY);
+ }
+ }
+
+ for (int i = 0; i < level->width * level->height; i++) {
+ Vector3 *vector = level->vectors[i];
+ DrawRectangle(vector->x, vector->y, 2, 2, BLACK);
+ }
+}
+
+void SE_FreeLevel(Level *level) {
+ for (int i = 0; i < level->width * level->height; i++) {
+ Vector3 *v = level->vectors[i];
+ free(v);
+ }
+ free(level);
+}
diff --git a/src/level.h b/src/level.h
new file mode 100644
index 0000000..fe8f62f
--- /dev/null
+++ b/src/level.h
@@ -0,0 +1,9 @@
+#include "raylib.h"
+typedef struct {
+ int width, height;
+ Vector3 *vectors[];
+} Level;
+
+Level *SE_CreateLevel(int width, int height);
+void SE_RenderLevel(Level *level);
+void SE_FreeLevel(Level *level);
diff --git a/src/main.c b/src/main.c
index 0f659cb..10e98f0 100644
--- a/src/main.c
+++ b/src/main.c
@@ -1,3 +1,4 @@
+#include "level.h"
#include "raylib.h"
int main() {
@@ -5,13 +6,20 @@ int main() {
InitWindow(800, 600, "sillyeditor");
SetTargetFPS(60);
+ Level *level = SE_CreateLevel(30, 30);
+
while (!WindowShouldClose()) {
BeginDrawing();
ClearBackground(RAYWHITE);
DrawText("hi world!", GetScreenWidth() / 2 - 16 * 4,
GetScreenHeight() / 2 - 16, 32, BLACK);
+
+ SE_RenderLevel(level);
+
EndDrawing();
}
+ SE_FreeLevel(level);
+
return 0;
-} \ No newline at end of file
+}