Add a room and the ability to look at it

This commit is contained in:
Bill Rossi 2025-01-03 21:24:56 -05:00
parent 9611904323
commit 900ffecae8
6 changed files with 28 additions and 2 deletions

View File

@ -4,7 +4,7 @@ void gs_handle_command(GameState *gs, const char *command) {
Input *input = gs->input;
if (strcmp(input->input_buffer, "QUIT") == 0) {
*(gs->should_close) = true;
} else {
push_input_buffer_to_log(input);
} else if (strcmp(input->input_buffer, "LOOK") == 0) {
push_line_to_log(input->log, gs->rooms[0].description);
}
}

View File

@ -4,10 +4,13 @@
#include <stdbool.h>
typedef struct GameState GameState;
#include "input.h"
#include "room.h"
struct GameState {
bool *should_close;
Input *input;
Room *rooms;
int rooms_count;
};
void gs_handle_command(GameState *gs, const char *command);

View File

@ -30,10 +30,15 @@ void push_input_buffer_to_log(Input *input) {
push_line_to_log(input->log, input->input_buffer);
}
void push_command_to_log(Input *input) {
push_line_to_log(input->log, &(input->command));
}
void handleKeyPress(Input *input, int c) {
if (c == BACKSPACE) {
pop_character(input);
} else if (c == ENTER) {
push_command_to_log(input);
gs_handle_command(input->gs, input->input_buffer);
clear_input_buffer(input);
} else if ((c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9') || c == ' ') {

View File

@ -9,6 +9,7 @@ typedef struct Input Input;
#define INPUT_BUFFER_MAX_LENGTH 80
struct Input {
char command; // Don't move this
char input_buffer[INPUT_BUFFER_MAX_LENGTH];
int input_length;
Vector2 position;

View File

@ -21,8 +21,14 @@ int main(void) {
Input *input = create_input(input_position);
input->log = log;
input->gs = gs;
input->command = '>'; // Don't change this
gs->input = input;
gs->rooms = malloc(sizeof(Room));
Room *room = &gs->rooms[0];
room->name = "First room";
room->description = "You are in an enormous room. It is big but empty.";
while (!WindowShouldClose() && !*(gs->should_close))
{
BeginDrawing();

11
01_text_adventure/room.h Normal file
View File

@ -0,0 +1,11 @@
#ifndef _FD_ROOM_
#define _FD_ROOM_
typedef struct Room Room;
struct Room {
char *name;
char *description;
};
#endif