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-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 ;
Player player ;
2023-06-17 23:07:26 -05:00
Renderable GFX_Warrior_Sheet , GFX_Slime_Sheet , GFX_Circle ,
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 ,
GFX_ChainLightning , GFX_LightningSplash ;
2023-06-24 01:18:21 -07:00
public :
2023-06-24 02:14:11 -07:00
Renderable GFX_BulletCircle , GFX_BulletCircleOutline , GFX_EnergyBolt ;
2023-07-10 18:40:51 +00:00
Pathfinding pathfinder ;
2023-06-24 01:18:21 -07:00
private :
2023-06-15 00:11:39 -05:00
std :: vector < Effect > foregroundEffects , backgroundEffects ;
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-06-11 22:57:43 -05:00
public :
Crawler ();
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-11 22:57:43 -05:00
bool OnUserCreate () override ;
bool OnUserUpdate ( float fElapsedTime ) override ;
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-06-15 00:11:39 -05:00
void AddEffect ( Effect foreground , Effect background );
2023-06-19 03:25:01 -05:00
//If back is true, places the effect in the background
void AddEffect ( 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-06-15 23:44:34 -05: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-06-11 22:57:43 -05:00
};