-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
134 lines (114 loc) · 4.2 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
/*
* Land of Limbs
* Copyright 2024 Matthew Payne
* <https://www.pattmayne.com>
*
* .--..--..--..--..--..--..--..--..--..--..--..--..--.
* / .. \.. \.. \.. \.. \.. \.. \.. \.. \.. \.. \.. \.. \
* \ \/\ `'\ `'\ `'\ `'\ `'\ `'\ `'\ `'\ `'\ `'\ `'\ \/ /
* \/ /`--'`--'`--'`--'`--'`--'`--'`--'`--'`--'`--'\/ /
* / /\ / /\
* / /\ \ _ _ __ / /\ \
* \ \/ / | | __ _ _ __ __| | ___ / _| \ \/ /
* \/ / | | / _` | '_ \ / _` | / _ \| |_ \/ /
* / /\ | |__| (_| | | | | (_| | | (_) | _| / /\
* / /\ \ |_____\__,_|_| |_|\__,_| \___/|_| / /\ \
* \ \/ / | | (_)_ __ ___ | |__ ___ \ \/ /
* \/ / | | | | '_ ` _ \| '_ \/ __| \/ /
* / /\ | |___| | | | | | | |_) \__ \ / /\
* / /\ \ |_____|_|_| |_| |_|_.__/|___/ / /\ \
* \ \/ / \ \/ /
* \/ / \/ /
* / /\.--..--..--..--..--..--..--..--..--..--..--./ /\
* / /\ \.. \.. \.. \.. \.. \.. \.. \.. \.. \.. \.. \/\ \
* \ `'\ `'\ `'\ `'\ `'\ `'\ `'\ `'\ `'\ `'\ `'\ `'\ `' /
* `--'`--'`--'`--'`--'`--'`--'`--'`--'`--'`--'`--'`--'
*
* A puzzle/adventure/RPG game where you build a modular character from LIMBs.
*
*/
#include "include/json.hpp"
#include "SDL.h"
#include "SDL_image.h"
#include <stdio.h>
#include <string>
#include <iostream>
#include "SDL_ttf.h"
#include <vector>
#include <cstdlib>
#include <ctime>
import UI;
import GameState;
import MenuScreen;
import MapScreen;
import BattleScreen;
import CharacterCreationScreen;
import TypeStorage;
import Resources;
import Database;
using namespace std;
const bool DEBUG = false;
/* declarations */
void exit(SDL_Surface* surface, SDL_Window* window);
/* Main game loop manages particular screens, which do actual game logic. */
int main(int argc, char* args[]) {
cout << "Game loaded.\n";
createDB();
/* seed the random number generator now for the whole game */
srand((unsigned int)time(NULL));
/* instantiate the UI instance, and hold the reference for eventual destruction in this file. */
UI& ui = UI::getInstance();
GameState& gameState = GameState::getInstance();
gameState.setPlayerID(createPlayerCharacterOrGetID());
if (gameState.getPlayerID() < 1) {
cout << "ERROR: No player character\n";
return -1;
}
ScreenStruct screenToLoadStruct = closingScreenStruct();
bool running = true;
SDL_Event e;
/* Game loop checks gameState for screen to load, then loads that screen.
* Each screen, once loaded, has its own game loop (where the real game logic happens).
* When a screen is finished its job (or a user has chosen to move to a new screen),
* the screen's "run" function returns a NEW screen to load. */
while (running) {
/* Check for closing the app(clicking the(x) button) */
while (SDL_PollEvent(&e) != 0) {
if (e.type == SDL_QUIT) { running = false; }
}
/* run the chosen screen and receive the next screen to load
* if the screenToLoad is Map or Battle, we will send in the ID to the Run function */
if (gameState.getScreenType() == ScreenType::Menu) {
cout << "\n\n MENU \n\n";
MenuScreen menuScreen = MenuScreen();
menuScreen.run();
}
else if (gameState.getScreenType() == ScreenType::Map) {
cout << "\nselected MAP\n";
MapScreen mapScreen = MapScreen("forest");
mapScreen.run();
}else if (gameState.getScreenType() == ScreenType::Battle) {
cout << "\nselected BATTLE\n";
BattleScreen battleScreen = BattleScreen();
battleScreen.run();
}else if (gameState.getScreenType() == ScreenType::CharacterCreation) {
cout << "\nselected CHARACTER CREATION\n";
CharacterCreationScreen characterCreationScreen = CharacterCreationScreen();
characterCreationScreen.run();
}
/* check for closingScreen type and close.Otherwise we will load the NEW screen on the next loop */
if (gameState.getScreenType() == ScreenType::NoScreen) {
cout << "\n\n WHY NO SCREEN?? \n\n";
running = false; }
}
exit(ui.getWindowSurface(), ui.getMainWindow());
return 0;
}
/* Free SDL resources and quit */
void exit(SDL_Surface* surface, SDL_Window* window) {
SDL_FreeSurface(surface);
surface = NULL;
SDL_DestroyWindow(window);
window = NULL;
SDL_Quit();
}