diff --git a/assets/HamsterGame.tiled-project b/assets/HamsterGame.tiled-project index 2a46977..e47560e 100644 --- a/assets/HamsterGame.tiled-project +++ b/assets/HamsterGame.tiled-project @@ -10,6 +10,54 @@ "properties": [ ], "propertyTypes": [ + { + "color": "#ffa0a0a4", + "drawFill": true, + "id": 4, + "members": [ + { + "name": "Powerup Type", + "propertyType": "PowerupType", + "type": "int", + "value": 0 + }, + { + "name": "Upper-Left", + "type": "bool", + "value": false + } + ], + "name": "PowerupProps", + "type": "class", + "useAs": [ + "property", + "map", + "layer", + "object", + "tile", + "tileset", + "wangcolor", + "wangset", + "project" + ] + }, + { + "id": 3, + "name": "PowerupType", + "storageType": "int", + "type": "enum", + "values": [ + "WHEEL", + "GRASS", + "SAND", + "SWAMP", + "LAVA", + "FOREST", + "ICE", + "JET" + ], + "valuesAsFlags": false + }, { "id": 1, "name": "TerrainType", diff --git a/assets/HamsterGame.tiled-session b/assets/HamsterGame.tiled-session index b3a812a..36e605e 100644 --- a/assets/HamsterGame.tiled-session +++ b/assets/HamsterGame.tiled-session @@ -33,7 +33,7 @@ "openFiles": [ ], "project": "HamsterGame.tiled-project", - "property.type": "TerrainType", + "property.type": "bool", "recentFiles": [ ], "tileset.lastUsedFormat": "tsx", diff --git a/assets/Terrain.tsx b/assets/Terrain.tsx index 9473bd9..ea498b0 100644 --- a/assets/Terrain.tsx +++ b/assets/Terrain.tsx @@ -597,7 +597,7 @@ - + @@ -1753,7 +1753,7 @@ - + @@ -2839,7 +2839,7 @@ - + @@ -4882,7 +4882,7 @@ - + @@ -4892,7 +4892,7 @@ - + @@ -4902,7 +4902,7 @@ - + @@ -4912,7 +4912,7 @@ - + @@ -4926,7 +4926,7 @@ - + @@ -4956,7 +4956,7 @@ - + @@ -4986,7 +4986,7 @@ - + @@ -5016,7 +5016,7 @@ - + @@ -5128,7 +5128,7 @@ - + @@ -5173,7 +5173,7 @@ - + @@ -5199,7 +5199,7 @@ - + @@ -5225,7 +5225,7 @@ - + @@ -5251,7 +5251,7 @@ - + @@ -5878,8 +5878,16 @@ - - + + + + + + + + + + @@ -5907,8 +5915,16 @@ - - + + + + + + + + + + @@ -5978,8 +5994,16 @@ - - + + + + + + + + + + @@ -6007,8 +6031,16 @@ - - + + + + + + + + + + @@ -6046,8 +6078,16 @@ - - + + + + + + + + + + @@ -6075,8 +6115,16 @@ - - + + + + + + + + + + @@ -6416,22 +6464,94 @@ - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -6448,22 +6568,86 @@ - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/assets/TestLevel.tmx b/assets/TestLevel.tmx index 1f6a620..ef8f5c0 100644 --- a/assets/TestLevel.tmx +++ b/assets/TestLevel.tmx @@ -1,5 +1,5 @@ - + @@ -80,6 +80,11 @@ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1438,1439,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1466,1467,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1444,1445,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1472,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0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1478,1479,0, +0,0,0,0,0,1452,1453,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,1480,1481,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, diff --git a/assets/gametiles.png b/assets/gametiles.png index 7d3e7f2..724c5d2 100644 Binary files a/assets/gametiles.png and b/assets/gametiles.png differ diff --git a/assets/gametiles.xcf b/assets/gametiles.xcf new file mode 100644 index 0000000..dab4bce Binary files /dev/null and b/assets/gametiles.xcf differ diff --git a/assets/gametiles_original.xcf b/assets/gametiles_original.xcf new file mode 100644 index 0000000..a6eb68e Binary files /dev/null and b/assets/gametiles_original.xcf differ diff --git a/assets/hamster.png b/assets/hamster.png index 404137c..40e3263 100644 Binary files a/assets/hamster.png and b/assets/hamster.png differ diff --git a/assets/hamster.xcf b/assets/hamster.xcf index 27240c8..86acd44 100644 Binary files a/assets/hamster.xcf and b/assets/hamster.xcf differ diff --git a/hamster.vcxproj b/hamster.vcxproj index 1a4ac96..ebec35f 100644 --- a/hamster.vcxproj +++ b/hamster.vcxproj @@ -329,6 +329,10 @@ if %errorlevel% neq 0 goto :VCEnd + + + + @@ -370,6 +374,10 @@ if %errorlevel% neq 0 goto :VCEnd + + + + diff --git a/hamster.vcxproj.filters b/hamster.vcxproj.filters index 38aa74e..7560861 100644 --- a/hamster.vcxproj.filters +++ b/hamster.vcxproj.filters @@ -22,6 +22,9 @@ Source Files + + Source Files + @@ -88,5 +91,8 @@ Header Files + + Header Files + \ No newline at end of file diff --git a/src/HamsterGame.cpp b/src/HamsterGame.cpp index d604f0d..20b192e 100644 --- a/src/HamsterGame.cpp +++ b/src/HamsterGame.cpp @@ -22,6 +22,7 @@ bool HamsterGame::OnUserCreate(){ tv.SetWorldOffset(-SCREEN_FRAME.pos); LoadGraphics(); LoadAnimations(); + currentTileset=TSXParser{ASSETS_DIR+std::string("Terrain.tsx")}; LoadLevel("TestLevel.tmx"); //THIS IS TEMPORARY. border.ChangeBorder(Border::DEFAULT); @@ -73,10 +74,22 @@ void HamsterGame::LoadLevel(const std::string_view mapName){ const vf2d levelSpawnLoc{50,50}; //TEMPORARY currentMap=TMXParser{ASSETS_DIR+std::string(mapName)}; - currentTileset=TSXParser{ASSETS_DIR+std::string("Terrain.tsx")}; Hamster::LoadHamsters(levelSpawnLoc); camera.SetTarget(Hamster::GetPlayer().GetPos()); + + #pragma region Detect powerup tiles + std::vectormapPowerups; + for(const LayerTag&layer:currentMap.value().GetData().GetLayers()){ + for(size_t y:std::ranges::iota_view(0U,layer.tiles.size())){ + for(size_t x:std::ranges::iota_view(0U,layer.tiles[y].size())){ + const int tileID{layer.tiles[y][x]-1}; + if(Powerup::TileIDIsUpperLeftPowerupTile(tileID))mapPowerups.emplace_back(vf2d{float(x),float(y)}*16+vf2d{16,16},Powerup::TileIDPowerupType(tileID)); + } + } + } + Powerup::Initialize(mapPowerups); + #pragma endregion } void HamsterGame::UpdateGame(const float fElapsedTime){ @@ -88,6 +101,7 @@ void HamsterGame::UpdateGame(const float fElapsedTime){ void HamsterGame::DrawGame(){ DrawLevelTiles(); + Powerup::DrawPowerups(tv); Hamster::DrawHamsters(tv); border.Draw(); DrawStringDecal(SCREEN_FRAME.pos+vf2d{1,1},"Terrain Type: "+Terrain::TerrainToString(Hamster::GetPlayer().GetTerrainStandingOn()),BLACK); @@ -118,7 +132,7 @@ void HamsterGame::DrawLevelTiles(){ int tileX{int(floor(x)/16)}; int tileY{int(floor(y)/16)}; int tileID{layer.tiles[tileY][tileX]-1}; - if(tileID==-1)continue; + if(tileID==-1||Powerup::TileIDIsPowerupTile(tileID))continue; int imgTileX{tileID%numTilesWide}; int imgTileY{tileID/numTilesWide}; diff --git a/src/Powerup.cpp b/src/Powerup.cpp new file mode 100644 index 0000000..77be9d3 --- /dev/null +++ b/src/Powerup.cpp @@ -0,0 +1,96 @@ +#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 + +#include "HamsterGame.h" +#include "Powerup.h" + +std::vectorPowerup::powerupList; +std::unordered_map>Powerup::powerupIds; +const vf2d Powerup::POWERUP_TILESET_STARTING_POS{144.f,816.f}; + +Powerup::Powerup(const vf2d pos,const PowerupType type) +:pos(pos),type(type){} +void Powerup::Initialize(const std::vector&powerupList){ + Powerup::powerupList.clear(); + Powerup::powerupList=powerupList; +} +const vf2d&Powerup::GetPos()const{ + return pos; +} +const Powerup::PowerupType&Powerup::GetType()const{ + return type; +} +const std::vector&Powerup::GetPowerups(){ + return powerupList; +} + +void Powerup::AddOrUpdatePowerupIdList(const int powerupId,const PowerupType powerupType){ + if(powerupIds.count(powerupId)){ + powerupIds[powerupId].first=powerupType; + }else{ + powerupIds[powerupId]={powerupType,TileType::DEFAULT}; + } +} + +void Powerup::AddOrUpdatePowerupIdList(const int powerupId,const TileType powerupTileType){ + if(powerupIds.count(powerupId)){ + powerupIds[powerupId].second=powerupTileType; + }else{ + powerupIds[powerupId]={PowerupType::WHEEL,powerupTileType}; + } +} + +const bool Powerup::TileIDIsPowerupTile(const int tileId){ + return powerupIds.count(tileId); +} + + +const bool Powerup::TileIDIsUpperLeftPowerupTile(const int tileId){ + return powerupIds.count(tileId)&&powerupIds[tileId].second==TileType::IS_UPPERLEFT_TILE; +} + +const Powerup::PowerupType Powerup::TileIDPowerupType(const int tileId){ + return powerupIds.at(tileId).first; +} + +void Powerup::DrawPowerups(TransformedView&tv){ + for(const Powerup&powerup:powerupList){ + geom2d::rectspriteRect{POWERUP_TILESET_STARTING_POS+vf2d{int(powerup.GetType())*32.f,0.f},{32,32}}; + tv.DrawPartialRotatedDecal(powerup.GetPos(),HamsterGame::GetGFX("gametiles.png").Decal(),0.f,{16,16},spriteRect.pos,spriteRect.size); + } +} \ No newline at end of file diff --git a/src/Powerup.h b/src/Powerup.h new file mode 100644 index 0000000..a44f880 --- /dev/null +++ b/src/Powerup.h @@ -0,0 +1,78 @@ +#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 +#include +#include "olcUTIL_Geometry2D.h" +#include "olcPGEX_TransformedView.h" + +class Powerup{ +public: + enum PowerupType{ + WHEEL, + GRASS, + SAND, + SWAMP, + LAVA, + FOREST, + ICE, + JET, + }; + enum TileType{ + IS_UPPERLEFT_TILE=true, + DEFAULT=false, + }; +private: + static std::vectorpowerupList; + static std::unordered_map>powerupIds; + static const vf2d POWERUP_TILESET_STARTING_POS; + vf2d pos; + PowerupType type; +public: + Powerup(const vf2d pos,const PowerupType type); + static void Initialize(const std::vector&powerupList); + const vf2d&GetPos()const; + const PowerupType&GetType()const; + static const std::vector&GetPowerups(); + static void AddOrUpdatePowerupIdList(const int powerupId,const PowerupType powerupType); + static void AddOrUpdatePowerupIdList(const int powerupId,const TileType powerupTileType); + static const bool TileIDIsPowerupTile(const int tileId); + static const bool TileIDIsUpperLeftPowerupTile(const int tileId); + static const PowerupType TileIDPowerupType(const int tileId); + static void DrawPowerups(TransformedView&tv); +}; \ No newline at end of file diff --git a/src/TSXParser.h b/src/TSXParser.h index 14cf5f5..85a4e2d 100644 --- a/src/TSXParser.h +++ b/src/TSXParser.h @@ -39,6 +39,7 @@ All rights reserved. #include #include "TMXParser.h" #include "Terrain.h" +#include "Powerup.h" using namespace olc; @@ -169,7 +170,19 @@ class TSXParser{ std::pair&tileData{parsedTilesetInfo.TerrainData[tagID]}; tileData.first=Terrain::SolidType(newTag.GetBool("value")); } - } + } else + if(newTag.tag=="property"&&newTag.data["propertytype"]=="PowerupType"){ + //The way animation data is stored is every "animation_tile_precision" ms indicating which frame we should be on. + for(int&tagID:previousTagID){ + Powerup::AddOrUpdatePowerupIdList(tagID,Powerup::PowerupType(newTag.GetInteger("value"))); + } + } else + if(newTag.tag=="property"&&newTag.data["name"]=="Upper-Left"){ + //The way animation data is stored is every "animation_tile_precision" ms indicating which frame we should be on. + for(int&tagID:previousTagID){ + Powerup::AddOrUpdatePowerupIdList(tagID,Powerup::TileType(newTag.GetBool("value"))); + } + } else if (newTag.tag=="object"&&previousTag.size()>0&&previousTag[0]=="tile"){ for(int&tagID:previousTagID){ TileCollisionData data; diff --git a/src/olcUTIL_Geometry2D.h b/src/olcUTIL_Geometry2D.h index 8eec079..245bc78 100644 --- a/src/olcUTIL_Geometry2D.h +++ b/src/olcUTIL_Geometry2D.h @@ -2532,4 +2532,5 @@ namespace olc::utils::geom2d #endif // PGE_VER +using namespace olc; using namespace olc::utils; \ No newline at end of file