Skip to content

Commit

Permalink
Gametimer, Checkpoint bug fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
Historn committed Jan 29, 2023
1 parent 972197e commit 6895c56
Show file tree
Hide file tree
Showing 11 changed files with 92 additions and 31 deletions.
2 changes: 1 addition & 1 deletion citm_desvj_project_template-L07/Game/Game.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<SubSystem>Windows</SubSystem>
<AdditionalDependencies>SDL2.lib;SDL2main.lib;SDL2_image.lib;SDL2_mixer.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;OptickCore.lib;SDL2_ttf.lib;ox2D.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalDependencies>SDL2.lib;SDL2main.lib;SDL2_image.lib;SDL2_mixer.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;OptickCore.lib;SDL2_ttf.lib;Box2D.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalLibraryDirectories>$(ProjectDir)Source\External\SDL_ttf\libx86;$(ProjectDir)Source\External\Optick\lib\releaseLib;$(ProjectDir)Source\External\Optick\lib\debugLib;$(ProjectDir)Source\External\SDL\libx86;$(ProjectDir)Source\External\SDL_image\libx86;$(ProjectDir)Source\External\SDL_mixer\libx86;$(ProjectDir)Source\External\Box2D\libx86\ReleaseLib</AdditionalLibraryDirectories>
</Link>
<PostBuildEvent>
Expand Down
1 change: 1 addition & 0 deletions citm_desvj_project_template-L07/Game/Source/Item.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ void Item::OnCollision(PhysBody* physA, PhysBody* physB) {


if (iType == "life" && app->scene->player->lives < 3) {
app->scene->itemLivesCount++;
pbody->body->SetActive(false);
this->Disable();
}
Expand Down
8 changes: 7 additions & 1 deletion citm_desvj_project_template-L07/Game/Source/Player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,12 @@ bool Player::Update()
currentAnim->Update();
}

if (gameTimer <= 0) {
lives = 0;
dead = true;
app->audio->PlayFx(dieSFX);
app->fade->FadeToBlack((Module*)app->scene, (Module*)app->endingscreen, 60);
}

return true;
}
Expand Down Expand Up @@ -400,7 +406,7 @@ void Player::OnCollision(PhysBody* physA, PhysBody* physB) {
break;
case ColliderType::BAT_HITBOX:
LOG("Collison BAT HEAD HITBOX");

Jump();
app->scene->bat->lives--;
app->scene->bat->onCollision = true;
if (app->scene->bat->lives <= 0) {
Expand Down
63 changes: 44 additions & 19 deletions citm_desvj_project_template-L07/Game/Source/Scene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ bool Scene::Start()
{
item = (Item*)app->entityManager->CreateEntity(EntityType::ITEM);
item->parameters = itemNode;
livesCollectedList.Add(item);
}

//L02: DONE 3: Instantiate the player using the entity manager
Expand Down Expand Up @@ -179,12 +180,6 @@ bool Scene::Update(float dt)
app->LoadGameRequest();
app->audio->PlayFx(selectSFX);
}

if (app->input->GetKey(SDL_SCANCODE_L) == KEY_DOWN)
{
app->render->limitFPS = !app->render->limitFPS;
app->audio->PlayFx(selectSFX);
}

// God Mode key
if (app->input->GetKey(SDL_SCANCODE_F10) == KEY_DOWN)
Expand Down Expand Up @@ -212,10 +207,10 @@ bool Scene::Update(float dt)
}


// Cap FPS to 30
// Cap FPS to 60
if (app->input->GetKey(SDL_SCANCODE_F11) == KEY_DOWN)
{
capTo30fps = !capTo30fps;
app->render->limitFPS = !app->render->limitFPS;
app->audio->PlayFx(selectSFX);
}

