diff --git a/Crawler/Crawler.cpp b/Crawler/Crawler.cpp index 1d684dd1..9dfa39e8 100644 --- a/Crawler/Crawler.cpp +++ b/Crawler/Crawler.cpp @@ -57,6 +57,7 @@ SUCH DAMAGE. #include "Unlock.h" #include "State_OverworldMap.h" #include "Test.h" +#include "ItemDrop.h" INCLUDE_EMITTER_LIST @@ -181,6 +182,7 @@ bool Crawler::OnUserCreate(){ GameState::Initialize(); Unlock::Initialize(); + ItemDrop::Initialize(); ValidateGameStatus(); //Checks to make sure everything has been initialized properly. @@ -417,6 +419,9 @@ void Crawler::HandleUserInput(float fElapsedTime){ if(GetKey(I).bPressed){ Menu::OpenMenu(INVENTORY); } + if(GetKey(O).bPressed){ + ItemDrop::SpawnItem(&ITEM_DATA.at("Green Slime Remains"),player->GetPos()); + } } void Crawler::UpdateCamera(float fElapsedTime){ @@ -554,6 +559,10 @@ void Crawler::PopulateRenderLists(){ foregroundEffectsUpper.clear(); endZones.clear(); upperEndZones.clear(); + dropsBeforeLower.clear(); + dropsAfterLower.clear(); + dropsBeforeUpper.clear(); + dropsAfterUpper.clear(); tilePreparationList.clear(); tileForegroundList.clear(); @@ -575,6 +584,22 @@ void Crawler::PopulateRenderLists(){ } } } + for(int i=0;iGetPos().y){//This item drop renders before the player does (behind the player) + if(drop.OnUpperLevel()){ + dropsBeforeUpper.push_back(i); + }else{ + dropsBeforeLower.push_back(i); + } + } else {//This item drop renders after the player does (in front of the player) + if(drop.OnUpperLevel()){ + dropsAfterUpper.push_back(i); + }else{ + dropsAfterLower.push_back(i); + } + } + } for(auto it=BULLET_LIST.begin();it!=BULLET_LIST.end();++it){ Bullet*b=(*it).get(); if(b->OnUpperLevel()){ @@ -660,6 +685,7 @@ void Crawler::RenderWorld(float fElapsedTime){ pos=player->teleportStartPosition.lerp(player->teleportTarget,(0.35-player->teleportAnimationTimer)/0.35); } view.DrawPartialRotatedDecal(pos+vf2d{0,-player->GetZ()*(std::signbit(scale.y)?-1:1)},player->GetFrame().GetSourceImage()->Decal(),player->GetSpinAngle(),{12,12},player->GetFrame().GetSourceRect().pos,player->GetFrame().GetSourceRect().size,playerScale*scale,player->GetBuffs(BuffType::ATTACK_UP).size()>0?Pixel{255,uint8_t(255*abs(sin(1.4*player->GetBuffs(BuffType::ATTACK_UP)[0].duration))),uint8_t(255*abs(sin(1.4*player->GetBuffs(BuffType::ATTACK_UP)[0].duration)))}:WHITE); + SetDecalMode(DecalMode::NORMAL); if(player->GetState()==State::BLOCK){ view.DrawDecal(player->GetPos()-vf2d{12,12},GFX["block.png"].Decal()); } @@ -814,12 +840,18 @@ void Crawler::RenderWorld(float fElapsedTime){ for(ZoneData&zone:endZones){ RenderZone(zone.zone); } + for(int index:dropsBeforeLower){ + ItemDrop::drops[index].Draw(); + } for(Monster*m:monstersBeforeLower){ m->Draw(); } if(!player->upperLevel){ RenderPlayer(player->GetPos(),{1,1}); } + for(int index:dropsAfterLower){ + ItemDrop::drops[index].Draw(); + } for(Monster*m:monstersAfterLower){ m->Draw(); } @@ -965,12 +997,18 @@ void Crawler::RenderWorld(float fElapsedTime){ for(ZoneData&zone:upperEndZones){ RenderZone(zone.zone); } + for(int index:dropsBeforeUpper){ + ItemDrop::drops[index].Draw(); + } for(Monster*m:monstersBeforeUpper){ m->Draw(); } if(player->upperLevel){ RenderPlayer(player->GetPos(),{1,1}); } + for(int index:dropsAfterUpper){ + ItemDrop::drops[index].Draw(); + } for(Monster*m:monstersAfterUpper){ m->Draw(); } @@ -1962,6 +2000,9 @@ void Crawler::ValidateGameStatus(){ if(!Unlock::IsUnlocked(State_OverworldMap::GetCurrentConnectionPoint())){ ERR("WARNING! The current connection point is not unlocked! This is not supposed to be happening.") } + if(ItemDrop::gravity!="ItemDrop.Item Drop Gravity"_F){ + ERR("WARNING! Gravity constant for item drops was not initialized to "<<"Item Drop Gravity"_F<<". Actual value: "<>foregroundEffects,backgroundEffects,foregroundEffectsToBeInserted,backgroundEffectsToBeInserted; std::vectortilePreparationList,tileForegroundList; + std::vectordropsBeforeLower,dropsAfterLower,dropsBeforeUpper,dropsAfterUpper; std::vectorendZones,upperEndZones; std::vectorcircleCooldownPoints; std::mapMAP_TILESETS; diff --git a/Crawler/Crawler.vcxproj b/Crawler/Crawler.vcxproj index 051cd64b..3e341f6a 100644 --- a/Crawler/Crawler.vcxproj +++ b/Crawler/Crawler.vcxproj @@ -286,6 +286,10 @@ + + + + @@ -354,6 +358,7 @@ + diff --git a/Crawler/Crawler.vcxproj.filters b/Crawler/Crawler.vcxproj.filters index 087d0ecc..dcca21c9 100644 --- a/Crawler/Crawler.vcxproj.filters +++ b/Crawler/Crawler.vcxproj.filters @@ -258,6 +258,9 @@ Header Files + + Header Files + @@ -434,6 +437,9 @@ Source Files\Game States + + Source Files + diff --git a/Crawler/ItemDrop.cpp b/Crawler/ItemDrop.cpp new file mode 100644 index 00000000..98e6cdd2 --- /dev/null +++ b/Crawler/ItemDrop.cpp @@ -0,0 +1,123 @@ +#pragma region License +/* +License (OLC-3) +~~~~~~~~~~~~~~~ + +Copyright 2018 - 2023 OneLoneCoder.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. +*/ +#pragma endregion +#include "ItemDrop.h" +#include "olcUTIL_Geometry2D.h" +#include "Crawler.h" + +INCLUDE_game +INCLUDE_GFX + +float ItemDrop::gravity; +std::vectorItemDrop::drops; + +void ItemDrop::Initialize(){ + gravity="ItemDrop.Item Drop Gravity"_F; +} + +ItemDrop::ItemDrop(ItemInfo*item,vf2d pos) +:item(item),pos(pos){ + speed.x=util::random("ItemDrop.Item Drop Horizontal Speed"_f[1]-"ItemDrop.Item Drop Horizontal Speed"_f[0])+"ItemDrop.Item Drop Horizontal Speed"_f[0]; + speed.y=util::random("ItemDrop.Item Drop Vertical Speed"_f[1]-"ItemDrop.Item Drop Vertical Speed"_f[0])+"ItemDrop.Item Drop Vertical Speed"_f[0]; + zSpeed="ItemDrop.Item Drop Initial Rise Speed"_F; +} + +vf2d ItemDrop::GetPos(){ + return pos; +} + +bool ItemDrop::OnUpperLevel(){ + return upperLevel; +} + +void ItemDrop::Draw(){ + #pragma region Item Drop Shadow Rendering + if(GetZ()>0){ + vf2d shadowScale=vf2d{8*"ItemDrop.Item Drop Scale"_F/3.f,1}/std::max(1.f,GetZ()/24); + game->view.DrawDecal(GetPos()-vf2d{3,3}*shadowScale/2+vf2d{0,6*"ItemDrop.Item Drop Scale"_F},GFX["circle.png"].Decal(),shadowScale,BLACK); + } + #pragma endregion + + game->view.DrawRotatedDecal(pos-vf2d{0,GetZ()},item->Decal(),0,item->Decal()->sprite->Size()/2,{"ItemDrop.Item Drop Scale"_F,"ItemDrop.Item Drop Scale"_F}); + game->SetDecalMode(DecalMode::ADDITIVE); + game->view.DrawRotatedDecal(pos-vf2d{0,GetZ()},item->Decal(),0,item->Decal()->sprite->Size()/2,{"ItemDrop.Item Drop Scale"_F,"ItemDrop.Item Drop Scale"_F},{uint8_t(abs(sin(game->levelTime*1.5)*255.f)),uint8_t(abs(sin(game->levelTime*1.5)*255.f)),uint8_t(abs(sin(game->levelTime*1.5)*255.f)),255}); + game->SetDecalMode(DecalMode::NORMAL); +} + +void ItemDrop::UpdateDrops(float fElapsedTime){ + for(ItemDrop&drop:drops){ + #pragma region Handle Z Speed + drop.z+=drop.zSpeed*fElapsedTime; + if(drop.z<0)drop.zSpeed=0; + else{ + drop.zSpeed+=gravity*fElapsedTime; + drop.pos+=drop.speed*fElapsedTime; + } + #pragma endregion + + #pragma region Check for Suction / Player pull-in + if(drop.zSpeed==0&&drop.OnUpperLevel()==game->GetPlayer()->OnUpperLevel()){ + geom2d::linelineTo=geom2d::line(drop.pos,game->GetPlayer()->GetPos()); + float dist=lineTo.length(); + if(dist<="ItemDrop.Item Drop Suction Range"_F){ + vf2d pointVel=lineTo.vector(); + drop.pos+=pointVel*(1/dist*fElapsedTime); + } + } + #pragma endregion + + #pragma region Handle Upper/Lower Level Zone Intersecting + if(drop.speed.mag()>0){ + std::map>&zoneData=game->GetZoneData(game->GetCurrentLevel()); + for(ZoneData&upperLevelZone:zoneData["UpperZone"]){ + if(geom2d::overlaps(upperLevelZone.zone,drop.pos)){ + drop.upperLevel=true; + } + } + for(ZoneData&lowerLevelZone:zoneData["LowerZone"]){ + if(geom2d::overlaps(lowerLevelZone.zone,drop.pos)){ + drop.upperLevel=false; + } + } + } + #pragma endregion + } +} + +float ItemDrop::GetZ(){ + return z; +} + +void ItemDrop::SpawnItem(ItemInfo*item,vf2d pos){ + drops.push_back(ItemDrop{item,pos}); +} \ No newline at end of file diff --git a/Crawler/ItemDrop.h b/Crawler/ItemDrop.h new file mode 100644 index 00000000..88955f12 --- /dev/null +++ b/Crawler/ItemDrop.h @@ -0,0 +1,59 @@ +#pragma region License +/* +License (OLC-3) +~~~~~~~~~~~~~~~ + +Copyright 2018 - 2023 OneLoneCoder.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. +*/ +#pragma endregion +#include "olcPixelGameEngine.h" +#include "Item.h" +#include "util.h" +#include "Crawler.h" + +class ItemDrop{ + friend class Crawler; + vf2d pos; + vf2d speed{}; + float zSpeed=0; + float z=0; + float randomSpinOffset=0; + ItemInfo*item=nullptr; + bool upperLevel=false; + static float gravity; + static std::vectordrops; + ItemDrop(ItemInfo*item,vf2d pos); +public: + static void Initialize(); + vf2d GetPos(); + bool OnUpperLevel(); + void Draw(); + static void UpdateDrops(float fElapsedTime); + float GetZ(); + static void SpawnItem(ItemInfo*item,vf2d pos); +}; \ No newline at end of file diff --git a/Crawler/State_GameRun.cpp b/Crawler/State_GameRun.cpp index b9394967..dcbe6605 100644 --- a/Crawler/State_GameRun.cpp +++ b/Crawler/State_GameRun.cpp @@ -35,6 +35,7 @@ SUCH DAMAGE. #include "Crawler.h" #include "DEFINES.h" #include "Menu.h" +#include "ItemDrop.h" INCLUDE_MONSTER_LIST INCLUDE_game @@ -63,6 +64,7 @@ void State_GameRun::OnUserUpdate(Crawler*game){ } game->monstersToBeSpawned.clear(); + ItemDrop::UpdateDrops(game->GetElapsedTime()); game->UpdateBullets(game->GetElapsedTime()); game->UpdateCamera(game->GetElapsedTime()); }; diff --git a/Crawler/Version.h b/Crawler/Version.h index f9f19365..758e2e55 100644 --- a/Crawler/Version.h +++ b/Crawler/Version.h @@ -35,7 +35,7 @@ SUCH DAMAGE. #define VERSION_MAJOR 0 #define VERSION_MINOR 2 #define VERSION_PATCH 1 -#define VERSION_BUILD 2998 +#define VERSION_BUILD 3052 #define stringify(a) stringify_(a) #define stringify_(a) #a diff --git a/Crawler/assets/config/items/items.txt b/Crawler/assets/config/items/items.txt index 338580c6..33782bfd 100644 --- a/Crawler/assets/config/items/items.txt +++ b/Crawler/assets/config/items/items.txt @@ -3,4 +3,24 @@ ItemConfiguration Item Database = "ItemDatabase.txt" Item Scripts = "ItemScript.txt" Item Categories = "ItemCategory.txt +} +ItemDrop +{ + # Item drops horizontal random speed range + Item Drop Horizontal Speed = -30,30 + + # Item drops vertical random speed range + Item Drop Vertical Speed = -15,15 + + # Item drop suction range + Item Drop Suction Range = 48 + + # Item drop initial rise speed + Item Drop Initial Rise Speed = 10 + + # Item drop gravity + Item Drop Gravity = -9.8 + + # Item drop scale + Item Drop Scale = 0.4 } \ No newline at end of file diff --git a/Crawler/olcPixelGameEngine.h b/Crawler/olcPixelGameEngine.h index a94337a7..0e5e608a 100644 --- a/Crawler/olcPixelGameEngine.h +++ b/Crawler/olcPixelGameEngine.h @@ -851,6 +851,8 @@ namespace olc STENCIL, ILLUMINATE, WIREFRAME, + BLENDWHITE, + SCREEN, MODEL3D, }; @@ -4505,6 +4507,11 @@ namespace olc case olc::DecalMode::WIREFRAME: glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); break; + case olc::DecalMode::BLENDWHITE: + break; + case olc::DecalMode::SCREEN: + glBlendFunc(GL_ONE, GL_ONE); + break; } nDecalMode = mode;