Add border image + setup asset loading and animation loading for images.

main
sigonasr2 4 months ago
parent e6ba1e88c7
commit 593841971d
  1. 3
      .gitignore
  2. 8
      ALL_BUILD.vcxproj
  3. 4
      ALL_BUILD.vcxproj.user
  4. 6
      CMakeCache.txt
  5. 0
      New Text Document.txt
  6. 8
      ZERO_CHECK.vcxproj
  7. BIN
      assets/border.png
  8. BIN
      assets/border.xcf
  9. BIN
      assets/gfx/space.png
  10. BIN
      assets/sounds/Explosions1.wav
  11. BIN
      assets/sounds/Laser_Shoot11.wav
  12. BIN
      assets/sounds/bg-music.wav
  13. BIN
      assets/sounds/lose9.wav
  14. BIN
      assets/sounds/thruster.wav
  15. BIN
      bin/hamster.exe
  16. BIN
      bin/hamster.pdb
  17. 232
      copy_data.vcxproj
  18. 14
      copy_data.vcxproj.filters
  19. 4
      copy_data.vcxproj.user
  20. 36
      hamster.vcxproj
  21. 42
      hamster.vcxproj.filters
  22. 38
      src/HamsterGame.cpp
  23. 12
      src/HamsterGame.h
  24. 2
      src/olcUTIL_Animate2D.h

3
.gitignore vendored

@ -11,3 +11,6 @@ vs-build
/CMakeFiles /CMakeFiles
/hamster.dir/Debug /hamster.dir/Debug
/x64/Debug /x64/Debug
/bin/assets
/bin/hamster.exe
/bin/hamster.pdb

File diff suppressed because one or more lines are too long

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup />
</Project>

@ -154,10 +154,10 @@ CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO:STRING=/debug /INCREMENTAL
//If set, runtime paths are not added when installing shared libraries, //If set, runtime paths are not added when installing shared libraries,
// but are added when building. // but are added when building.
CMAKE_SKIP_INSTALL_RPATH:BOOL=NO CMAKE_SKIP_INSTALL_RPATH:BOOL=OFF
//If set, runtime paths are not added when using shared libraries. //If set, runtime paths are not added when using shared libraries.
CMAKE_SKIP_RPATH:BOOL=NO CMAKE_SKIP_RPATH:BOOL=OFF
//Flags used by the linker during the creation of static libraries //Flags used by the linker during the creation of static libraries
// during all build types. // during all build types.
@ -183,7 +183,7 @@ CMAKE_STATIC_LINKER_FLAGS_RELWITHDEBINFO:STRING=
// .SILENT directive, and all commands will be echoed to the console // .SILENT directive, and all commands will be echoed to the console
// during the make. This is useful for debugging only. With Visual // during the make. This is useful for debugging only. With Visual
// Studio IDE projects all commands are done without /nologo. // Studio IDE projects all commands are done without /nologo.
CMAKE_VERBOSE_MAKEFILE:BOOL=FALSE CMAKE_VERBOSE_MAKEFILE:BOOL=OFF
//Show a terminal window for STDOUT/STDERR //Show a terminal window for STDOUT/STDERR
HAS_TERMINAL:BOOL=ON HAS_TERMINAL:BOOL=ON

File diff suppressed because one or more lines are too long

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.9 KiB

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 45 KiB

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

File diff suppressed because one or more lines are too long

