commit 081a52fa37da59878a88a792af9fba4eac8df5cf
Author: thing1 <thing1@seacrossedlovers.xyz>
Date: Tue, 18 Nov 2025 19:35:04 +0000
init commit
Diffstat:
| A | main | | | 0 | |
| A | main.c | | | 91 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
| A | run.sh | | | 7 | +++++++ |
3 files changed, 98 insertions(+), 0 deletions(-)
diff --git a/main b/main
Binary files differ.
diff --git a/main.c b/main.c
@@ -0,0 +1,91 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <fcntl.h>
+
+#define MAPW 30
+#define MAPH 30
+
+struct vec2 {
+ int x, y;
+};
+
+char map[MAPH][MAPW] = {0};
+char scr[MAPH][MAPW] = {0};
+
+void
+drawbox(struct vec2 pos, struct vec2 size) {
+ for (int y = pos.y; y < size.y + pos.y; y++) {
+ for (int x = pos.x; x < size.x + pos.x; x++) {
+
+ if (y == pos.y && x == pos.x)
+ map[y][x] = '/';
+
+ else if (y == pos.y && x == pos.x + size.x - 1)
+ map[y][x] = '\\';
+
+ else if (y == pos.y + size.y - 1 && x == pos.x)
+ map[y][x] = '\\';
+
+ else if (y == pos.y + size.y - 1 && x == pos.x + size.x -1)
+ map[y][x] = '/';
+
+ else if (y == pos.y + size.y - 1 || y == pos.y)
+ map[y][x] = '-';
+
+ else if (x == pos.x + size.x - 1 || x == pos.x)
+ map[y][x] = '|';
+ }
+ }
+}
+
+void
+printscr() {
+ for (int y = 0; y < MAPH; y++) {
+ for (int x = 0; x < MAPW; x++) {
+ printf("%c", scr[y][x]);
+ }
+ printf("\n\r");
+ }
+}
+
+int
+main() {
+ struct vec2 player = {10, 10};
+
+ fcntl(0, F_SETFL, O_NONBLOCK);
+
+ memset(map, ' ', MAPH * MAPW);
+ struct vec2 pos = {5,5};
+ struct vec2 size = {5,5};
+ drawbox(pos, size);
+
+ char in;
+
+ for (;;) {
+ memcpy(scr, map, MAPH * MAPW);
+ scr[player.y][player.x] = '@';
+
+ read(0, &in, 1);
+ switch (in) {
+ case 'w':
+ player.y--;
+ break;
+ case 's':
+ player.y++;
+ break;
+ case 'a':
+ player.x--;
+ break;
+ case 'd':
+ player.x++;
+ break;
+ }
+ in = 0;
+
+ printf("\033c");
+ printscr();
+ usleep(32000);
+ }
+}
diff --git a/run.sh b/run.sh
@@ -0,0 +1,7 @@
+#!/bin/sh
+
+old=$(stty -g)
+stty -echo raw
+./main
+
+stty "$old"