Skip to content

Commit

Permalink
Merge pull request #2 from guillemalqueza/Development-A2
Browse files Browse the repository at this point in the history
Development a2
  • Loading branch information
guillemalqueza authored Dec 20, 2023
2 parents 024bdd0 + 1846d8f commit 6f280e6
Show file tree
Hide file tree
Showing 136 changed files with 225,098 additions and 8,630 deletions.
22 changes: 20 additions & 2 deletions PlatformerGame/Game/Game.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -95,44 +95,61 @@
</PostBuildEvent>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="Source\Chest.cpp" />
<ClCompile Include="Source\CrumblingPlatform.cpp" />
<ClCompile Include="Source\EntityManager.cpp" />
<ClCompile Include="Source\Equipment.cpp" />
<ClCompile Include="Source\FadeToBlack.cpp" />
<ClCompile Include="Source\Item.cpp" />
<ClCompile Include="Source\Ghost.cpp" />
<ClCompile Include="Source\Key.cpp" />
<ClCompile Include="Source\Jumper.cpp" />
<ClCompile Include="Source\LockDoor.cpp" />
<ClCompile Include="Source\LogObstacle.cpp" />
<ClCompile Include="Source\Main.cpp" />
<ClCompile Include="Source\App.cpp" />
<ClCompile Include="Source\Audio.cpp" />
<ClCompile Include="Source\Input.cpp" />
<ClCompile Include="Source\Map.cpp" />
<ClCompile Include="Source\Obstacle.cpp" />
<ClCompile Include="Source\ParticleManager.cpp" />
<ClCompile Include="Source\Pathfinding.cpp" />
<ClCompile Include="Source\PerfTimer.cpp" />
<ClCompile Include="Source\Physics.cpp" />
<ClCompile Include="Source\Player.cpp" />
<ClCompile Include="Source\Scene.cpp" />
<ClCompile Include="Source\Render.cpp" />
<ClCompile Include="Source\Skeleton.cpp" />
<ClCompile Include="Source\Textures.cpp" />
<ClCompile Include="Source\Timer.cpp" />
<ClCompile Include="Source\Window.cpp" />
<ClInclude Include="Source\Animation.h" />
<ClInclude Include="Source\Chest.h" />
<ClInclude Include="Source\CrumblingPlatform.h" />
<ClInclude Include="Source\Entity.h" />
<ClInclude Include="Source\EntityManager.h" />
<ClInclude Include="Source\Equipment.h" />
<ClInclude Include="Source\FadeToBlack.h" />
<ClInclude Include="Source\Item.h" />
<ClInclude Include="Source\Ghost.h" />
<ClInclude Include="Source\Key.h" />
<ClInclude Include="Source\Jumper.h" />
<ClInclude Include="Source\LockDoor.h" />
<ClInclude Include="Source\LogObstacle.h" />
<ClInclude Include="Source\Map.h" />
<ClInclude Include="Source\Obstacle.h" />
<ClInclude Include="Source\ParticleManager.h" />
<ClInclude Include="Source\Pathfinding.h" />
<ClInclude Include="Source\PerfTimer.h" />
<ClInclude Include="Source\Physics.h" />
<ClInclude Include="Source\Player.h" />
<ClInclude Include="Source\PQueue.h" />
<ClInclude Include="Source\Queue.h" />
<ClInclude Include="Source\Scene.h" />
<ClInclude Include="Source\Audio.h" />
<ClInclude Include="Source\Input.h" />
<ClInclude Include="Source\App.h" />
<ClInclude Include="Source\Module.h" />
<ClInclude Include="Source\Render.h" />
<ClInclude Include="Source\Skeleton.h" />
<ClInclude Include="Source\Textures.h" />
<ClInclude Include="Source\Timer.h" />
<ClInclude Include="Source\Window.h" />
Expand All @@ -149,6 +166,7 @@
</ItemGroup>
<ItemGroup>
<Xml Include="..\Output\config.xml" />
<Xml Include="..\Output\save_game.xml" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
Expand Down
60 changes: 56 additions & 4 deletions PlatformerGame/Game/Game.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
<ClCompile Include="Source\Input.cpp">
<Filter>Modules</Filter>
</ClCompile>
<ClCompile Include="Source\Item.cpp">
<ClCompile Include="Source\Key.cpp">
<Filter>Entities</Filter>
</ClCompile>
<ClCompile Include="Source\Physics.cpp">
Expand All @@ -57,8 +57,32 @@
<ClCompile Include="Source\Textures.cpp">
<Filter>Modules</Filter>
</ClCompile>
<ClCompile Include="Source\Skeleton.cpp">
<Filter>Entities</Filter>
</ClCompile>
<ClCompile Include="Source\Ghost.cpp">
<Filter>Entities</Filter>
</ClCompile>
<ClCompile Include="Source\Pathfinding.cpp">
<Filter>Modules</Filter>
</ClCompile>
<ClCompile Include="Source\Map.cpp">
<Filter>Tools</Filter>
<Filter>Modules</Filter>
</ClCompile>
<ClCompile Include="Source\Equipment.cpp">
<Filter>Entities</Filter>
</ClCompile>
<ClCompile Include="Source\ParticleManager.cpp">
<Filter>Modules</Filter>
</ClCompile>
<ClCompile Include="Source\Obstacle.cpp">
<Filter>Entities</Filter>
</ClCompile>
<ClCompile Include="Source\Chest.cpp">
<Filter>Entities</Filter>
</ClCompile>
<ClCompile Include="Source\LogObstacle.cpp">
<Filter>Entities</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
Expand Down Expand Up @@ -111,7 +135,7 @@
<ClInclude Include="Source\Input.h">
<Filter>Modules</Filter>
</ClInclude>
<ClInclude Include="Source\Item.h">
<ClInclude Include="Source\Key.h">
<Filter>Entities</Filter>
</ClInclude>
<ClInclude Include="Source\Scene.h">
Expand Down Expand Up @@ -147,8 +171,35 @@
<ClInclude Include="Source\Animation.h">
<Filter>Modules</Filter>
</ClInclude>
<ClInclude Include="Source\Skeleton.h">
<Filter>Entities</Filter>
</ClInclude>
<ClInclude Include="Source\Ghost.h">
<Filter>Entities</Filter>
</ClInclude>
<ClInclude Include="Source\Pathfinding.h">
<Filter>Modules</Filter>
</ClInclude>
<ClInclude Include="Source\Map.h">
<Filter>Tools</Filter>
<Filter>Modules</Filter>
</ClInclude>
<ClInclude Include="Source\PQueue.h">
<Filter>Utils</Filter>
</ClInclude>
<ClInclude Include="Source\Equipment.h">
<Filter>Entities</Filter>
</ClInclude>
<ClInclude Include="Source\ParticleManager.h">
<Filter>Modules</Filter>
</ClInclude>
<ClInclude Include="Source\Obstacle.h">
<Filter>Entities</Filter>
</ClInclude>
<ClInclude Include="Source\Chest.h">
<Filter>Entities</Filter>
</ClInclude>
<ClInclude Include="Source\LogObstacle.h">
<Filter>Entities</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
Expand All @@ -173,5 +224,6 @@
</ItemGroup>
<ItemGroup>
<Xml Include="..\Output\config.xml" />
<Xml Include="..\Output\save_game.xml" />
</ItemGroup>
</Project>
4 changes: 2 additions & 2 deletions PlatformerGame/Game/Source/Animation.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,12 @@ class Animation
return frames[actualFrame];
}