@ -2,14 +2,16 @@
<Project ToolsVersion="17.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <Project ToolsVersion="17.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup> <ItemGroup>
<CustomBuild Include="C:\Users\sigon\source\repos\hamster\assets\.keepme" /> <CustomBuild Include="C:\Users\sigon\source\repos\hamster\assets\.keepme" />
<CustomBuild Include="C:\Users\sigon\source\repos\hamster\assets\gfx\space.png"> <CustomBuild Include="C:\Users\sigon\source\repos\hamster\assets\border.png">
<Filter>Resources</Filter>
</CustomBuild>
<CustomBuild Include="C:\Users\sigon\source\repos\hamster\assets\border.xcf" />
<CustomBuild Include="C:\Users\sigon\source\repos\hamster\assets\gametiles.png">
<Filter>Resources</Filter>
</CustomBuild>
<CustomBuild Include="C:\Users\sigon\source\repos\hamster\assets\toybox32-1x.png">
<Filter>Resources</Filter> <Filter>Resources</Filter>
</CustomBuild> </CustomBuild>
<CustomBuild Include="C:\Users\sigon\source\repos\hamster\assets\sounds\Explosions1.wav" />
<CustomBuild Include="C:\Users\sigon\source\repos\hamster\assets\sounds\Laser_Shoot11.wav" />
<CustomBuild Include="C:\Users\sigon\source\repos\hamster\assets\sounds\bg-music.wav" />
<CustomBuild Include="C:\Users\sigon\source\repos\hamster\assets\sounds\lose9.wav" />
<CustomBuild Include="C:\Users\sigon\source\repos\hamster\assets\sounds\thruster.wav" />
<CustomBuild Include="C:\Users\sigon\source\repos\hamster\CMakeFiles\842494a5b997e5d0cebd893a59fb5c26\copy_data.rule"> <CustomBuild Include="C:\Users\sigon\source\repos\hamster\CMakeFiles\842494a5b997e5d0cebd893a59fb5c26\copy_data.rule">
<Filter>CMake Rules</Filter> <Filter>CMake Rules</Filter>
</CustomBuild> </CustomBuild>

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup />
</Project>

File diff suppressed because one or more lines are too long

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="17.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <Project ToolsVersion="17.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup> <ItemGroup>
<ClCompile Include="src\HamsterGame.cpp"> <ClCompile Include="C:\Users\sigon\source\repos\hamster\src\HamsterGame.cpp">
<Filter>Source Files</Filter> <Filter>Source Files</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="C:\Users\sigon\source\repos\hamster\src\olcPGEX_MiniAudio.cpp"> <ClCompile Include="C:\Users\sigon\source\repos\hamster\src\olcPGEX_MiniAudio.cpp">
@ -18,45 +18,5 @@
<Filter Include="Source Files"> <Filter Include="Source Files">
<UniqueIdentifier>{6FA4D8BB-23B0-3494-9ED3-B7DCE970FEDF}</UniqueIdentifier> <UniqueIdentifier>{6FA4D8BB-23B0-3494-9ED3-B7DCE970FEDF}</UniqueIdentifier>
</Filter> </Filter>
<Filter Include="Header Files">
<UniqueIdentifier>{7d02a2cb-d3b1-4576-813d-9a586e6aedd3}</UniqueIdentifier>
</Filter>
<Filter Include="Documentation">
<UniqueIdentifier>{ecbaa59b-6b75-4ab7-ab55-985bbd1e800c}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<ClInclude Include="src\miniaudio.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="src\olcPGEX_MiniAudio.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="src\olcPixelGameEngine.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="olcUTIL_Geometry2D.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="src\olcPGEX_ViewPort.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="src\olcUTIL_Geometry2D.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="src\HamsterGame.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="src\olcUTIL_Animate2D.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<Text Include="src\TODO.txt">
<Filter>Documentation</Filter>
</Text>
<Text Include="src\CREDITS.txt">
<Filter>Documentation</Filter>
</Text>
</ItemGroup> </ItemGroup>
</Project> </Project>

