mirror of
https://github.com/sigonasr2/hamster.git
synced 2025-04-22 07:54:24 -05:00
Wrote Animation loading functions.
This commit is contained in:
parent
23523b754d
commit
bc05757b84
44
Hamster.h
Normal file
44
Hamster.h
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
#pragma region License
|
||||||
|
/*
|
||||||
|
License (OLC-3)
|
||||||
|
~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
|
Copyright 2024 Joshua Sigona <sigonasr2@gmail.com>
|
||||||
|
|
||||||
|
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 <vector>
|
||||||
|
|
||||||
|
class Hamster{
|
||||||
|
//static std::vector<Hamster>HAMSTER_LIST;
|
||||||
|
};
|
BIN
assets/hamster.png
Normal file
BIN
assets/hamster.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.2 KiB |
@ -344,6 +344,10 @@ if %errorlevel% neq 0 goto :VCEnd</Command>
|
|||||||
<Text Include="src\TODO.txt" />
|
<Text Include="src\TODO.txt" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<ClInclude Include="Hamster.h">
|
||||||
|
<SubType>
|
||||||
|
</SubType>
|
||||||
|
</ClInclude>
|
||||||
<ClInclude Include="src\HamsterGame.h" />
|
<ClInclude Include="src\HamsterGame.h" />
|
||||||
<ClInclude Include="src\miniaudio.h" />
|
<ClInclude Include="src\miniaudio.h" />
|
||||||
<ClInclude Include="src\olcPGEX_MiniAudio.h" />
|
<ClInclude Include="src\olcPGEX_MiniAudio.h" />
|
||||||
|
@ -52,5 +52,8 @@
|
|||||||
<ClInclude Include="src\olcUTIL_Geometry2D.h">
|
<ClInclude Include="src\olcUTIL_Geometry2D.h">
|
||||||
<Filter>Header Files</Filter>
|
<Filter>Header Files</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
<ClInclude Include="Hamster.h">
|
||||||
|
<Filter>Header Files</Filter>
|
||||||
|
</ClInclude>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
@ -17,25 +17,37 @@ bool HamsterGame::OnUserCreate(){
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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))};
|
||||||
|
}
|
||||||
|
|
||||||
void HamsterGame::LoadGraphics(){
|
void HamsterGame::LoadGraphics(){
|
||||||
|
_LoadImage("border.png");
|
||||||
#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(){
|
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::vector<vf2d>frames,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){
|
bool HamsterGame::OnUserUpdate(float fElapsedTime){
|
||||||
DrawDecal({},GetGFX("border.png").Decal());
|
DrawDecal({},GetGFX("border.png").Decal());
|
||||||
gameWindow.FillRectDecal({},{500.f,150.f},WHITE);
|
gameWindow.FillRectDecal({},{500.f,150.f},WHITE);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -45,7 +45,7 @@ class HamsterGame : public olc::PixelGameEngine
|
|||||||
{
|
{
|
||||||
const static std::string ASSETS_DIR;
|
const static std::string ASSETS_DIR;
|
||||||
public:
|
public:
|
||||||
enum AnimationStates{
|
enum AnimationState{
|
||||||
DEFAULT
|
DEFAULT
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -62,6 +62,7 @@ public:
|
|||||||
private:
|
private:
|
||||||
void LoadGraphics();
|
void LoadGraphics();
|
||||||
void LoadAnimations();
|
void LoadAnimations();
|
||||||
|
void _LoadImage(const std::string_view img);
|
||||||
static std::unordered_map<std::string,Renderable>GFX;
|
static std::unordered_map<std::string,Renderable>GFX;
|
||||||
static std::unordered_map<std::string,Animate2D::Animation<int>>ANIMATIONS;
|
static std::unordered_map<std::string,Animate2D::Animation<int>>ANIMATIONS;
|
||||||
};
|
};
|
Loading…
x
Reference in New Issue
Block a user