void LoadAnimations(const char* name)
void LoadAnimations(const char* animationFrame, const char* entity)
{
pugi::xml_parse_result result = animFile.load_file("config.xml");
if (result != NULL)
{
pugi::xml_node animationName = animFile.child("config").child("animations").child(name);
pugi::xml_node animationName = animFile.child("config").child("animations").child(entity).child(animationFrame);
loop = animationName.attribute("loop").as_bool();
speed = animationName.attribute("speed").as_float();
for (pugi::xml_node animation = animationName.child("animation"); animation; animation = animation.next_sibling("animation"))
Expand Down
89 changes: 89 additions & 0 deletions PlatformerGame/Game/Source/App.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "Map.h"
#include "Physics.h"
#include "FadeToBlack.h"
#include "ParticleManager.h"

#include "Defs.h"
#include "Log.h"
Expand Down Expand Up @@ -35,6 +36,7 @@ App::App(int argc, char* args[]) : argc(argc), args(args)
map = new Map();
entityManager = new EntityManager();
fade = new FadeToBlack();
particleManager = new ParticleManager();


// Ordered for awake / Start / Update
Expand All @@ -47,6 +49,7 @@ App::App(int argc, char* args[]) : argc(argc), args(args)
AddModule(scene);
AddModule(map);
AddModule(entityManager);
AddModule(particleManager);
AddModule(fade);

// Render last to swap buffer
Expand Down Expand Up @@ -224,6 +227,16 @@ void App::FinishUpdate()
gameTitle.GetString(), framesPerSecond, averageFps, dt, vsync);

app->win->SetTitle(title);

if (loadRequest) {
loadRequest = false;
LoadFromFile();
}

if (saveRequest) {
saveRequest = false;
SaveFromFile();
}
}

