2023-06-11 22:57:43 -05:00
# 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"
2023-07-07 06:42:49 -05:00
# include "Bullet.h"
2023-06-15 00:11:39 -05:00
# include "Effect.h"
2023-06-21 14:30:14 -07:00
# include "Map.h"
# include "TMXParser.h"
2023-07-26 01:58:00 -05:00
# include "olcUTIL_DataFile.h"
2023-09-26 02:40:38 -05:00
# include "Key.h"
2023-06-21 14:30:14 -07:00
2023-06-11 22:57:43 -05:00
class Crawler : public olc : : PixelGameEngine
{
2023-07-12 00:23:36 -05:00
friend class sig : : Animation ;
2023-06-11 22:57:43 -05:00
Camera2D camera ;
2023-07-13 20:24:47 +00:00
std : : unique_ptr < Player > player ;
2023-06-24 01:18:21 -07:00
public :
2023-07-10 18:40:51 +00:00
Pathfinding pathfinder ;
2023-09-26 02:40:38 -05:00
static InputGroup KEY_ATTACK ;
static InputGroup KEY_LEFT ;
static InputGroup KEY_RIGHT ;
static InputGroup KEY_UP ;
static InputGroup KEY_DOWN ;
2023-09-07 20:20:21 +00:00
static float SIZE_CHANGE_SPEED ;
2023-09-13 18:54:24 +00:00
float levelTime ;
2023-06-24 01:18:21 -07:00
private :
2023-07-21 15:20:56 -05:00
std : : vector < std : : unique_ptr < Effect > > foregroundEffects , backgroundEffects , foregroundEffectsToBeInserted , backgroundEffectsToBeInserted ;
2023-09-24 04:01:04 -05:00
std : : vector < TileRenderData * > tilePreparationList , tileForegroundList ;
2023-09-24 05:23:49 -05:00
std : : vector < vf2d > circleCooldownPoints ;
2023-06-21 14:30:14 -07:00
std : : map < MapName , Map > MAP_DATA ;
2023-06-22 22:09:11 -07:00
std : : map < std : : string , TilesetData > MAP_TILESETS ;
2023-06-20 19:13:45 -07:00
vf2d worldShake = { } ;
float worldShakeTime = 0 ;
float lastWorldShakeAdjust = 0 ;
vf2d worldShakeVel = { } ;
const float WORLD_SHAKE_ADJUST_MAX_TIME = 0.4 ;
2023-06-22 02:46:38 -07:00
MapName currentLevel = MapName : : CAMPAIGN_1_1 ;
2023-06-22 23:28:16 -07:00
std : : vector < TileGroup > foregroundTileGroups ;
2023-07-06 14:24:43 -05:00
std : : vector < TileGroup > upperForegroundTileGroups ;
2023-07-07 06:42:49 -05:00
int bridgeLayerIndex = - 1 ;
2023-07-11 17:24:50 +00:00
float bridgeFadeFactor = 0.f ;
2023-07-26 21:08:17 +00:00
void InitializeClasses ( ) ;
2023-09-12 19:36:25 +00:00
int DEBUG_PATHFINDING = 0 ;
2023-09-15 01:02:10 -05:00
std : : vector < Monster * > monstersBeforeLower , monstersAfterLower , monstersBeforeUpper , monstersAfterUpper ;
std : : vector < Bullet * > bulletsLower , bulletsUpper ;
std : : vector < Effect * > backgroundEffectsLower , backgroundEffectsUpper , foregroundEffectsLower , foregroundEffectsUpper ;
float reflectionUpdateTimer = 0 ;
float reflectionStepTime = 0 ;
std : : set < vi2d > visibleTiles ;
2023-09-19 03:30:18 -05:00
std : : vector < Monster > monstersToBeSpawned ;
2023-09-26 05:22:04 -05:00
float bossDisplayTimer = 0 ;
std : : string bossName ;
2023-09-26 06:35:21 -05:00
int totalDamageDealt = 0 ;
float encounterDuration = 0 ;
bool encounterStarted = false ;
int totalBossEncounterMobs = 0 ;
2023-06-11 22:57:43 -05:00
public :
Crawler ( ) ;
2023-07-25 20:32:29 +00:00
bool OnUserCreate ( ) override ;
bool OnUserUpdate ( float fElapsedTime ) override ;
2023-09-16 07:00:38 -05:00
bool OnUserDestroy ( ) override ;
2023-06-11 22:57:43 -05:00
public :
2023-07-05 18:29:04 +00:00
geom2d : : rect < int > NO_COLLISION = { } ;
2023-06-23 20:42:55 -07:00
vi2d WORLD_SIZE = { 120 , 8 } ;
2023-06-15 00:11:39 -05:00
TileTransformedView view ;
2023-06-21 22:59:06 -07:00
void InitializeLevel ( std : : string mapFile , MapName map ) ;
2023-06-22 02:46:38 -07:00
void LoadLevel ( MapName map ) ;
2023-06-11 22:57:43 -05:00
void HandleUserInput ( float fElapsedTime ) ;
void UpdateCamera ( float fElapsedTime ) ;
2023-06-15 00:11:39 -05:00
void UpdateEffects ( float fElapsedTime ) ;
2023-06-16 01:41:38 -05:00
void UpdateBullets ( float fElapsedTime ) ;
2023-06-12 00:37:55 -05:00
void RenderWorld ( float fElapsedTime ) ;
2023-06-15 00:47:11 -05:00
void RenderHud ( ) ;
2023-09-29 00:03:20 -05:00
void RenderMenu ( ) ;
2023-07-13 01:35:51 -05:00
void AddEffect ( std : : unique_ptr < Effect > foreground , std : : unique_ptr < Effect > background ) ;
2023-06-19 03:25:01 -05:00
//If back is true, places the effect in the background
2023-07-13 01:35:51 -05:00
void AddEffect ( std : : unique_ptr < Effect > foreground , bool back = false ) ;
2023-09-11 05:27:36 -05:00
void HurtEnemies ( vf2d pos , float radius , int damage , bool upperLevel , float z ) ;
2023-06-15 04:53:57 -05:00
vf2d GetWorldMousePos ( ) ;
2023-06-15 05:06:50 -05:00
bool LeftHeld ( ) ;
bool RightHeld ( ) ;
bool UpHeld ( ) ;
bool DownHeld ( ) ;
bool LeftReleased ( ) ;
bool RightReleased ( ) ;
bool UpReleased ( ) ;
bool DownReleased ( ) ;
2023-07-13 20:24:47 +00:00
Player * GetPlayer ( ) ;
2023-06-20 19:13:45 -07:00
void SetupWorldShake ( float duration ) ;
2023-06-22 02:46:38 -07:00
vi2d GetWorldSize ( ) ;
2023-06-22 04:34:23 -07:00
//tileID is the tile number from the tilesets.
2023-06-22 22:09:11 -07:00
bool IsForegroundTile ( TilesheetData sheet , int tileID ) ;
//tileID is the tile number from the tilesets.
2023-09-12 04:54:58 -05:00
bool IsUpperForegroundTile ( int tileID ) ;
2023-07-06 14:24:43 -05:00
//tileID is the tile number from the tilesets.
2023-06-22 04:34:23 -07:00
TilesheetData GetTileSheet ( MapName map , int tileID ) ;
2023-07-06 14:59:21 -05:00
//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 : : rect < int > GetTileCollision ( MapName map , vf2d pos , bool upperLevel = false ) ;
2023-07-05 18:29:04 +00:00
//Checks if the point resides inside of a collision tile.
2023-07-06 14:59:21 -05:00
bool HasTileCollision ( MapName map , vf2d pos , bool upperLevel = false ) ;
2023-06-24 00:00:14 -07:00
MapName GetCurrentLevel ( ) ;
2023-07-06 14:24:43 -05:00
bool IsBridgeLayer ( LayerTag & layer ) ;
2023-07-07 04:31:36 -05:00
std : : map < std : : string , std : : vector < geom2d : : rect < int > > > & GetZoneData ( MapName map ) ;
2023-09-15 01:02:10 -05:00
void PopulateRenderLists ( ) ;
2023-07-13 20:24:47 +00:00
void ChangePlayerClass ( Class cl ) ;
2023-07-26 01:58:00 -05:00
std : : string GetString ( std : : string key ) ;
2023-07-26 18:08:06 +00:00
datafilestringdata GetStringList ( std : : string key ) ;
2023-07-26 01:58:00 -05:00
int GetInt ( std : : string key ) ;
2023-07-26 18:08:06 +00:00
datafileintdata GetIntList ( std : : string key ) ;
2023-07-26 01:58:00 -05:00
float GetFloat ( std : : string key ) ;
2023-07-26 18:08:06 +00:00
datafilefloatdata GetFloatList ( std : : string key ) ;
2023-07-26 01:58:00 -05:00
double GetDouble ( std : : string key ) ;
2023-07-26 18:08:06 +00:00
datafiledoubledata GetDoubleList ( std : : string key ) ;
2023-09-07 01:35:23 -05:00
static void OutputDebugInfo ( const char * key , std : : size_t len ) ;
2023-09-07 03:28:37 -05:00
void InitializeLevels ( ) ;
2023-09-13 18:57:46 -05:00
void RenderTile ( vi2d pos , TilesheetData tileSheet , int tileSheetIndex , vi2d tileSheetPos ) ;
void RenderTile ( TileRenderData & tileSheet , Pixel col ) ;
2023-09-15 01:02:10 -05:00
bool IsReflectiveTile ( TilesheetData tileSheet , int tileID ) ;
2023-09-26 06:35:21 -05:00
void SpawnMonster ( vf2d pos , MonsterData * data , bool upperLevel = false , bool isBossSpawn = false ) ; //Queues a monster for spawning on the next frame.
2023-09-24 05:23:49 -05:00
void DrawPie ( vf2d center , float radius , float degreesCut , Pixel col ) ;
2023-09-26 00:32:54 -05:00
void RenderCooldowns ( ) ;
2023-09-26 02:40:38 -05:00
void InitializeDefaultKeybinds ( ) ;
2023-09-26 05:22:04 -05:00
void SetBossNameDisplay ( std : : string name , float time = 5 ) ;
2023-09-26 06:35:21 -05:00
bool InBossEncounter ( ) ;
void StartBossEncounter ( ) ;
void DisplayBossEncounterInfo ( ) ;
void BossDamageDealt ( int damage ) ;
void ReduceBossEncounterMobCount ( ) ;
2023-10-02 19:54:21 +00:00
void InitializeGraphics ( ) ;
2023-09-07 04:41:23 -05:00
struct TileGroupData {
vi2d tilePos ;
int layer ;
bool operator < ( const TileGroupData & rhs ) const {
return layer < rhs . layer | | ( layer = = rhs . layer & & tilePos < rhs . tilePos ) ;
}
} ;
} ;