@ -1,6 +1,10 @@
#include "HamsterGame.h" #include "HamsterGame.h"
#include <stdexcept>
geom2d::rect<float>HamsterGame::SCREEN_FRAME{{96,0},{320,288}}; geom2d::rect<float>HamsterGame::SCREEN_FRAME{{96,0},{320,288}};
std::unordered_map<std::string,Animate2D::Animation<int>>HamsterGame::ANIMATIONS;
std::unordered_map<std::string,Renderable>HamsterGame::GFX;
const std::string HamsterGame::ASSETS_DIR{"assets/"};
HamsterGame::HamsterGame() HamsterGame::HamsterGame()
{ {
@ -8,22 +12,48 @@ HamsterGame::HamsterGame()
} }
bool HamsterGame::OnUserCreate(){ bool HamsterGame::OnUserCreate(){
LoadGraphics();
LoadAnimations(); LoadAnimations();
return true; return true;
} }
void HamsterGame::LoadGraphics(){
#undef LoadImage
auto LoadImage=[this](std::string_view img){
GFX.insert({ASSETS_DIR+std::string(img),Renderable{}});
rcode result{GFX[ASSETS_DIR+std::string(img)].Load(ASSETS_DIR+std::string(img))};
if(result!=OK)throw std::runtime_error{std::format("Failed to Load Image {}. OLC Rcode: {}",img,int(result))};
};
LoadImage("border.png");
}
void HamsterGame::LoadAnimations(){
}
bool HamsterGame::OnUserUpdate(float fElapsedTime){ bool HamsterGame::OnUserUpdate(float fElapsedTime){
DrawDecal({}, DrawDecal({},GetGFX("border.png").Decal());
gameWindow.FillRectDecal({},{150.f,150.f},WHITE); gameWindow.FillRectDecal({},{500.f,150.f},WHITE);
return true; return true;
} }
bool HamsterGame::OnUserDestroy(){ const Renderable&HamsterGame::GetGFX(const std::string_view img){
if(!GFX.count(ASSETS_DIR+std::string(img)))throw std::runtime_error{std::format("Image {} does not exist!",img)};
return GFX[ASSETS_DIR+std::string(img)];
}
const Animate2D::Animation<int>&HamsterGame::GetAnimations(const std::string_view img){
if(!ANIMATIONS.count(ASSETS_DIR+std::string(img)))throw std::runtime_error{std::format("Animations for {} does not exist!",img)};
return ANIMATIONS[ASSETS_DIR+std::string(img)];
}
bool HamsterGame::OnUserDestroy(){
ANIMATIONS.clear();
GFX.clear();
return true; return true;
} }
int main() int main()
{ {
HamsterGame game; HamsterGame game;

@ -43,15 +43,25 @@ All rights reserved.
class HamsterGame : public olc::PixelGameEngine class HamsterGame : public olc::PixelGameEngine
{ {
const static std::string ASSETS_DIR;
public: public:
enum AnimationStates{
DEFAULT
};
HamsterGame(); HamsterGame();
static geom2d::rect<float>SCREEN_FRAME; static geom2d::rect<float>SCREEN_FRAME;
static std::unordered_map<std::string,Animate2D::Animation<int>>ANIMATIONS;
const ViewPort gameWindow{{SCREEN_FRAME.pos,SCREEN_FRAME.pos+vf2d{0.f,SCREEN_FRAME.size.y},SCREEN_FRAME.pos+SCREEN_FRAME.size,SCREEN_FRAME.pos+vf2d{SCREEN_FRAME.size.x,0.f}},{96,0}}; const ViewPort gameWindow{{SCREEN_FRAME.pos,SCREEN_FRAME.pos+vf2d{0.f,SCREEN_FRAME.size.y},SCREEN_FRAME.pos+SCREEN_FRAME.size,SCREEN_FRAME.pos+vf2d{SCREEN_FRAME.size.x,0.f}},{96,0}};
public: public:
bool OnUserCreate()override final; bool OnUserCreate()override final;
bool OnUserUpdate(float fElapsedTime)override final; bool OnUserUpdate(float fElapsedTime)override final;
bool OnUserDestroy()override final; bool OnUserDestroy()override final;
static const Renderable&GetGFX(const std::string_view img);
static const Animate2D::Animation<int>&GetAnimations(const std::string_view img);
private: private:
void LoadGraphics();
void LoadAnimations(); void LoadAnimations();
static std::unordered_map<std::string,Renderable>GFX;
static std::unordered_map<std::string,Animate2D::Animation<int>>ANIMATIONS;
}; };

@ -59,7 +59,7 @@
#pragma once #pragma once
#include "olcPixelGameEngine.h" #include "olcPixelGameEngine.h"
#include "utilities/olcUTIL_Geometry2D.h" #include "olcUTIL_Geometry2D.h"
#include <unordered_map> #include <unordered_map>
namespace olc::utils::Animate2D namespace olc::utils::Animate2D

Loading…
Cancel
Save