144 lines
3.8 KiB
C++
144 lines
3.8 KiB
C++
#include <SDL3/SDL_rect.h>
|
|
#define SDL_MAIN_USE_CALLBACKS 1 /* use the callbacks instead of main() */
|
|
|
|
#include <SDL3/SDL.h>
|
|
#include <SDL3/SDL_events.h>
|
|
#include <SDL3/SDL_init.h>
|
|
#include <SDL3/SDL_keyboard.h>
|
|
#include <SDL3/SDL_keycode.h>
|
|
#include <SDL3/SDL_log.h>
|
|
#include <SDL3/SDL_main.h>
|
|
#include <SDL3/SDL_render.h>
|
|
#include <SDL3/SDL_video.h>
|
|
#include <SDL3_ttf/SDL_ttf.h>
|
|
#include "MathCommon.h"
|
|
#include "Text.h"
|
|
#include "fileCommon.h"
|
|
#include "game.h"
|
|
#include "window.h"
|
|
|
|
|
|
Game game;
|
|
Window window;
|
|
|
|
Text text;
|
|
|
|
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);
|
|
SaveJsonFile(path, j);
|
|
}
|
|
|
|
|
|
SDL_AppResult SDL_AppInit(void **appstate, int argc, char *argv[]) {
|
|
|
|
if (SDL_Init(SDL_INIT_VIDEO) == false) {
|
|
SDL_Log("SDL could not initialize! SDL error: %s\n", SDL_GetError());
|
|
}
|
|
|
|
Vector3 vector = Vector3(0, 255, 0);
|
|
|
|
SDL_AppResult result = window.CreateWindow(600, 800);
|
|
|
|
if (result != SDL_APP_CONTINUE) {
|
|
return result;
|
|
}
|
|
|
|
result = text.OpenFont("Resources/Pixelzone-E4MV4.ttf");
|
|
|
|
if (result != SDL_APP_CONTINUE) {
|
|
return result;
|
|
}
|
|
|
|
if (!game) {
|
|
game.Init();
|
|
Game::SetGameInstance(&game);
|
|
game.SetIsActive(true);
|
|
SDL_StartTextInput(window.GetWindow());
|
|
} else {
|
|
printf("Game Initalization failed! \n");
|
|
return SDL_APP_FAILURE;
|
|
}
|
|
|
|
text.SetText("Hello There", &window, {100, 100, 100, 500});
|
|
|
|
return SDL_APP_CONTINUE;
|
|
}
|
|
|
|
SDL_AppResult SDL_AppEvent(void *appstate, SDL_Event *event) {
|
|
if (event->type == SDL_EVENT_QUIT || !game.GetIsActive()) {
|
|
return SDL_APP_SUCCESS; /* end the program, reporting success to the OS. */
|
|
}
|
|
|
|
if (event->type == SDL_EVENT_KEY_DOWN) {
|
|
if (event->key.key == SDLK_ESCAPE) {
|
|
SDL_StopTextInput(window.GetWindow());
|
|
game.SetIsActive(false);
|
|
}
|
|
|
|
if (event->key.key == SDLK_RETURN) {
|
|
SDL_StopTextInput(window.GetWindow());
|
|
}
|
|
}
|
|
|
|
if (event->type == SDL_EVENT_WINDOW_PIXEL_SIZE_CHANGED) {
|
|
window.Resize(event->window.data1, event->window.data2);
|
|
}
|
|
|
|
return SDL_APP_CONTINUE;
|
|
}
|
|
|
|
SDL_AppResult SDL_AppIterate(void *appstate) {
|
|
if (game.GetIsActive()) {
|
|
|
|
SDL_SetRenderDrawColor(window.GetRenderer(), 0, 0, 0, 255); // Set render draw color to black
|
|
SDL_RenderClear(window.GetRenderer()); // Clear the renderer
|
|
text.Render();
|
|
SDL_RenderPresent(window.GetRenderer()); // Render the screen
|
|
|
|
// game.Run();
|
|
}
|
|
|
|
return SDL_APP_CONTINUE;
|
|
}
|
|
|
|
void SDL_AppQuit(void *appstate, SDL_AppResult result) {
|
|
if (result == SDL_APP_SUCCESS) {
|
|
window.Close();
|
|
text.CloseFont();
|
|
SDL_Quit();
|
|
}
|
|
}
|