diff --git a/2d-game.vcxproj b/2d-game.vcxproj index 04e8f1e17f7196530c57ddd6963da08a019e356f..708539984b27ce468e0dd3a4c7618422fb40df77 100644 --- a/2d-game.vcxproj +++ b/2d-game.vcxproj @@ -145,6 +145,7 @@ <ItemGroup> <ClCompile Include="Entity.cpp" /> <ClCompile Include="game.cpp" /> + <ClCompile Include="GameException.cpp" /> <ClCompile Include="LazySprite.cpp" /> <ClCompile Include="mainGame.cpp" /> <ClCompile Include="ResourceManager.cpp" /> @@ -154,6 +155,7 @@ </ItemGroup> <ItemGroup> <ClInclude Include="DynamicArray.hpp" /> + <ClInclude Include="GameException.h" /> <ClInclude Include="mainGame.h" /> <ClInclude Include="olc.h" /> <ClInclude Include="ITexture.h" /> diff --git a/2d-game.vcxproj.filters b/2d-game.vcxproj.filters index e0fb5b216e1478cd6f5a616d7cf8bbd75fd51ddc..044c2c58f4c55be300e9e54a18e61f8d71f6b502 100644 --- a/2d-game.vcxproj.filters +++ b/2d-game.vcxproj.filters @@ -56,6 +56,9 @@ <ClCompile Include="WallTexture.cpp"> <Filter>Source Files\gameObj</Filter> </ClCompile> + <ClCompile Include="GameException.cpp"> + <Filter>Source Files</Filter> + </ClCompile> </ItemGroup> <ItemGroup> <ClInclude Include="interfaces.h"> @@ -100,6 +103,9 @@ <ClInclude Include="WallTexture.h"> <Filter>Header Files\gameObj\render</Filter> </ClInclude> + <ClInclude Include="GameException.h"> + <Filter>Header Files</Filter> + </ClInclude> </ItemGroup> <ItemGroup> <None Include="README.md"> diff --git a/ClassDiagram.cd b/ClassDiagram.cd index 83351edbdd5d8341148138125b4127761ae9c243..e8e778608faf36479d5eb641d12ed924fceb2fcb 100644 --- a/ClassDiagram.cd +++ b/ClassDiagram.cd @@ -1,7 +1,7 @@ <?xml version="1.0" encoding="utf-8"?> <ClassDiagram MajorVersion="1" MinorVersion="1"> <Class Name="DynamicArray<T>" Collapsed="true"> - <Position X="9.5" Y="11.5" Width="1.5" /> + <Position X="8.5" Y="10" Width="1.5" /> <TypeIdentifier> <HashCode>AAAAAAACAAAAAAAEAAAggQBQAAAAAAAAAAAAAAIAAAA=</HashCode> <FileName>DynamicArray.hpp</FileName> @@ -10,12 +10,12 @@ <Class Name="GameClient" Collapsed="true"> <Position X="1" Y="10" Width="1.5" /> <TypeIdentifier> - <HashCode>AgAAAAAAABAAAAAAAAEABAAAAABAAQQACAAAAAAAAAA=</HashCode> + <HashCode>AgAAAAAAABAAAAAQAAEABAAAAABAAQQACAAAAAgAAAA=</HashCode> <FileName>mainGame.h</FileName> </TypeIdentifier> </Class> <Class Name="render::IRenderable" Collapsed="true"> - <Position X="9.75" Y="12.5" Width="1.5" /> + <Position X="8.5" Y="11.25" Width="1.5" /> <TypeIdentifier> <HashCode>AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQAAA=</HashCode> <FileName>interfaces.h</FileName> @@ -29,14 +29,14 @@ </TypeIdentifier> </Class> <Class Name="render::LazySprite" Collapsed="true"> - <Position X="7.75" Y="10.75" Width="1.5" /> + <Position X="6.75" Y="10" Width="1.5" /> <TypeIdentifier> <HashCode>AAAAAAAIAAAAAAAAAAAAAAgAABAAAAAAQAAAAAAwAAA=</HashCode> <FileName>LazySprite.h</FileName> </TypeIdentifier> </Class> <Class Name="render::SpriteManager" Collapsed="true"> - <Position X="7.75" Y="11.75" Width="1.5" /> + <Position X="6.75" Y="11.25" Width="1.5" /> <TypeIdentifier> <HashCode>AAAAABAAAAAAAAAAABAAAAAAAAIAAAAAAAAABAAAAAA=</HashCode> <FileName>ResourceManager.h</FileName> diff --git a/GameException.cpp b/GameException.cpp new file mode 100644 index 0000000000000000000000000000000000000000..610d242aedaff4e19b685ec1476f2bbdb900c9f9 --- /dev/null +++ b/GameException.cpp @@ -0,0 +1,4 @@ +#include "GameException.h" + +GameException::GameException(const std::string& description, entities::Entity& entity) + : runtime_error(description), affectedEntity(entity) {} diff --git a/GameException.h b/GameException.h new file mode 100644 index 0000000000000000000000000000000000000000..d7a2d0caf4ac3f855c26db3c34f85abf1dde665c --- /dev/null +++ b/GameException.h @@ -0,0 +1,17 @@ +#pragma once +#include <stdexcept> + +namespace entities +{ + class Entity; +} + +class GameException : + public std::runtime_error +{ +private: + entities::Entity& affectedEntity; +public: + GameException(const std::string& description, entities::Entity& entity); +}; + diff --git a/RenderException.cpp b/RenderException.cpp new file mode 100644 index 0000000000000000000000000000000000000000..0517d34500975717ee1300cca3fdd731e427a777 --- /dev/null +++ b/RenderException.cpp @@ -0,0 +1 @@ +#include "RenderException.h" diff --git a/RenderException.h b/RenderException.h new file mode 100644 index 0000000000000000000000000000000000000000..8f65f38a06248a8ad65ec15c79d472b2b8cb606a --- /dev/null +++ b/RenderException.h @@ -0,0 +1,5 @@ +#pragma once +class RenderException +{ +}; + diff --git a/WallTexture.cpp b/WallTexture.cpp index d03cd23f297b1c728ee6b2d295c8ec812a289682..30e0ffece307af29427d269a5446f7dbeb9ed35b 100644 --- a/WallTexture.cpp +++ b/WallTexture.cpp @@ -1,5 +1,6 @@ #include "WallTexture.h" #include "WallEntity.h" +#include "GameException.h" using namespace olc; using namespace entities; @@ -13,7 +14,7 @@ namespace render void WallTexture::render(olc::TransformedView& scene, Entity& entity) { if(entity.getAsWallEntity() == nullptr){ - throw std::invalid_argument("Wall texture needs a wall entity"); + throw GameException("Wall texture needs a wall entity", entity); } WallEntity& wallEntity = *entity.getAsWallEntity(); vf2d offset = this->baseOffset; diff --git a/mainGame.cpp b/mainGame.cpp index bcba77c3f2dd99cc0dfbece2a24c2ed81029ad75..031fc3d644cad7263e82ffe44385c41d9beda3ce 100644 --- a/mainGame.cpp +++ b/mainGame.cpp @@ -65,11 +65,14 @@ bool GameClient::OnUserUpdate(float fElapsedTime) TransformedView scene; - scene.Initialise() - + scene.Initialise(this->viewArea, this->viewScale); + for(auto& entity : entities){ // I literally add entities to the scene :D - scene += entity; + try { + scene += entity; + } + catch () } return true; diff --git a/mainGame.h b/mainGame.h index dd138ab0cf4138405936502bf118a19bef65f73c..863ab4014b5c49a521a843d31ef04a25d60d52a8 100644 --- a/mainGame.h +++ b/mainGame.h @@ -13,6 +13,8 @@ private: static GameClient& createInstance(); //I want it to me a singleton, but I don't want to let anything init this friend int main(int, char* []); + olc::vf2d viewArea = {0, 0}; + olc::vf2d viewScale; public: static GameClient& getInstance();