diff --git a/Hamster.h b/Hamster.h new file mode 100644 index 0000000..fb4e9ce --- /dev/null +++ b/Hamster.h @@ -0,0 +1,44 @@ +#pragma region License +/* +License (OLC-3) +~~~~~~~~~~~~~~~ + +Copyright 2024 Joshua Sigona + +Redistribution and use in source and binary forms, with or without modification, +are permitted provided that the following conditions are met: + +1. Redistributions or derivations of source code must retain the above copyright +notice, this list of conditions and the following disclaimer. + +2. Redistributions or derivative works in binary form must reproduce the above +copyright notice. This list of conditions and the following disclaimer must be +reproduced in the documentation and/or other materials provided with the distribution. + +3. Neither the name of the copyright holder nor the names of its contributors may +be used to endorse or promote products derived from this software without specific +prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY +EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES +OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT +SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED +TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR +BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +SUCH DAMAGE. + +Portions of this software are copyright © 2024 The FreeType +Project (www.freetype.org). Please see LICENSE_FT.txt for more information. +All rights reserved. +*/ +#pragma endregion +#pragma once + +#include + +class Hamster{ + //static std::vectorHAMSTER_LIST; +}; \ No newline at end of file diff --git a/assets/hamster.png b/assets/hamster.png new file mode 100644 index 0000000..af6ff59 Binary files /dev/null and b/assets/hamster.png differ diff --git a/hamster.vcxproj b/hamster.vcxproj index ac195f0..6fa01d8 100644 --- a/hamster.vcxproj +++ b/hamster.vcxproj @@ -344,6 +344,10 @@ if %errorlevel% neq 0 goto :VCEnd + + + + diff --git a/hamster.vcxproj.filters b/hamster.vcxproj.filters index d1d8d33..8f2c85d 100644 --- a/hamster.vcxproj.filters +++ b/hamster.vcxproj.filters @@ -52,5 +52,8 @@ Header Files + + Header Files + \ No newline at end of file diff --git a/src/HamsterGame.cpp b/src/HamsterGame.cpp index 19b28aa..47a05a5 100644 --- a/src/HamsterGame.cpp +++ b/src/HamsterGame.cpp @@ -17,25 +17,37 @@ bool HamsterGame::OnUserCreate(){ 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))}; - }; +void HamsterGame::_LoadImage(const 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::LoadGraphics(){ + _LoadImage("border.png"); } void HamsterGame::LoadAnimations(){ - + auto LoadStillAnimation=[this](const AnimationState state,const std::string_view img){ + Animate2D::FrameSequence stillAnimation{0.f,Animate2D::Style::OneShot}; + if(!GFX.count(ASSETS_DIR+std::string(img)))_LoadImage(img); + stillAnimation.AddFrame(Animate2D::Frame{&GetGFX(img),{{},GetGFX(img).Sprite()->Size()}}); + ANIMATIONS[ASSETS_DIR+std::string(img)].AddState(state,stillAnimation); + }; + auto LoadAnimation=[this](const AnimationState state,const std::string_view img,const std::vectorframes,const float frameDuration=0.1f,const Animate2D::Style style=Animate2D::Style::Repeat,vf2d frameSize={32,32}){ + Animate2D::FrameSequence stillAnimation{0.f,Animate2D::Style::OneShot}; + if(!GFX.count(ASSETS_DIR+std::string(img)))_LoadImage(img); + stillAnimation.AddFrame(Animate2D::Frame{&GetGFX(img),{{},GetGFX(img).Sprite()->Size()}}); + ANIMATIONS[ASSETS_DIR+std::string(img)].AddState(state,stillAnimation); + }; + + LoadAnimation(DEFAULT,"hamster.png",{{},{0,32}},0.3f); } bool HamsterGame::OnUserUpdate(float fElapsedTime){ DrawDecal({},GetGFX("border.png").Decal()); gameWindow.FillRectDecal({},{500.f,150.f},WHITE); + return true; } diff --git a/src/HamsterGame.h b/src/HamsterGame.h index de4b33c..ffe76f5 100644 --- a/src/HamsterGame.h +++ b/src/HamsterGame.h @@ -45,7 +45,7 @@ class HamsterGame : public olc::PixelGameEngine { const static std::string ASSETS_DIR; public: - enum AnimationStates{ + enum AnimationState{ DEFAULT }; @@ -62,6 +62,7 @@ public: private: void LoadGraphics(); void LoadAnimations(); + void _LoadImage(const std::string_view img); static std::unordered_mapGFX; static std::unordered_map>ANIMATIONS; }; \ No newline at end of file