Compare commits

...

19 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
a1d157c69f Convert original_post.mfm to standard markdown 2026-02-18 13:21:03 +01:00
89d15fc30b fix percentages 2026-02-17 19:42:35 +01:00
e0a4d684fc Generate a world and show the centre quadrant 2026-02-17 14:44:39 +01:00
abbc3e5aa7 Add world files to build 2026-02-17 14:40:49 +01:00
e74f1255a6 Create world.c 2026-02-17 14:39:19 +01:00
e3c561f396 Pretty sure this is world.h done for now 2026-02-17 14:06:53 +01:00
4fd9493380 Better formatting 2026-02-17 13:48:41 +01:00
1965e10bc4 Add quadrant values 2026-02-17 13:47:24 +01:00
e4d78a575a Update main.c 2026-02-17 13:35:23 +01:00
b5cea69fb8 Add stricter compiler warnings 2026-02-17 13:27:55 +01:00
0e8a1b46ec What am I even doing at this point 2026-02-17 13:20:09 +01:00
f6b4cf11b0 . 2026-02-17 13:17:23 +01:00
ea9acc1e3d Add world.c and world.h 2026-02-17 13:15:54 +01:00
4bb81d0c68 Rename asteroid belt to asteroid field 2026-02-17 13:11:29 +01:00
11 changed files with 213 additions and 16 deletions

View File

