Compare commits

..

5 Commits

Author SHA1 Message Date
02938c7933 Use switch 2026-02-25 11:33:55 +01:00
b8cd1ce56f Quit on q 2026-02-25 11:32:27 +01:00
1db758543f Add player and game loop 2026-02-24 15:52:07 +01:00
9ff08e4a91 Use prettynames.h 2026-02-24 14:03:43 +01:00
a094105476 prettynames.c 2026-02-24 13:59:10 +01:00
7 changed files with 94 additions and 21 deletions

View File

@@ -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`).

View File

@@ -6,8 +6,8 @@ TARGET = main
all: $(TARGET)
$(TARGET): main.c random.c random.h world.c world.h
$(CC) $(CFLAGS) -o $@ main.c random.c world.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)

View File

@@ -1,31 +1,23 @@
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include "prettynames.h"
#include "player.h"
#include "random.h"
#include "world.h"
static const char *quadrant_type_name(quadrant_type type) {
switch (type) {
case Q_EMPTY: return "Empty";
case Q_ASTEROID_FIELD: return "Asteroid field";
case Q_STAR_SYSTEM: return "Star system";
case Q_NEBULA: return "Nebula";
case Q_BLACK_HOLE: return "Black hole";
case Q_WHITE_HOLE: return "White hole";
case Q_PULSAR: return "Pulsar";
case Q_QUASAR: return "Quasar";
case Q_SUPERNOVA: return "Supernova";
case Q_ANOMALY: return "Anomaly";
case Q_SINGULARITY: return "Singularity";
case Q_COUNT: return "Count";
default: return "Undefined";
}
}
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;
@@ -50,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;
}

21
iris_c/player.c Normal file
View File

@@ -0,0 +1,21 @@
#include "player.h"
#include <stddef.h>
#include <stdlib.h>
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) {
// Quit on q
switch (action[0]) {
case 'q':
exit(0);
default:
break;
}
(void)player;
}

14
iris_c/player.h Normal file
View File

@@ -0,0 +1,14 @@
#ifndef PLAYER_H
#define PLAYER_H
#include <stdint.h>
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

19
iris_c/prettynames.c Normal file
View File

@@ -0,0 +1,19 @@
#include "prettynames.h"
const char *quadrant_type_name(quadrant_type type) {
switch (type) {
case Q_EMPTY: return "Empty";
case Q_ASTEROID_FIELD: return "Asteroid field";
case Q_STAR_SYSTEM: return "Star system";
case Q_NEBULA: return "Nebula";
case Q_BLACK_HOLE: return "Black hole";
case Q_WHITE_HOLE: return "White hole";
case Q_PULSAR: return "Pulsar";
case Q_QUASAR: return "Quasar";
case Q_SUPERNOVA: return "Supernova";
case Q_ANOMALY: return "Anomaly";
case Q_SINGULARITY: return "Singularity";
case Q_COUNT: return "Count";
default: return "Undefined";
}
}

8
iris_c/prettynames.h Normal file
View File

@@ -0,0 +1,8 @@
#ifndef PRETTYNAMES_H
#define PRETTYNAMES_H
#include "world.h"
const char *quadrant_type_name(quadrant_type type);
#endif