Added error checking for config.json

This commit is contained in:
2021-03-08 20:51:58 -05:00
parent fe13bac080
commit de99b127b1
10 changed files with 161 additions and 52 deletions

View File

@@ -59,6 +59,7 @@ int last_time;
int current_time;
int diff_time;
Game::Game() {
// TODO Auto-generated constructor stub
@@ -94,6 +95,7 @@ void Game::init(const char *title, int width, int height, bool fullscreen, int g
else
{
SDL_SetRenderDrawColor(renderer, 255,255,255,255);
SDL_SetHint(SDL_HINT_RENDER_VSYNC, "1");
isRunning = true;
}
//Initialize SDL_mixer
@@ -119,9 +121,10 @@ void Game::init(const char *title, int width, int height, bool fullscreen, int g
map = new Map("terrain",globalScale,16);
const char* myText = "Find lost puppies!";
std::string myText = "Find lost puppies!\nThey need your help!";
text = new UIText(myText, "font", 0, 0, 8, 12, globalScale);
text->ParseString(myText, 12, 22, globalScale);
text->ParseString(myText, 12, 22, globalScale, "text");
SDL_Rect myDestRect = SDL_Rect();
myDestRect.x = 12;
myDestRect.y = 8;
@@ -145,6 +148,16 @@ void Game::init(const char *title, int width, int height, bool fullscreen, int g
puppy.addComponent<SpriteComponent>("puppy", SpriteComponent::spriteObject);
puppy.addGroup(groupObjects);
// const char* strA = "r";
// const char* strB = "r";
//
// if (strcmp(strA,strB)==0)
// {
// printf("strcomp evaluated to true");
// } else {
// printf("strcomp false or not evaluated");
// }
// enemy.addComponent<TransformComponent>(180*globalScale,180*globalScale,32,32,globalScale);
// enemy.addComponent<SpriteComponent>("robber", SpriteComponent::spriteAnimation, "assets/textures/actors/robberrodent.json");
// enemy.addGroup(groupEnemies);
@@ -186,12 +199,24 @@ void Game::update()
SDL_Rect playerCol = player.getComponent<ColliderComponent>().collider;
Vector2D playerPos = player.getComponent<TransformComponent>().position;
if (Mix_PlayingMusic() == 0)
// if (gsm->currentState == GameStateManager::ST_INIT)
// {
// const char* initText = "Loading...";
// text->ParseString(initText,12,22,gScale,"init");
// const char* titleText = "Beagle Rescue";
// const char* gameOverText = "Game Over";
// }
if (Mix_PlayingMusic() == 0 && gsm->currentState == GameStateManager::ST_COREGAME)
{
// std::cout << "Play Music Now" << std::endl;
// Mix_PlayMusic(assets->GetMusicTrack("simonZ"), -1);
Mix_PlayMusic(assets->GetMusicTrack("simonZ"), -1);
}
if (Mix_PlayingMusic() != 0 && gsm->currentState != GameStateManager::ST_COREGAME)
{
Mix_HaltMusic();
}
// if (Mix_PlayChannel(-1, Game::assets->GetSoundClip("bark1"),0) == 0)
// {
// Mix_PlayChannel(-1, Game::assets->GetSoundClip("bark1"),0);
@@ -274,7 +299,7 @@ void Game::render()
{
p->draw();
}
if (gsm->currentState==GameStateManager::ST_TITLESCREEN){
if (gsm->currentState==GameStateManager::ST_TITLESCREEN||gsm->currentState==GameStateManager::ST_INIT||gsm->currentState==GameStateManager::ST_GAMEOVER){
for (auto& guiElement : gui)
{
guiElement->draw();