Add a room and the ability to look at it
This commit is contained in:
parent
9611904323
commit
900ffecae8
@ -4,7 +4,7 @@ void gs_handle_command(GameState *gs, const char *command) {
|
|||||||
Input *input = gs->input;
|
Input *input = gs->input;
|
||||||
if (strcmp(input->input_buffer, "QUIT") == 0) {
|
if (strcmp(input->input_buffer, "QUIT") == 0) {
|
||||||
*(gs->should_close) = true;
|
*(gs->should_close) = true;
|
||||||
} else {
|
} else if (strcmp(input->input_buffer, "LOOK") == 0) {
|
||||||
push_input_buffer_to_log(input);
|
push_line_to_log(input->log, gs->rooms[0].description);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,10 +4,13 @@
|
|||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
typedef struct GameState GameState;
|
typedef struct GameState GameState;
|
||||||
#include "input.h"
|
#include "input.h"
|
||||||
|
#include "room.h"
|
||||||
|
|
||||||
struct GameState {
|
struct GameState {
|
||||||
bool *should_close;
|
bool *should_close;
|
||||||
Input *input;
|
Input *input;
|
||||||
|
Room *rooms;
|
||||||
|
int rooms_count;
|
||||||
};
|
};
|
||||||
|
|
||||||
void gs_handle_command(GameState *gs, const char *command);
|
void gs_handle_command(GameState *gs, const char *command);
|
||||||
|
@ -30,10 +30,15 @@ void push_input_buffer_to_log(Input *input) {
|
|||||||
push_line_to_log(input->log, input->input_buffer);
|
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) {
|
void handleKeyPress(Input *input, int c) {
|
||||||
if (c == BACKSPACE) {
|
if (c == BACKSPACE) {
|
||||||
pop_character(input);
|
pop_character(input);
|
||||||
} else if (c == ENTER) {
|
} else if (c == ENTER) {
|
||||||
|
push_command_to_log(input);
|
||||||
gs_handle_command(input->gs, input->input_buffer);
|
gs_handle_command(input->gs, input->input_buffer);
|
||||||
clear_input_buffer(input);
|
clear_input_buffer(input);
|
||||||
} else if ((c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9') || c == ' ') {
|
} else if ((c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9') || c == ' ') {
|
||||||
|
@ -9,6 +9,7 @@ typedef struct Input Input;
|
|||||||
#define INPUT_BUFFER_MAX_LENGTH 80
|
#define INPUT_BUFFER_MAX_LENGTH 80
|
||||||
|
|
||||||
struct Input {
|
struct Input {
|
||||||
|
char command; // Don't move this
|
||||||
char input_buffer[INPUT_BUFFER_MAX_LENGTH];
|
char input_buffer[INPUT_BUFFER_MAX_LENGTH];
|
||||||
int input_length;
|
int input_length;
|
||||||
Vector2 position;
|
Vector2 position;
|
||||||
|
@ -21,8 +21,14 @@ int main(void) {
|
|||||||
Input *input = create_input(input_position);
|
Input *input = create_input(input_position);
|
||||||
input->log = log;
|
input->log = log;
|
||||||
input->gs = gs;
|
input->gs = gs;
|
||||||
|
input->command = '>'; // Don't change this
|
||||||
gs->input = input;
|
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))
|
while (!WindowShouldClose() && !*(gs->should_close))
|
||||||
{
|
{
|
||||||
BeginDrawing();
|
BeginDrawing();
|
||||||
|
11
01_text_adventure/room.h
Normal file
11
01_text_adventure/room.h
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
#ifndef _FD_ROOM_
|
||||||
|
#define _FD_ROOM_
|
||||||
|
|
||||||
|
typedef struct Room Room;
|
||||||
|
|
||||||
|
struct Room {
|
||||||
|
char *name;
|
||||||
|
char *description;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
Loading…
Reference in New Issue
Block a user