From 1db758543fafa8e31956a765d64b28b413913b03 Mon Sep 17 00:00:00 2001 From: N0VA Date: Tue, 24 Feb 2026 15:52:07 +0100 Subject: [PATCH] Add player and game loop --- RULESET.md | 8 ++++++++ iris_c/Makefile | 4 ++-- iris_c/main.c | 22 +++++++++++++++++++++- iris_c/player.c | 12 ++++++++++++ iris_c/player.h | 14 ++++++++++++++ 5 files changed, 57 insertions(+), 3 deletions(-) create mode 100644 iris_c/player.c create mode 100644 iris_c/player.h diff --git a/RULESET.md b/RULESET.md index 18b0c87..31c383a 100644 --- a/RULESET.md +++ b/RULESET.md @@ -34,3 +34,11 @@ ### Wormholes - When entering a black hole, the player is teleported to a random white hole. If there are no white holes, the player is teleported to a random quadrant. + +## Game Loop + +- Every turn one player action is read and applied + +## Player + +- At startup, the player is created at the world centre (`WORLD_WIDTH / 2`, `WORLD_HEIGHT / 2`). diff --git a/iris_c/Makefile b/iris_c/Makefile index 6eb7cce..f0a22f1 100644 --- a/iris_c/Makefile +++ b/iris_c/Makefile @@ -6,8 +6,8 @@ TARGET = main all: $(TARGET) -$(TARGET): main.c random.c random.h world.c world.h prettynames.c prettynames.h - $(CC) $(CFLAGS) -o $@ main.c random.c world.c prettynames.c +$(TARGET): main.c player.c player.h random.c random.h world.c world.h prettynames.c prettynames.h + $(CC) $(CFLAGS) -o $@ main.c player.c random.c world.c prettynames.c clean: rm -f $(TARGET) diff --git a/iris_c/main.c b/iris_c/main.c index 39a6d2e..631b16b 100644 --- a/iris_c/main.c +++ b/iris_c/main.c @@ -1,14 +1,23 @@ #include #include +#include #include "prettynames.h" +#include "player.h" #include "random.h" #include "world.h" int main() { uint32_t seed; printf("Enter seed: "); - scanf("%u", &seed); + if (scanf("%u", &seed) != 1) { + printf("Invalid seed.\n"); + return 1; + } + + int ch = 0; + while ((ch = getchar()) != '\n' && ch != EOF) {} + set_random_seed(seed); world_t world; @@ -33,5 +42,16 @@ int main() { centre->is_discovered ? "true" : "false" ); + player_t player = player_create(x, y); + char action[128]; + for (;;) { + printf(">"); + fflush(stdout); + if (fgets(action, sizeof(action), stdin) == NULL) break; + + action[strcspn(action, "\n")] = '\0'; + player_process_action(&player, action); + } + return 0; } diff --git a/iris_c/player.c b/iris_c/player.c new file mode 100644 index 0000000..0c4f384 --- /dev/null +++ b/iris_c/player.c @@ -0,0 +1,12 @@ +#include "player.h" + +#include + +player_t player_create(uint16_t x, uint16_t y) { + return (player_t){.x = x, .y = y}; +} + +void player_process_action(player_t *player, const char *action) { + (void)player; + (void)action; +} diff --git a/iris_c/player.h b/iris_c/player.h new file mode 100644 index 0000000..9175351 --- /dev/null +++ b/iris_c/player.h @@ -0,0 +1,14 @@ +#ifndef PLAYER_H +#define PLAYER_H + +#include + +typedef struct { + uint16_t x; + uint16_t y; +} player_t; + +player_t player_create(uint16_t x, uint16_t y); +void player_process_action(player_t *player, const char *action); + +#endif