#pragma once #include "olcPixelGameEngine.h" #include "Animation.h" #include "olcUTIL_Animate2D.h" #include "Monster.h" #include "olcPGEX_TransformedView.h" #include "Player.h" #include "olcUTIL_Camera2D.h" #include "Bullet.h" #include "Effect.h" #include "Map.h" #include "TMXParser.h" #include "olcUTIL_DataFile.h" class Crawler : public olc::PixelGameEngine { friend class sig::Animation; Camera2D camera; std::unique_ptrplayer; public: Pathfinding pathfinder; static Key KEY_ABILITY1; static Key KEY_ABILITY2; static Key KEY_ABILITY3; static Key KEY_ABILITY4; static float SIZE_CHANGE_SPEED; float levelTime; private: std::vector>foregroundEffects,backgroundEffects,foregroundEffectsToBeInserted,backgroundEffectsToBeInserted; std::vectortilePreparationList,tileForegroundList; std::vectorcircleCooldownPoints; std::mapMAP_DATA; std::mapMAP_TILESETS; vf2d worldShake={}; float worldShakeTime=0; float lastWorldShakeAdjust=0; vf2d worldShakeVel={}; const float WORLD_SHAKE_ADJUST_MAX_TIME=0.4; MapName currentLevel=MapName::CAMPAIGN_1_1; std::vectorforegroundTileGroups; std::vectorupperForegroundTileGroups; int bridgeLayerIndex=-1; float bridgeFadeFactor=0.f; void InitializeClasses(); int DEBUG_PATHFINDING=0; std::vectormonstersBeforeLower,monstersAfterLower,monstersBeforeUpper,monstersAfterUpper; std::vectorbulletsLower,bulletsUpper; std::vectorbackgroundEffectsLower,backgroundEffectsUpper,foregroundEffectsLower,foregroundEffectsUpper; float reflectionUpdateTimer=0; float reflectionStepTime=0; std::setvisibleTiles; std::vectormonstersToBeSpawned; public: Crawler(); bool OnUserCreate() override; bool OnUserUpdate(float fElapsedTime) override; bool OnUserDestroy() override; public: geom2d::rectNO_COLLISION={}; vi2d WORLD_SIZE={120,8}; TileTransformedView view; void InitializeLevel(std::string mapFile,MapName map); void LoadLevel(MapName map); void HandleUserInput(float fElapsedTime); void UpdateCamera(float fElapsedTime); void UpdateEffects(float fElapsedTime); void UpdateBullets(float fElapsedTime); void RenderWorld(float fElapsedTime); void RenderHud(); void AddEffect(std::unique_ptrforeground,std::unique_ptrbackground); //If back is true, places the effect in the background void AddEffect(std::unique_ptrforeground,bool back=false); void HurtEnemies(vf2d pos,float radius,int damage,bool upperLevel,float z); vf2d GetWorldMousePos(); bool LeftHeld(); bool RightHeld(); bool UpHeld(); bool DownHeld(); bool LeftReleased(); bool RightReleased(); bool UpReleased(); bool DownReleased(); Player*GetPlayer(); void SetupWorldShake(float duration); vi2d GetWorldSize(); //tileID is the tile number from the tilesets. bool IsForegroundTile(TilesheetData sheet,int tileID); //tileID is the tile number from the tilesets. bool IsUpperForegroundTile(int tileID); //tileID is the tile number from the tilesets. TilesheetData GetTileSheet(MapName map,int tileID); //Gets the rectangle of the tile collision at this tile. If upperLevel is set to true, the collision tile must be in a Bridge class layer for the tile to hit. Also, zones containing LowerBridgeCollision will apply when upperLevel is set to false. geom2d::rectGetTileCollision(MapName map,vf2d pos,bool upperLevel=false); //Checks if the point resides inside of a collision tile. bool HasTileCollision(MapName map,vf2d pos,bool upperLevel=false); MapName GetCurrentLevel(); bool IsBridgeLayer(LayerTag&layer); std::map>>&GetZoneData(MapName map); void PopulateRenderLists(); void ChangePlayerClass(Class cl); std::string GetString(std::string key); datafilestringdata GetStringList(std::string key); int GetInt(std::string key); datafileintdata GetIntList(std::string key); float GetFloat(std::string key); datafilefloatdata GetFloatList(std::string key); double GetDouble(std::string key); datafiledoubledata GetDoubleList(std::string key); static void OutputDebugInfo(const char*key,std::size_t len); void InitializeLevels(); void RenderTile(vi2d pos,TilesheetData tileSheet,int tileSheetIndex,vi2d tileSheetPos); void RenderTile(TileRenderData&tileSheet,Pixel col); bool IsReflectiveTile(TilesheetData tileSheet,int tileID); void SpawnMonster(vf2d pos,MonsterData*data,bool upperLevel=false); //Queues a monster for spawning on the next frame. void DrawPie(vf2d center,float radius,float degreesCut,Pixel col); struct TileGroupData{ vi2d tilePos; int layer; bool operator<(const TileGroupData&rhs)const{ return layer