diff --git a/assets/HamsterGame.tiled-session b/assets/HamsterGame.tiled-session index 4ca9167..5c6725c 100644 --- a/assets/HamsterGame.tiled-session +++ b/assets/HamsterGame.tiled-session @@ -8,6 +8,7 @@ ], "fileStates": { }, + "frame.defaultDuration": 200, "last.imagePath": "C:/Users/sigon/source/repos/hamster/assets", "map.lastUsedFormat": "tmx", "openFiles": [ diff --git a/assets/Terrain.tsx b/assets/Terrain.tsx index 4e940f7..f18dcb0 100644 --- a/assets/Terrain.tsx +++ b/assets/Terrain.tsx @@ -6,6 +6,31 @@ + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/assets/TestLevel.tmx b/assets/TestLevel.tmx index 2a5c67d..3fb979c 100644 --- a/assets/TestLevel.tmx +++ b/assets/TestLevel.tmx @@ -16,13 +16,13 @@ 1235,1153,1154,1234,1207,1234,494,1177,494,494,494,494,494,494,1021,298,1021,298,1051,1137,1138,1106,993,1021,1110,1134,1138,1022,1109,1082, 1181,1179,1266,1178,1182,1234,494,494,494,1149,494,1179,1181,494,1051,1136,1137,1137,1138,1022,1025,1109,993,993,1110,1022,1026,1134,1137,1138, 1234,1235,1151,1237,1266,1209,1149,1179,1180,1180,1263,1266,1209,494,1107,1108,1108,1108,1108,1109,993,1021,1080,298,1107,1109,1107,1108,1108,1108, -1206,1149,1121,1238,1266,1262,1264,1266,1150,1236,1153,1236,1237,494,494,494,494,494,494,494,494,494,494,494,494,494,494,494,494,494, -1209,494,1177,1210,1150,1153,1152,1154,1206,494,494,494,494,494,1121,1121,1149,1179,1180,1181,1207,1206,1177,1121,494,494,1149,494,494,1121, -1209,494,1177,1235,1237,1121,1177,1207,1234,1149,1121,494,494,1177,494,494,1149,1235,1154,1206,1235,1237,1179,1181,494,494,494,494,494,1149, -1178,494,494,494,1121,494,1121,1238,1209,494,494,494,494,494,1149,494,1121,494,1182,1262,1263,1265,1266,1209,494,494,494,494,1179,1264, -1237,1149,1177,494,494,494,494,1238,1178,494,1121,1179,1265,1265,1180,1181,494,1121,1235,1151,1154,1150,1154,1206,1149,494,494,1149,1235,1152, -494,1121,1149,1121,494,1149,1179,1266,1206,494,1177,1207,1150,1236,1151,1237,494,1177,1121,494,1238,1234,1235,1237,494,494,494,494,494,1149, -494,494,494,494,494,494,1235,1154,1234,1179,1263,1266,1209,1121,494,1177,494,1149,1177,494,1210,1209,494,1177,494,494,1149,1121,1121,494 +1206,1149,1121,1238,1266,1262,1264,1266,1150,1328,1328,1328,1328,1328,1328,1328,1328,1328,1328,494,494,494,494,494,494,494,494,494,494,494, +1209,494,1177,1210,1150,1153,1152,1154,1206,1328,1352,1381,1381,1381,1381,1381,1381,1354,1328,1181,1207,1051,1135,1136,1137,1053,1149,494,494,1121, +1209,494,1177,1235,1237,1121,1177,1207,1234,1328,1380,1385,1385,1385,1385,1385,1385,1382,1328,1386,1386,1054,1413,1413,1413,1081,494,494,494,1149, +1178,494,494,494,1121,494,1121,1238,1209,1328,1380,1385,1385,1385,1385,1385,1385,1382,1328,1386,1386,1082,1413,1413,1413,1081,494,494,1179,1264, +1237,1149,1177,494,494,494,494,1238,1178,1328,1380,1385,1385,1385,1385,1385,1385,1382,1328,1386,1386,1110,1413,1413,1413,1081,494,1149,1235,1152, +494,1121,1149,1121,494,1149,1179,1266,1206,1328,1408,1381,1381,1381,1381,1381,1381,1410,1328,494,1238,1107,1108,1108,1108,1109,494,494,494,1149, +494,494,494,494,494,494,1235,1154,1234,1328,1328,1328,1328,1328,1328,1328,1328,1328,1328,494,1210,1209,494,1177,494,494,1149,1121,1121,494 diff --git a/assets/gametiles.png b/assets/gametiles.png index 9027707..524a9fe 100644 Binary files a/assets/gametiles.png and b/assets/gametiles.png differ diff --git a/src/HamsterGame.cpp b/src/HamsterGame.cpp index a2d119e..14625d7 100644 --- a/src/HamsterGame.cpp +++ b/src/HamsterGame.cpp @@ -8,6 +8,7 @@ std::unordered_map std::unordered_mapHamsterGame::GFX; const std::string HamsterGame::ASSETS_DIR{"assets/"}; PixelGameEngine*HamsterGame::self{nullptr}; +std::unordered_mapHamsterGame::ANIMATED_TILE_IDS; HamsterGame::HamsterGame(){ sAppName = "Project Hamster"; @@ -56,6 +57,14 @@ void HamsterGame::LoadAnimations(){ }; LoadAnimation(DEFAULT,"hamster.png",{{0,32},{32,32}},0.3f); + Animate2D::FrameSequence&waterAnimFrames{(*ANIMATED_TILE_IDS.insert({1384,Animate2D::FrameSequence{0.2f}}).first).second}; + for(vf2d&sourcePos:std::vector{{192+16*0,784},{192+16*1,784},{192+16*2,784},{192+16*3,784},{192+16*4,784},{192+16*5,784},{192+16*6,784},{192+16*7,784}}){ + waterAnimFrames.AddFrame(Animate2D::Frame{&GetGFX("gametiles.png"),{sourcePos,{16,16}}}); + } + Animate2D::FrameSequence&lavaAnimFrames{(*ANIMATED_TILE_IDS.insert({1412,Animate2D::FrameSequence{0.2f}}).first).second}; + for(vf2d&sourcePos:std::vector{{192+16*0,800},{192+16*1,800},{192+16*2,800},{192+16*3,800},{192+16*4,800},{192+16*5,800},{192+16*6,800},{192+16*7,800},{192+16*8,800}}){ + lavaAnimFrames.AddFrame(Animate2D::Frame{&GetGFX("gametiles.png"),{sourcePos,{16,16}}}); + } } void HamsterGame::LoadLevel(const std::string_view mapName){ @@ -93,12 +102,19 @@ void HamsterGame::DrawLevelTiles(){ int imgTileX{tileID%numTilesWide}; int imgTileY{tileID/numTilesWide}; - tv.DrawPartialDecal(vf2d{float(tileX),float(tileY)}*16,GetGFX("gametiles.png").Decal(),vf2d{float(imgTileX),float(imgTileY)}*16,{16,16}); + if(ANIMATED_TILE_IDS.count(tileID)){ + Animate2D::FrameSequence&animatedTile{ANIMATED_TILE_IDS[tileID]}; + const Animate2D::Frame¤tFrame{animatedTile.GetFrame(runTime)}; + tv.DrawPartialDecal(vf2d{float(tileX),float(tileY)}*16,currentFrame.GetSourceImage()->Decal(),currentFrame.GetSourceRect().pos,currentFrame.GetSourceRect().size); + }else{ + tv.DrawPartialDecal(vf2d{float(tileX),float(tileY)}*16,GetGFX("gametiles.png").Decal(),vf2d{float(imgTileX),float(imgTileY)}*16,{16,16}); + } } } } bool HamsterGame::OnUserUpdate(float fElapsedTime){ + runTime+=fElapsedTime; UpdateGame(fElapsedTime); DrawGame(); return true; @@ -123,6 +139,10 @@ PixelGameEngine&HamsterGame::Game(){ return *self; } +const double HamsterGame::GetRuntime()const{ + return runTime; +} + int main() { HamsterGame game; diff --git a/src/HamsterGame.h b/src/HamsterGame.h index e230d75..5879d93 100644 --- a/src/HamsterGame.h +++ b/src/HamsterGame.h @@ -49,7 +49,7 @@ class HamsterGame : public olc::PixelGameEngine const static std::string ASSETS_DIR; public: enum AnimationState{ - DEFAULT + DEFAULT, }; HamsterGame(); @@ -63,6 +63,8 @@ public: static const Renderable&GetGFX(const std::string_view img); static const Animate2D::Animation&GetAnimations(const std::string_view img); static PixelGameEngine&Game(); + static std::unordered_mapANIMATED_TILE_IDS; + const double GetRuntime()const; private: void UpdateGame(const float fElapsedTime); void DrawGame(); @@ -77,4 +79,5 @@ private: Border border; void DrawLevelTiles(); std::optionalcurrentMap; + double runTime{}; }; \ No newline at end of file diff --git a/src/TODO.txt b/src/TODO.txt index df70236..94a8802 100644 --- a/src/TODO.txt +++ b/src/TODO.txt @@ -1,2 +1,11 @@ +Walkways - 100% +Grass - 80% +Sand - 60% +Swamp - 50%, after 5 seconds: Hamster sinks and respawns. +Lava - Hamster melts (*dies*) and respawns. +Water - +Hamster Wheel - Enhances Speed + +============================ olcPGEX_ViewPort - Submit a PR where the offset is subtracted instead of added to determine clip region cutoffs. \ No newline at end of file diff --git a/src/olcPixelGameEngine.h b/src/olcPixelGameEngine.h index 9fe62ff..c7fbb7c 100644 --- a/src/olcPixelGameEngine.h +++ b/src/olcPixelGameEngine.h @@ -2855,8 +2855,8 @@ namespace olc di.decal = decal; di.tint = { tint, tint, tint, tint }; di.pos = { { vQuantisedPos.x, vQuantisedPos.y }, { vQuantisedPos.x, vQuantisedDim.y }, { vQuantisedDim.x, vQuantisedDim.y }, { vQuantisedDim.x, vQuantisedPos.y } }; - olc::vf2d uvtl = (source_pos + olc::vf2d(0.0001f, 0.0001f)) * decal->vUVScale; - olc::vf2d uvbr = (source_pos + source_size - olc::vf2d(0.0001f, 0.0001f)) * decal->vUVScale; + olc::vf2d uvtl = (source_pos + olc::vf2d(0.01f, 0.01f)) * decal->vUVScale; + olc::vf2d uvbr = uvtl + ((source_size - olc::vf2d(0.02f, 0.02f)) * decal->vUVScale); di.uv = { { uvtl.x, uvtl.y }, { uvtl.x, uvbr.y }, { uvbr.x, uvbr.y }, { uvbr.x, uvtl.y } }; di.w = { 1,1,1,1 }; di.mode = nDecalMode; @@ -2883,8 +2883,8 @@ namespace olc di.decal = decal; di.tint = { tint, tint, tint, tint }; di.pos = { { vScreenSpacePos.x, vScreenSpacePos.y }, { vScreenSpacePos.x, vScreenSpaceDim.y }, { vScreenSpaceDim.x, vScreenSpaceDim.y }, { vScreenSpaceDim.x, vScreenSpacePos.y } }; - olc::vf2d uvtl = (source_pos) * decal->vUVScale; - olc::vf2d uvbr = uvtl + ((source_size) * decal->vUVScale); + olc::vf2d uvtl = (source_pos + olc::vf2d(0.02f, 0.02f)) * decal->vUVScale; + olc::vf2d uvbr = (source_pos + source_size - olc::vf2d(0.03f, 0.03f)) * decal->vUVScale; di.uv = { { uvtl.x, uvtl.y }, { uvtl.x, uvbr.y }, { uvbr.x, uvbr.y }, { uvbr.x, uvtl.y } }; di.w = { 1,1,1,1 }; di.mode = nDecalMode; diff --git a/src/olcUTIL_Animate2D.h b/src/olcUTIL_Animate2D.h index c1d29f9..580b68f 100644 --- a/src/olcUTIL_Animate2D.h +++ b/src/olcUTIL_Animate2D.h @@ -124,7 +124,7 @@ namespace olc::utils::Animate2D } // Returns a Frame Object for a given time into an animation - inline const Frame& GetFrame(const float fTime) const + inline const Frame& GetFrame(const double fTime) const { return m_vFrames[ConvertTimeToFrame(fTime)]; } @@ -135,7 +135,7 @@ namespace olc::utils::Animate2D float m_fFrameDuration = 0.1f; float m_fFrameRate = 10.0f; - inline const size_t ConvertTimeToFrame(const float fTime) const + inline const size_t ConvertTimeToFrame(const double fTime) const { switch (m_nStyle) {