107 lines
2.8 KiB
C++
107 lines
2.8 KiB
C++
#include <SDL3/SDL.h>
|
|
#include <SDL3/SDL_init.h>
|
|
#include <SDL3/SDL_main.h>
|
|
#include <SDL3/SDL_render.h>
|
|
#include <SDL3_ttf/SDL_ttf.h>
|
|
|
|
/* We will use this renderer to draw into this window every frame. */
|
|
static SDL_Window *window = nullptr;
|
|
static SDL_Renderer *renderer = nullptr;
|
|
|
|
#include "game.h"
|
|
|
|
void EditRooms() {
|
|
|
|
fs::path path("Resources/rooms.json");
|
|
|
|
std::vector<std::vector<Room>> roomDat = {
|
|
{
|
|
{
|
|
0,
|
|
"Test Room 1",
|
|
"First Test Room",
|
|
{{0, S, false}, {1, E, false}},
|
|
{
|
|
{0, "Rock", "A Grey Rock", {"Rock"}, ObjectType::SCENERY, false, 0},
|
|
},
|
|
},
|
|
{1,
|
|
"Test Room 2",
|
|
"A court yard",
|
|
{{2, W, false}, {3, E, false}, {4, S, false}},
|
|
{{1,
|
|
"Tree",
|
|
"A fine looking Tree stands in the courtyard",
|
|
{"Tree"},
|
|
ObjectType::SCENERY,
|
|
false,
|
|
1}}},
|
|
|
|
},
|
|
{{3,
|
|
"Test Room 3",
|
|
"You can hear the sound of a waterfall nearby",
|
|
{{5, N, false}, {6, E, false}},
|
|
{{3, "Waterfall", "A fine waterfall on a cliff", {"Waterfall"}, ObjectType::SCENERY, false, 3}}}}};
|
|
|
|
nlohmann::json j(roomDat);
|
|
|
|
std::fstream outFile(absolute(path), std::fstream::in | std::fstream::out | std::fstream::app);
|
|
outFile << std::setw(4) << j << std::endl;
|
|
|
|
outFile.close();
|
|
}
|
|
|
|
int main(int argc, char *argv[]) {
|
|
Game game;
|
|
SDL_Event e;
|
|
|
|
if (SDL_Init(SDL_INIT_VIDEO) == false) {
|
|
SDL_Log("SDL could not initialize! SDL error: %s\n", SDL_GetError());
|
|
}
|
|
|
|
TTF_Init();
|
|
|
|
|
|
window = SDL_CreateWindow("Text Adventure", 1280, 720, 0);
|
|
|
|
if (window == nullptr) {
|
|
printf("SDL_CreateWindow Error: \n", SDL_GetError());
|
|
SDL_Quit();
|
|
return 1;
|
|
}
|
|
|
|
renderer = SDL_CreateRenderer(window, NULL);
|
|
|
|
if (renderer == nullptr)
|
|
{
|
|
printf("SDL_CreateRenderer Error: \n", SDL_GetError());
|
|
SDL_DestroyWindow(window);
|
|
SDL_Quit();
|
|
return 1;
|
|
}
|
|
|
|
|
|
if (!game) {
|
|
game.Init();
|
|
Game::SetGameInstance(&game);
|
|
}
|
|
|
|
while (game.GetIsActive()) {
|
|
while (SDL_PollEvent(&e)) {
|
|
if (e.type == SDL_EVENT_QUIT) {
|
|
game.SetIsActive(false);
|
|
}
|
|
}
|
|
|
|
game.Run();
|
|
|
|
SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255); // Set render draw color to black
|
|
SDL_RenderClear(renderer); // Clear the renderer
|
|
|
|
SDL_RenderPresent(renderer); // Render the screen
|
|
|
|
}
|
|
return 0;
|
|
}
|