// Call modules before each loop iteration
Expand Down Expand Up @@ -343,3 +356,79 @@ float App::GetDT()
return dt;
}

// Request a save data in an XML file
bool App::LoadRequest() {

bool ret = true;
loadRequest = true;
return ret;
}

// Request to load data from XML file
bool App::SaveRequest() {
bool ret = true;
saveRequest = true;
return true;
}

bool App::LoadFromFile() {

bool ret = true;

pugi::xml_document saveFile;
pugi::xml_parse_result result = saveFile.load_file("save_game.xml");

if (result)
{
LOG("save_game.xml parsed without errors");

// Iterates all modules and call the load of each with the part of the XML node that corresponds to the module
ListItem<Module*>* item;
item = modules.start;

while (item != NULL && ret == true)
{
ret = item->data->LoadState(saveFile.child("game_state").child(item->data->name.GetString()));
item = item->next;
}

}
else
{
LOG("Error loading save_game.xml: %s", result.description());
ret = false;
}



return ret;

}

bool App::SaveFromFile() {

bool ret = true;

pugi::xml_document saveFile;
pugi::xml_node gameState = saveFile.append_child("game_state");

// Iterates all modules and call the save of each with the part of the XML node that corresponds to the module
ListItem<Module*>* item;
item = modules.start;

while (item != NULL && ret == true)
{
pugi::xml_node module = gameState.append_child(item->data->name.GetString());
ret = item->data->SaveState(module);
item = item->next;
}

ret = saveFile.save_file("save_game.xml");

if (ret) LOG("Saved");
else LOG("Error saving game state");

return ret;

}

17 changes: 17 additions & 0 deletions PlatformerGame/Game/Source/App.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class EntityManager;
class Map;
class Physics;
class FadeToBlack;
class ParticleManager;

class App
{
Expand Down Expand Up @@ -53,6 +54,12 @@ class App
const char* GetOrganization() const;
float GetDT();

// Request a save data in an XML file
bool LoadRequest();

// Request to load data from XML file
bool SaveRequest();

private:

// Load config file
Expand All @@ -73,6 +80,12 @@ class App
// Call modules after each loop iteration
bool PostUpdate();

// Reads XML file and loads the data
bool LoadFromFile();

// Sace XML file with modules data
bool SaveFromFile();

public:

// Modules
Expand All @@ -86,11 +99,15 @@ class App
Map* map;
Physics* physics;
FadeToBlack* fade;
ParticleManager* particleManager;

uint32 maxFrameDuration = 16;
uint32 initialMaxFrameDuration = 16;
uint32 capMaxFrameDuration = 32;

bool loadRequest = false;
bool saveRequest = false;

private:

int argc;
Expand Down
18 changes: 18 additions & 0 deletions PlatformerGame/Game/Source/Audio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,4 +175,22 @@ bool Audio::PlayFx(unsigned int id, int repeat)
}

return ret;
}

void Audio::PauseFx(unsigned int id)
{
if (!active)
return;

if (id > 0 && id <= fx.Count())
{
for (int i = 0; i < MIX_CHANNELS; ++i)
{
if (Mix_GetChunk(i) == fx[id - 1] && Mix_Playing(i))
{
Mix_HaltChannel(i);
break;
}
}
}
}
3 changes: 3 additions & 0 deletions PlatformerGame/Game/Source/Audio.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ class Audio : public Module
// Play a previously loaded WAV
bool PlayFx(unsigned int fx, int repeat = 0);

// Pause FX audio
void PauseFx(unsigned int id);

private:

_Mix_Music* music;
Expand Down
Loading

0 comments on commit 6f280e6

Please sign in to comment.