Expand Down Expand Up @@ -389,12 +384,17 @@ void Scene::ResetScene() {

app->audio->PlayMusic("Assets/Audio/Music/song1.ogg", 1.0f);

if (checkpointEnabled == false) {
pugi::xml_document gameStateFile;
pugi::xml_parse_result result = gameStateFile.load_file("save_game.xml");

if (checkpointEnabled == false || result == NULL) {
checkpointEnabled = false;
player->ResetPlayerPos();
player->lives = 3;
}
else
else if (checkpointEnabled == true && result != NULL) {
app->LoadGameRequest();
}
}

bool Scene::LoadState(pugi::xml_node& data)
Expand All @@ -410,21 +410,39 @@ bool Scene::LoadState(pugi::xml_node& data)
//Load previous saved player number of lives
app->scene->player->lives = data.child("playerLives").attribute("playerLives").as_float();

/*app->scene->player->coins = data.child("coins").attribute("coins").as_int();
app->scene->player->coins = data.child("coins").attribute("coins").as_int();
ListItem<Coin*>* coinsCollected;
coinsCollected = coinsList.end;
coinsCollected = coinsList.start;
int countCoins = app->scene->player->coins;
while(countCoins >= 0 && coinsCollected != NULL){

if (coinsCollected->data->isPicked == true) {
coinsCollected->data->ResetCoin();
if (coinsCollected->data->isPicked == false) {
coinsCollected->data->isPicked = true;
countCoins--;
}


coinsCollected = coinsCollected->prev;
}*/
coinsCollected = coinsCollected->next;
}

itemLivesCount = data.child("itemLives").attribute("itemLives").as_int();
ListItem<Item*>* livesCollected;
livesCollected = livesCollectedList.start;
int countLives = itemLivesCount;
while(countLives >= 0 && livesCollected != NULL){

if (livesCollected->data->isPicked == false) {
livesCollected->data->isPicked = true;
countLives--;
}


livesCollected = livesCollected->next;
}

//Load previous saved player number of lives
checkpointEnabled = data.child("checkpointEnabled").attribute("checkpointEnabled").as_bool();

// Load previous saved slime position
b2Vec2 slimePos = { data.child("slimePosition").attribute("x").as_float(), data.child("slimePosition").attribute("y").as_float() };
app->scene->slime->pbody->body->SetTransform(slimePos, 0);
Expand Down Expand Up @@ -463,9 +481,16 @@ bool Scene::SaveState(pugi::xml_node& data)
playerLives.append_attribute("playerLives") = app->scene->player->lives;

// Save current player number of coins
/*pugi::xml_node playerCoins = data.append_child("coins");
playerCoins.append_attribute("coins") = app->scene->player->coins;*/

pugi::xml_node playerCoins = data.append_child("coins");
playerCoins.append_attribute("coins") = app->scene->player->coins;

// Save current player number of coins
pugi::xml_node itemLives = data.append_child("itemLives");
itemLives.append_attribute("itemLives") = itemLives;

// Save current player number of coins
pugi::xml_node checkpointEnabled = data.append_child("checkpointEnabled");
checkpointEnabled.append_attribute("checkpointEnabled") = checkpointEnabled;

// Save current slime position
pugi::xml_node slimePos = data.append_child("slimePosition");
Expand Down
3 changes: 3 additions & 0 deletions citm_desvj_project_template-L07/Game/Source/Scene.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ class Scene : public Module

List<Coin*> coinsList;

List<Item*> livesCollectedList;
int itemLivesCount = 0;

private:
SDL_Texture* img_pause;
iPoint startPosition;
Expand Down
4 changes: 4 additions & 0 deletions citm_desvj_project_template-L07/Game/Source/TitleScreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,10 @@ bool TitleScreen::OnGuiMouseClickEvent(GuiControl* control)
// Play button
app->fade->FadeToBlack(this, (Module*)app->scene, 90);
app->audio->PlayFx(startSFX);
if (remove("save_game.xml") != 0)
LOG("Error at Deleting Save Game");
else
LOG("Save Game Successfully Deleted");
break;

case 2:
Expand Down
22 changes: 18 additions & 4 deletions citm_desvj_project_template-L07/Game/Source/UI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ bool UI::Start()
/*Initialize*/
font1Path = app->configNode.child("ui").child("font1").attribute("texturepath").as_string();
font2Path = app->configNode.child("ui").child("font2").attribute("texturepath").as_string();
font2_RedPath = app->configNode.child("ui").child("font2Red").attribute("texturepath").as_string();
livesTexPath = app->configNode.child("scene").child("life").attribute("texturepath").as_string();
coinsTexPath = app->configNode.child("scene").child("coin").attribute("texturepath").as_string();

Expand All @@ -48,6 +49,9 @@ bool UI::Start()