@@ -7,6 +7,6 @@
>[!WARNING] >[!WARNING]
>I have no idea what I'm doing and I'm definitely not a professional >I have no idea what I'm doing and I'm definitely not a professional
To read the original post go to [the original post](https://fedi.krzak.org/notes/aikajnzup9za0001) or [its copy](./original_post.mfm) To read the original post go to [the original post](https://fedi.krzak.org/notes/aikajnzup9za0001) or [its copy](./original_post.md)
A **C** implementation will **SLOWLY** be done in [./iris_c](./iris_c) A **C** implementation will **SLOWLY** be done in [./iris_c](./iris_c)

View File

@@ -12,8 +12,15 @@
- The world is a 256x256 grid of tiles called quadrants - The world is a 256x256 grid of tiles called quadrants
### Quadrants ### Quadrants
- Every quadrant has three boolean values:
- Visited - Whether the player has visited the quadrant
- Discovered - Whether the player has discovered the quadrant (and is visible on map)
- Old - Whether the quadrant is old, effects differ. Every quadrant has a 20% chance of being old.
#### Quadrant Types
- Empty - 30% chance - Empty - 30% chance
- Asteroid belt - 10% chance - Asteroid field - 10% chance
- Star system - 10% chance - Star system - 10% chance
- Nebula - 10% chance - Nebula - 10% chance
- Black hole - 10% chance - Black hole - 10% chance
@@ -27,3 +34,11 @@
### Wormholes ### 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. - 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

@@ -1,13 +1,13 @@
CC = gcc CC = gcc
CFLAGS = -Wall -Wextra -O2 CFLAGS = -Wall -Wextra -Werror -pedantic -O2
TARGET = main TARGET = main
.PHONY: all clean .PHONY: all clean
all: clean $(TARGET) all: $(TARGET)
$(TARGET): main.c random.c random.h $(TARGET): main.c player.c player.h random.c random.h world.c world.h prettynames.c prettynames.h
$(CC) $(CFLAGS) -o $@ main.c random.c $(CC) $(CFLAGS) -o $@ main.c player.c random.c world.c prettynames.c
clean: clean:
rm -f $(TARGET) rm -f $(TARGET)

View File

@@ -1,16 +1,57 @@
#include "random.h"
#include <stdint.h> #include <stdint.h>
#include <stdio.h> #include <stdio.h>
#include <string.h>
#include "prettynames.h"
#include "player.h"
#include "random.h"
#include "world.h"
int main() { int main() {
uint32_t seed; uint32_t seed;
printf("Enter seed: "); printf("Enter seed: ");
scanf("%u", &seed); if (scanf("%u", &seed) != 1) {
set_random_seed(seed); printf("Invalid seed.\n");
uint32_t num = random_range(20); return 1;
for (uint32_t i = 0; i < num; i++) {
printf("%u\n", random_u32());
} }
printf("%u random numbers\n", num);
int ch = 0;
while ((ch = getchar()) != '\n' && ch != EOF) {}
set_random_seed(seed);
world_t world;
world_generate(&world);
uint16_t x = WORLD_WIDTH / 2;
uint16_t y = WORLD_HEIGHT / 2;
const quadrant_t *centre = world_get_quadrant(&world, x, y);
if (centre == NULL) {
printf("Failed to read centre quadrant.\n");
return 1;
}
printf("Generated world: %ux%u\n", WORLD_WIDTH, WORLD_HEIGHT);
printf(
"Centre (%u, %u): type=%s (%d), old=%s, visited=%s, discovered=%s\n",
x, y,
quadrant_type_name(centre->type),
(int)centre->type,
centre->is_old ? "true" : "false",
centre->is_visited ? "true" : "false",
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; 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

41
iris_c/world.c Normal file
View File

@@ -0,0 +1,41 @@
#include "world.h"
#include <stddef.h>
#include "random.h"
static quadrant_type random_quadrant_type(void) {
uint8_t roll = random_range(100);
if (roll < 30) return Q_EMPTY;
if (roll < 40) return Q_ASTEROID_FIELD;
if (roll < 50) return Q_STAR_SYSTEM;
if (roll < 60) return Q_NEBULA;
if (roll < 70) return Q_BLACK_HOLE;
if (roll < 80) return Q_WHITE_HOLE;
if (roll < 85) return Q_PULSAR;
if (roll < 90) return Q_QUASAR;
if (roll < 95) return Q_SUPERNOVA;
if (roll < 99) return Q_ANOMALY;
return Q_SINGULARITY;
}
void world_generate(world_t *w) {
if (w == NULL) return;
for (uint16_t y = 0; y < WORLD_HEIGHT; y++) {
for (uint16_t x = 0; x < WORLD_WIDTH; x++) {
quadrant_t *q = &w->quadrants[y][x];
q->type = random_quadrant_type();
q->is_old = (random_range(100) < 20);
q->is_visited = false;
q->is_discovered = false;
}
}
}
const quadrant_t *world_get_quadrant(const world_t *w, uint16_t x, uint16_t y) {
if (w == NULL) return NULL;
if (x >= WORLD_WIDTH || y >= WORLD_HEIGHT) return NULL;
return &w->quadrants[y][x];
}

39
iris_c/world.h Normal file
View File

@@ -0,0 +1,39 @@
#ifndef WORLD_H
#define WORLD_H
#include <stdint.h>
#include <stdbool.h>
#define WORLD_WIDTH 256
#define WORLD_HEIGHT 256
typedef enum {
Q_EMPTY,
Q_ASTEROID_FIELD,
Q_STAR_SYSTEM,
Q_NEBULA,
Q_BLACK_HOLE,
Q_WHITE_HOLE,
Q_PULSAR,
Q_QUASAR,
Q_SUPERNOVA,
Q_ANOMALY,
Q_SINGULARITY,
Q_COUNT
} quadrant_type;
typedef struct {
quadrant_type type;
bool is_visited;
bool is_discovered;
bool is_old;
} quadrant_t;
typedef struct {
quadrant_t quadrants[WORLD_HEIGHT][WORLD_WIDTH];
} world_t;
void world_generate(world_t *w);
const quadrant_t * world_get_quadrant(const world_t *w, uint16_t x, uint16_t y);
#endif

View File

@@ -1,6 +1,5 @@
I have this giant idea. Essentially, you know how you have the space game easteregg in A15 and 16? I want to make something like that, but not in the normal way. Like, I don't want to just make a similar game. Like, obviously, it'll be bigger and so on. It's meant to be this trading-thing, like, you go from planet to planet, then, text-based, you sell and buy things, get quests, sometimes not quite legal and so on. But why is this a giant idea? You know how you have card games? But not ones with custom cards, things like war or poker, with normal playing cards. What do you get when you 'get' a card game like that? You get a set of rules, maths and so on. I want to make something like that. I want to make that game in a way where you can just go step-by-step, implement each function in any programming language, in any graphics engine and get the same game back. You could do it in JS, you could do it in Godot, you could do it in C and compile for an old console or you could do it in x86 assembly and run it without an operating system, it would still be the exact. same. game. If someone wanted to, they could even follow each rule themselves, with pen and paper, with no electronics and doing the maths in their head and it would still be the same game. Someone could even grow mice neurons in a petri dish and still - the. same. game. that is the plan. I have this giant idea. Essentially, you know how you have the space game easteregg in A15 and 16? I want to make something like that, but not in the normal way. Like, I don't want to just make a similar game. Like, obviously, it'll be bigger and so on. It's meant to be this trading-thing, like, you go from planet to planet, then, text-based, you sell and buy things, get quests, sometimes not quite legal and so on. But why is this a giant idea? You know how you have card games? But not ones with custom cards, things like war or poker, with normal playing cards. What do you get when you 'get' a card game like that? You get a set of rules, maths and so on. I want to make something like that. I want to make that game in a way where you can just go step-by-step, implement each function in any programming language, in any graphics engine and get the same game back. You could do it in JS, you could do it in Godot, you could do it in C and compile for an old console or you could do it in x86 assembly and run it without an operating system, it would still be the exact. same. game. If someone wanted to, they could even follow each rule themselves, with pen and paper, with no electronics and doing the maths in their head and it would still be the same game. Someone could even grow mice neurons in a petri dish and still - the. same. game. that is the plan.
## I'll write a properly formatting, less rambling version later, I just want to make sure I don't lose this idea
$[x2 I'll write a properly formatting, less rambling version later, I just want to make sure I don't lose this idea] [#gamedev](https://fedi.krzak.org/tags/gamedev) [#gamedesign](https://fedi.krzak.org/tags/gamedesign) [#gamedevelopment](https://fedi.krzak.org/tags/gamedevelopment) [#game](https://fedi.krzak.org/tags/game) [#gameidea](https://fedi.krzak.org/tags/gameidea) [#idea](https://fedi.krzak.org/tags/idea) [#ideas](https://fedi.krzak.org/tags/ideas) [#ideas-ill-probably-never-get-to-making-even-though-i-want-to-so-much](https://fedi.krzak.org/tags/ideas-ill-probably-never-get-to-making-even-though-i-want-to-so-much)
#gamedev #gamedesign #gamedevelopment #game #gameidea #idea #ideas #ideas-ill-probably-never-get-to-making-even-though-i-want-to-so-much