Added animated water and lava tiles.

main
sigonasr2 3 months ago
parent 506b5f99ae
commit 4be0ebc161
  1. 1
      assets/HamsterGame.tiled-session
  2. 25
      assets/Terrain.tsx
  3. 14
      assets/TestLevel.tmx
  4. BIN
      assets/gametiles.png
  5. 20
      src/HamsterGame.cpp
  6. 5
      src/HamsterGame.h
  7. 9
      src/TODO.txt
  8. 8
      src/olcPixelGameEngine.h
  9. 4
      src/olcUTIL_Animate2D.h

@ -8,6 +8,7 @@
],
"fileStates": {
},
"frame.defaultDuration": 200,
"last.imagePath": "C:/Users/sigon/source/repos/hamster/assets",
"map.lastUsedFormat": "tmx",
"openFiles": [

@ -6,6 +6,31 @@
<tile id="1148" probability="4"/>
<tile id="1176" probability="4"/>
<tile id="1207" probability="10"/>
<tile id="1384">
<animation>
<frame tileid="1384" duration="200"/>
<frame tileid="1385" duration="200"/>
<frame tileid="1386" duration="200"/>
<frame tileid="1387" duration="200"/>
<frame tileid="1388" duration="200"/>
<frame tileid="1389" duration="200"/>
<frame tileid="1390" duration="200"/>
<frame tileid="1391" duration="200"/>
</animation>
</tile>
<tile id="1412">
<animation>
<frame tileid="1412" duration="200"/>
<frame tileid="1413" duration="200"/>
<frame tileid="1414" duration="200"/>
<frame tileid="1415" duration="200"/>
<frame tileid="1416" duration="200"/>
<frame tileid="1417" duration="200"/>
<frame tileid="1418" duration="200"/>
<frame tileid="1419" duration="200"/>
<frame tileid="1420" duration="200"/>
</animation>
</tile>
<wangsets>
<wangset name="Sand" type="corner" tile="-1">
<wangcolor name="Desert" color="#ff0000" tile="-1" probability="1"/>

@ -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
</data>
</layer>
</map>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 70 KiB

After

Width:  |  Height:  |  Size: 71 KiB

@ -8,6 +8,7 @@ std::unordered_map<std::string,Animate2D::Animation<HamsterGame::AnimationState>
std::unordered_map<std::string,Renderable>HamsterGame::GFX;
const std::string HamsterGame::ASSETS_DIR{"assets/"};
PixelGameEngine*HamsterGame::self{nullptr};
std::unordered_map<uint32_t,Animate2D::FrameSequence>HamsterGame::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<vf2d>{{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<vf2d>{{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};
if(ANIMATED_TILE_IDS.count(tileID)){
Animate2D::FrameSequence&animatedTile{ANIMATED_TILE_IDS[tileID]};
const Animate2D::Frame&currentFrame{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;

@ -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<HamsterGame::AnimationState>&GetAnimations(const std::string_view img);
static PixelGameEngine&Game();
static std::unordered_map<uint32_t,Animate2D::FrameSequence>ANIMATED_TILE_IDS;
const double GetRuntime()const;
private:
void UpdateGame(const float fElapsedTime);
void DrawGame();
@ -77,4 +79,5 @@ private:
Border border;
void DrawLevelTiles();
std::optional<TMXParser>currentMap;
double runTime{};
};

@ -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.

@ -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;

@ -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)
{

Loading…
Cancel
Save