char lookupTableFont2[] = { "! %&'()*+,-./0123456789:;<=>abcdefghijklmnopqrstuvwxyz" };
font2_id = app->fonts->Load(font2Path, lookupTableFont2, 1);

char lookupTableFont2Red[] = { "! %&'()*+,-./0123456789:;<=>abcdefghijklmnopqrstuvwxyz" };
font2Red_id = app->fonts->Load(font2_RedPath, lookupTableFont2Red, 1);

livesTex = app->tex->Load(livesTexPath);
coinsTex = app->tex->Load(coinsTexPath);
Expand Down Expand Up @@ -122,9 +126,19 @@ void UI::BlitLives()

void UI::BlitTimer()
{
char time[20];
sprintf_s(time, 20, "time: %.f", app->scene->player->gameTimer);
app->fonts->BlitText(400, 15, font2_id, time);
if (app->scene->player->gameTimer < 50)
{
char time[20];
sprintf_s(time, 20, "time: %.f", app->scene->player->gameTimer);
app->fonts->BlitText(425, 15, font2Red_id, time);
}
else
{
char time[20];
sprintf_s(time, 20, "time: %.f", app->scene->player->gameTimer);
app->fonts->BlitText(425, 15, font2_id, time);
}

}

void UI::BlitCoins()
Expand Down Expand Up @@ -187,7 +201,7 @@ void UI::BlitFPS()
{
char fps[25];
sprintf_s(fps, 25, "fps: %d", app->GetFPS());
app->fonts->BlitText(825, 15, font2_id, fps);
app->fonts->BlitText(870, 15, font2_id, fps);
}

void UI::BlitAverageFPS()
Expand Down
2 changes: 2 additions & 0 deletions citm_desvj_project_template-L07/Game/Source/UI.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class UI : public Module

uint font1_id = -1;
uint font2_id = -1;
uint font2Red_id = -1;

SDL_Texture* livesTex;
const char* livesTexPath;
Expand All @@ -62,6 +63,7 @@ class UI : public Module

const char* font1Path;
const char* font2Path;
const char* font2_RedPath;

};

Expand Down
4 changes: 3 additions & 1 deletion citm_desvj_project_template-L07/Output/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
- {F3} - Start from the beginning of the current level
- {F5} - Save current game state (player & enemies)
- {F6} - Load the previous game state (player & enemies)
- {F7} - Move between checkpoints
- {F9} - View colliders/logic/paths
- {F8} - View GUI bounds rectangles and state
- {F10} - God Mode
- {F11} - Enable/Disable FPS cap to 30

Expand All @@ -28,7 +30,7 @@
- {SPACEBAR} - Player's jump
- {SPACEBAR + SPACEBAR} - Player's DOUBLE jump
- {ENTER} - Pass to the next screen
- {ESCAPE} - Exit the game
- {ESCAPE} - Pause the game

## Developers

Expand Down
1 change: 1 addition & 0 deletions citm_desvj_project_template-L07/Output/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
<ui>
<font1 texturepath="Assets/Textures/font1.png"/>
<font2 texturepath="Assets/Textures/font2.png"/>
<font2Red texturepath="Assets/Textures/font2_red.png"/>
</ui>

<logo>
Expand Down
13 changes: 8 additions & 5 deletions citm_desvj_project_template-L07/Output/save_game.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,17 @@
<:anonymous />
<pathfinding />
<scene>
<playerPosition x="61.7768059" y="10.156683" />
<playerPosition x="63.1790428" y="10.6825018" />
<cameraIsFix value="true" />
<cameraIsFix2 value="false" />
<playerLives playerLives="3" />
<slimePosition x="80.5" y="4.77625084" />
<coins coins="3" />
<itemLives itemLives="true" />
<checkpointEnabled checkpointEnabled="true" />
<slimePosition x="71.2845001" y="17.7762527" />
<slimeLives slimeLives="2" />
<batPosition x="51.6377525" y="9.79751301" />
<batLives batLives="1" />
<batPosition x="7.80534267e-30" y="2.24259555e-36" />
<batLives batLives="0" />
<checkPoint checkPoint="true" />
</scene>
<Fonts_Module />
Expand All @@ -28,6 +31,6 @@
<EndingScreen />
<guiManager />
<renderer>
<camera x="-1453" y="0" />
<camera x="297" y="0" />
</renderer>
</save_state>

0 comments on commit 6895c56

Please sign in to comment.