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-06-21 14:30:14 -07:00
2023-06-22 04:34:23 -07:00
struct TilesheetData {
2023-06-22 22:09:11 -07:00
TilesetData & tileset ;
2023-06-22 04:34:23 -07:00
int firstgid ;
} ;
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-07-13 01:35:51 -05:00
Renderable GFX_Warrior_Sheet , GFX_Slime_Sheet ,
2023-06-16 01:59:46 -05:00
GFX_Effect_GroundSlam_Back , GFX_Effect_GroundSlam_Front ,
2023-06-19 03:25:01 -05:00
GFX_Heart , GFX_BLOCK_BUBBLE , GFX_Ranger_Sheet , GFX_Wizard_Sheet ,
2023-07-05 05:34:21 -05:00
GFX_Battlecry_Effect , GFX_Mana , GFX_SonicSlash , GFX_EnergyParticle ,
2023-07-12 00:23:36 -05:00
GFX_Splash_Effect , GFX_LightningBolt , GFX_LightningBoltParticle1 ,
GFX_LightningBoltParticle2 , GFX_LightningBoltParticle3 , GFX_LightningBoltParticle4 ,
2023-07-25 18:37:12 -05:00
GFX_ChainLightning , GFX_LightningSplash , GFX_Meteor , GFX_Arrow ,
GFX_Laser , GFX_ChargedArrow ;
2023-06-24 01:18:21 -07:00
public :
2023-07-13 01:35:51 -05:00
Renderable GFX_BulletCircle , GFX_BulletCircleOutline , GFX_EnergyBolt , GFX_Circle ;
2023-07-10 18:40:51 +00:00
Pathfinding pathfinder ;
2023-07-21 18:47:45 +00:00
static Key KEY_ABILITY1 ;
static Key KEY_ABILITY2 ;
static Key KEY_ABILITY3 ;
static Key KEY_ABILITY4 ;
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-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-22 04:21:10 -05:00
void InitializeClassAbilities ( ) ;
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-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-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-07-07 19:48:45 +00:00
void HurtEnemies ( vf2d pos , float radius , int damage , bool upperLevel ) ;
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-07-06 14:24:43 -05:00
bool IsUpperForegroundTile ( TilesheetData sheet , int tileID ) ;
//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-07-07 06:42:49 -05:00
void PopulateRenderLists ( std : : vector < Monster * > & monstersBeforeLower , std : : vector < Monster * > & monstersBeforeUpper , std : : vector < Monster * > & monstersAfterLower , std : : vector < Monster * > & monstersAfterUpper , std : : vector < Bullet * > & bulletsLower , std : : vector < Bullet * > & bulletsUpper , std : : vector < Effect * > & backgroundEffectsLower , std : : vector < Effect * > & backgroundEffectsUpper , std : : vector < Effect * > & foregroundEffectsLower , std : : vector < Effect * > & foregroundEffectsUpper ) ;
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 ) ;
} ;
//Read a string array from the config.
datafilestringdata operator " " s ( const char * key , std : : size_t len ) ;
//Read an int array from the config.
datafileintdata operator " " i ( const char * key , std : : size_t len ) ;
//Read a float array from the config.
datafilefloatdata operator " " f ( const char * key , std : : size_t len ) ;
//Read a double array from the config.
datafiledoubledata operator " " d ( const char * key , std : : size_t len ) ;
//Read a string key from the config.
std : : string operator " " S ( const char * key , std : : size_t len ) ;
//Read an integer key from the config.
int operator " " I ( const char * key , std : : size_t len ) ;
//Read a float key from the config.
float operator " " F ( const char * key , std : : size_t len ) ;
//Read a double key from the config.
double operator " " D ( const char * key , std : : size_t len ) ;