@ -49,7 +49,7 @@ bool Crawler::OnUserCreate(){
//Initialize Camera.
//Initialize Camera.
camera = Camera2D { WINDOW_SIZE } ;
camera = Camera2D { WINDOW_SIZE } ;
camera . SetMode ( olc : : utils : : Camera2D : : Mode : : LazyFollow ) ;
camera . SetMode ( olc : : utils : : Camera2D : : Mode : : LazyFollow ) ;
camera . SetTarget ( player . GetPos ( ) ) ;
camera . SetTarget ( player - > GetPos ( ) ) ;
camera . SetWorldBoundary ( { 0 , 0 } , WORLD_SIZE * 24 ) ;
camera . SetWorldBoundary ( { 0 , 0 } , WORLD_SIZE * 24 ) ;
camera . EnableWorldBoundary ( false ) ;
camera . EnableWorldBoundary ( false ) ;
@ -88,7 +88,7 @@ bool Crawler::OnUserCreate(){
LoadLevel ( CAMPAIGN_1_1 ) ;
LoadLevel ( CAMPAIGN_1_1 ) ;
player . ChangeClass ( WARRIOR ) ;
player - > ChangeClass ( WARRIOR ) ;
return true ;
return true ;
}
}
@ -97,7 +97,7 @@ bool Crawler::OnUserUpdate(float fElapsedTime){
fElapsedTime = std : : min ( 1 / 60.f , fElapsedTime ) ;
fElapsedTime = std : : min ( 1 / 60.f , fElapsedTime ) ;
HandleUserInput ( fElapsedTime ) ;
HandleUserInput ( fElapsedTime ) ;
UpdateEffects ( fElapsedTime ) ;
UpdateEffects ( fElapsedTime ) ;
player . Update ( fElapsedTime ) ;
player - > Update ( fElapsedTime ) ;
for ( Monster & m : MONSTER_LIST ) {
for ( Monster & m : MONSTER_LIST ) {
m . Update ( fElapsedTime ) ;
m . Update ( fElapsedTime ) ;
}
}
@ -139,36 +139,36 @@ void Crawler::HandleUserInput(float fElapsedTime){
ConsoleShow ( F1 ) ;
ConsoleShow ( F1 ) ;
}
}
if ( GetMouseWheel ( ) > 0 ) {
if ( GetMouseWheel ( ) > 0 ) {
switch ( player . cl ) {
switch ( player - > GetClass ( ) ) {
case WARRIOR : {
case WARRIOR : {
player . ChangeClass ( RANGER ) ;
player - > ChangeClass ( RANGER ) ;
} break ;
} break ;
case RANGER : {
case RANGER : {
player . ChangeClass ( WIZARD ) ;
player - > ChangeClass ( WIZARD ) ;
} break ;
} break ;
case WIZARD : {
case WIZARD : {
player . ChangeClass ( WARRIOR ) ;
player - > ChangeClass ( WARRIOR ) ;
} break ;
} break ;
}
}
}
}
if ( GetMouseWheel ( ) < 0 ) {
if ( GetMouseWheel ( ) < 0 ) {
switch ( player . cl ) {
switch ( player - > GetClass ( ) ) {
case WARRIOR : {
case WARRIOR : {
player . ChangeClass ( WIZARD ) ;
player - > ChangeClass ( WIZARD ) ;
} break ;
} break ;
case RANGER : {
case RANGER : {
player . ChangeClass ( WARRIOR ) ;
player - > ChangeClass ( WARRIOR ) ;
} break ;
} break ;
case WIZARD : {
case WIZARD : {
player . ChangeClass ( RANGER ) ;
player - > ChangeClass ( RANGER ) ;
} break ;
} break ;
}
}
}
}
if ( player . GetVelocity ( ) = = vf2d { 0 , 0 } & & player . CanMove ( ) ) {
if ( player - > GetVelocity ( ) = = vf2d { 0 , 0 } & & player - > CanMove ( ) ) {
auto GetPlayerStaircaseDirection = [ & ] ( ) {
auto GetPlayerStaircaseDirection = [ & ] ( ) {
for ( LayerTag & layer : MAP_DATA [ GetCurrentLevel ( ) ] . LayerData ) {
for ( LayerTag & layer : MAP_DATA [ GetCurrentLevel ( ) ] . LayerData ) {
int truncatedPlayerX = int ( player . GetX ( ) ) / 24 ;
int truncatedPlayerX = int ( player - > GetX ( ) ) / 24 ;
int truncatedPlayerY = int ( player . GetY ( ) ) / 24 ;
int truncatedPlayerY = int ( player - > GetY ( ) ) / 24 ;
int tileID = layer . tiles [ truncatedPlayerY ] [ truncatedPlayerX ] ;
int tileID = layer . tiles [ truncatedPlayerY ] [ truncatedPlayerX ] ;
TilesheetData dat = GetTileSheet ( GetCurrentLevel ( ) , tileID ) ;
TilesheetData dat = GetTileSheet ( GetCurrentLevel ( ) , tileID ) ;
if ( dat . tileset . staircaseTiles . find ( tileID ) ! = dat . tileset . staircaseTiles . end ( ) ) {
if ( dat . tileset . staircaseTiles . find ( tileID ) ! = dat . tileset . staircaseTiles . end ( ) ) {
@ -179,133 +179,133 @@ void Crawler::HandleUserInput(float fElapsedTime){
} ;
} ;
std : : string staircaseDirection = GetPlayerStaircaseDirection ( ) ;
std : : string staircaseDirection = GetPlayerStaircaseDirection ( ) ;
if ( RightHeld ( ) ) {
if ( RightHeld ( ) ) {
player . SetX ( player . GetX ( ) + fElapsedTime * 100 * player . GetMoveSpdMult ( ) ) ;
player - > SetX ( player - > GetX ( ) + fElapsedTime * 100 * player - > GetMoveSpdMult ( ) ) ;
if ( staircaseDirection = = " RIGHT " ) {
if ( staircaseDirection = = " RIGHT " ) {
player . SetY ( player . GetY ( ) - 60 * fElapsedTime * player . GetMoveSpdMult ( ) ) ;
player - > SetY ( player - > GetY ( ) - 60 * fElapsedTime * player - > GetMoveSpdMult ( ) ) ;
} else
} else
if ( staircaseDirection = = " LEFT " ) {
if ( staircaseDirection = = " LEFT " ) {
player . SetY ( player . GetY ( ) + 60 * fElapsedTime * player . GetMoveSpdMult ( ) ) ;
player - > SetY ( player - > GetY ( ) + 60 * fElapsedTime * player - > GetMoveSpdMult ( ) ) ;
}
}
player . SetFacingDirection ( RIGHT ) ;
player - > SetFacingDirection ( RIGHT ) ;
if ( player . GetState ( ) = = State : : NORMAL ) {
if ( player - > GetState ( ) = = State : : NORMAL ) {
player . UpdateWalkingAnimation ( RIGHT ) ;
player - > UpdateWalkingAnimation ( RIGHT ) ;
}
}
setIdleAnimation = false ;
setIdleAnimation = false ;
}
}
if ( LeftHeld ( ) ) {
if ( LeftHeld ( ) ) {
player . SetX ( player . GetX ( ) - fElapsedTime * 100 * player . GetMoveSpdMult ( ) ) ;
player - > SetX ( player - > GetX ( ) - fElapsedTime * 100 * player - > GetMoveSpdMult ( ) ) ;
if ( staircaseDirection = = " RIGHT " ) {
if ( staircaseDirection = = " RIGHT " ) {
player . SetY ( player . GetY ( ) + 60 * fElapsedTime * player . GetMoveSpdMult ( ) ) ;
player - > SetY ( player - > GetY ( ) + 60 * fElapsedTime * player - > GetMoveSpdMult ( ) ) ;
} else
} else
if ( staircaseDirection = = " LEFT " ) {
if ( staircaseDirection = = " LEFT " ) {
player . SetY ( player . GetY ( ) - 60 * fElapsedTime * player . GetMoveSpdMult ( ) ) ;
player - > SetY ( player - > GetY ( ) - 60 * fElapsedTime * player - > GetMoveSpdMult ( ) ) ;
}
}
if ( setIdleAnimation ) {
if ( setIdleAnimation ) {
player . SetFacingDirection ( LEFT ) ;
player - > SetFacingDirection ( LEFT ) ;
if ( player . GetState ( ) = = State : : NORMAL ) {
if ( player - > GetState ( ) = = State : : NORMAL ) {
player . UpdateWalkingAnimation ( LEFT ) ;
player - > UpdateWalkingAnimation ( LEFT ) ;
}
}
}
}
setIdleAnimation = false ;
setIdleAnimation = false ;
}
}
if ( UpHeld ( ) ) {
if ( UpHeld ( ) ) {
player . SetY ( player . GetY ( ) - fElapsedTime * 100 * player . GetMoveSpdMult ( ) ) ;
player - > SetY ( player - > GetY ( ) - fElapsedTime * 100 * player - > GetMoveSpdMult ( ) ) ;
if ( setIdleAnimation ) {
if ( setIdleAnimation ) {
player . SetFacingDirection ( UP ) ;
player - > SetFacingDirection ( UP ) ;
if ( player . GetState ( ) = = State : : NORMAL ) {
if ( player - > GetState ( ) = = State : : NORMAL ) {
player . UpdateWalkingAnimation ( UP ) ;
player - > UpdateWalkingAnimation ( UP ) ;
}
}
}
}
setIdleAnimation = false ;
setIdleAnimation = false ;
}
}
if ( DownHeld ( ) ) {
if ( DownHeld ( ) ) {
player . SetY ( player . GetY ( ) + fElapsedTime * 100 * player . GetMoveSpdMult ( ) ) ;
player - > SetY ( player - > GetY ( ) + fElapsedTime * 100 * player - > GetMoveSpdMult ( ) ) ;
if ( setIdleAnimation ) {
if ( setIdleAnimation ) {
player . SetFacingDirection ( DOWN ) ;
player - > SetFacingDirection ( DOWN ) ;
if ( player . GetState ( ) = = State : : NORMAL ) {
if ( player - > GetState ( ) = = State : : NORMAL ) {
player . UpdateWalkingAnimation ( DOWN ) ;
player - > UpdateWalkingAnimation ( DOWN ) ;
}
}
}
}
setIdleAnimation = false ;
setIdleAnimation = false ;
}
}
}
}
if ( UpReleased ( ) ) {
if ( UpReleased ( ) ) {
player . SetLastReleasedMovementKey ( UP ) ;
player - > SetLastReleasedMovementKey ( UP ) ;
if ( player . GetState ( ) = = State : : NORMAL ) {
if ( player - > GetState ( ) = = State : : NORMAL ) {
if ( RightHeld ( ) ) {
if ( RightHeld ( ) ) {
player . UpdateWalkingAnimation ( RIGHT ) ;
player - > UpdateWalkingAnimation ( RIGHT ) ;
} else
} else
if ( DownHeld ( ) ) {
if ( DownHeld ( ) ) {
player . UpdateWalkingAnimation ( DOWN ) ;
player - > UpdateWalkingAnimation ( DOWN ) ;
} else
} else
if ( LeftHeld ( ) ) {
if ( LeftHeld ( ) ) {
player . UpdateWalkingAnimation ( LEFT ) ;
player - > UpdateWalkingAnimation ( LEFT ) ;
}
}
}
}
}
}
if ( RightReleased ( ) ) {
if ( RightReleased ( ) ) {
player . SetLastReleasedMovementKey ( RIGHT ) ;
player - > SetLastReleasedMovementKey ( RIGHT ) ;
if ( player . GetState ( ) = = State : : NORMAL ) {
if ( player - > GetState ( ) = = State : : NORMAL ) {
if ( UpHeld ( ) ) {
if ( UpHeld ( ) ) {
player . UpdateWalkingAnimation ( UP ) ;
player - > UpdateWalkingAnimation ( UP ) ;
} else
} else
if ( DownHeld ( ) ) {
if ( DownHeld ( ) ) {
player . UpdateWalkingAnimation ( DOWN ) ;
player - > UpdateWalkingAnimation ( DOWN ) ;
} else
} else
if ( LeftHeld ( ) ) {
if ( LeftHeld ( ) ) {
player . UpdateWalkingAnimation ( LEFT ) ;
player - > UpdateWalkingAnimation ( LEFT ) ;
}
}
}
}
}
}
if ( LeftReleased ( ) ) {
if ( LeftReleased ( ) ) {
player . SetLastReleasedMovementKey ( LEFT ) ;
player - > SetLastReleasedMovementKey ( LEFT ) ;
if ( player . GetState ( ) = = State : : NORMAL ) {
if ( player - > GetState ( ) = = State : : NORMAL ) {
if ( RightHeld ( ) ) {
if ( RightHeld ( ) ) {
player . UpdateWalkingAnimation ( RIGHT ) ;
player - > UpdateWalkingAnimation ( RIGHT ) ;
} else
} else
if ( DownHeld ( ) ) {
if ( DownHeld ( ) ) {
player . UpdateWalkingAnimation ( DOWN ) ;
player - > UpdateWalkingAnimation ( DOWN ) ;
} else
} else
if ( UpHeld ( ) ) {
if ( UpHeld ( ) ) {
player . UpdateWalkingAnimation ( UP ) ;
player - > UpdateWalkingAnimation ( UP ) ;
}
}
}
}
}
}
if ( DownReleased ( ) ) {
if ( DownReleased ( ) ) {
player . SetLastReleasedMovementKey ( DOWN ) ;
player - > SetLastReleasedMovementKey ( DOWN ) ;
if ( player . GetState ( ) = = State : : NORMAL ) {
if ( player - > GetState ( ) = = State : : NORMAL ) {
if ( RightHeld ( ) ) {
if ( RightHeld ( ) ) {
player . UpdateWalkingAnimation ( RIGHT ) ;
player - > UpdateWalkingAnimation ( RIGHT ) ;
} else
} else
if ( UpHeld ( ) ) {
if ( UpHeld ( ) ) {
player . UpdateWalkingAnimation ( UP ) ;
player - > UpdateWalkingAnimation ( UP ) ;
} else
} else
if ( LeftHeld ( ) ) {
if ( LeftHeld ( ) ) {
player . UpdateWalkingAnimation ( LEFT ) ;
player - > UpdateWalkingAnimation ( LEFT ) ;
}
}
}
}
}
}
if ( player . GetState ( ) ! = State : : NORMAL ) {
if ( player - > GetState ( ) ! = State : : NORMAL ) {
setIdleAnimation = false ;
setIdleAnimation = false ;
}
}
if ( setIdleAnimation ) {
if ( setIdleAnimation ) {
switch ( player . GetLastReleasedMovementKey ( ) ) {
switch ( player - > GetLastReleasedMovementKey ( ) ) {
case UP : {
case UP : {
player . UpdateIdleAnimation ( UP ) ;
player - > UpdateIdleAnimation ( UP ) ;
} break ;
} break ;
case DOWN : {
case DOWN : {
player . UpdateIdleAnimation ( DOWN ) ;
player - > UpdateIdleAnimation ( DOWN ) ;
} break ;
} break ;
case LEFT : {
case LEFT : {
player . UpdateIdleAnimation ( LEFT ) ;
player - > UpdateIdleAnimation ( LEFT ) ;
} break ;
} break ;
case RIGHT : {
case RIGHT : {
player . UpdateIdleAnimation ( RIGHT ) ;
player - > UpdateIdleAnimation ( RIGHT ) ;
} break ;
} break ;
default : {
default : {
player . UpdateIdleAnimation ( DOWN ) ;
player - > UpdateIdleAnimation ( DOWN ) ;
}
}
}
}
}
}
@ -326,7 +326,7 @@ void Crawler::UpdateCamera(float fElapsedTime){
}
}
worldShake + = worldShakeVel * fElapsedTime ;
worldShake + = worldShakeVel * fElapsedTime ;
} else {
} else {
camera . SetTarget ( player . GetPos ( ) ) ;
camera . SetTarget ( player - > GetPos ( ) ) ;
}
}
worldShakeTime = std : : max ( 0.f , worldShakeTime - fElapsedTime ) ;
worldShakeTime = std : : max ( 0.f , worldShakeTime - fElapsedTime ) ;
camera . Update ( fElapsedTime ) ;
camera . Update ( fElapsedTime ) ;
@ -388,9 +388,9 @@ void Crawler::UpdateBullets(float fElapsedTime){
}
}
}
}
} else {
} else {
if ( b - > OnUpperLevel ( ) = = player . OnUpperLevel ( ) & & geom2d : : overlaps ( geom2d : : circle ( player . GetPos ( ) , 12 * player . GetSizeMult ( ) / 2 ) , geom2d : : circle ( b - > pos , b - > radius ) ) ) {
if ( b - > OnUpperLevel ( ) = = player - > OnUpperLevel ( ) & & geom2d : : overlaps ( geom2d : : circle ( player - > GetPos ( ) , 12 * player - > GetSizeMult ( ) / 2 ) , geom2d : : circle ( b - > pos , b - > radius ) ) ) {
if ( player . Hurt ( b - > damage ) ) {
if ( player - > Hurt ( b - > damage ) ) {
if ( b - > PlayerHit ( player ) ) {
if ( b - > PlayerHit ( GetPlayer ( ) ) ) {
it = BULLET_LIST . erase ( it ) ;
it = BULLET_LIST . erase ( it ) ;
if ( it = = BULLET_LIST . end ( ) ) {
if ( it = = BULLET_LIST . end ( ) ) {
break ;
break ;
@ -431,10 +431,10 @@ void Crawler::HurtEnemies(vf2d pos,float radius,int damage,bool upperLevel){
}
}
void Crawler : : 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 ) {
void Crawler : : 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 ) {
Player & pl = player ;
Player * pl = GetPlayer ( ) ;
for ( auto it = MONSTER_LIST . begin ( ) ; it ! = MONSTER_LIST . end ( ) ; + + it ) {
for ( auto it = MONSTER_LIST . begin ( ) ; it ! = MONSTER_LIST . end ( ) ; + + it ) {
Monster & m = * it ;
Monster & m = * it ;
if ( m . GetPos ( ) . y < pl . GetPos ( ) . y ) { //This monster renders before the player does (behind the player)
if ( m . GetPos ( ) . y < pl - > GetPos ( ) . y ) { //This monster renders before the player does (behind the player)
if ( m . OnUpperLevel ( ) ) {
if ( m . OnUpperLevel ( ) ) {
monstersBeforeUpper . push_back ( & m ) ;
monstersBeforeUpper . push_back ( & m ) ;
} else {
} else {
@ -489,11 +489,11 @@ void Crawler::RenderWorld(float fElapsedTime){
for ( LayerTag & layer : MAP_DATA [ currentLevel ] . LayerData ) {
for ( LayerTag & layer : MAP_DATA [ currentLevel ] . LayerData ) {
if ( IsBridgeLayer ( layer ) ) {
if ( IsBridgeLayer ( layer ) ) {
bridgeLayer = & layer ;
bridgeLayer = & layer ;
if ( ! bridgeLayerFade & & ! player . upperLevel ) {
if ( ! bridgeLayerFade & & ! player - > upperLevel ) {
int tileID = layer . tiles [ y ] [ x ] - 1 ;
int tileID = layer . tiles [ y ] [ x ] - 1 ;
if ( tileID ! = - 1 ) {
if ( tileID ! = - 1 ) {
int playerXTruncated = int ( player . GetPos ( ) . x ) / 24 ;
int playerXTruncated = int ( player - > GetPos ( ) . x ) / 24 ;
int playerYTruncated = int ( player . GetPos ( ) . y ) / 24 ;
int playerYTruncated = int ( player - > GetPos ( ) . y ) / 24 ;
if ( playerXTruncated = = x & & playerYTruncated = = y ) {
if ( playerXTruncated = = x & & playerYTruncated = = y ) {
bridgeLayerFade = true ;
bridgeLayerFade = true ;
}
}
@ -534,13 +534,13 @@ void Crawler::RenderWorld(float fElapsedTime){
std : : vector < Monster * > monstersBeforeLower , monstersAfterLower , monstersBeforeUpper , monstersAfterUpper ;
std : : vector < Monster * > monstersBeforeLower , monstersAfterLower , monstersBeforeUpper , monstersAfterUpper ;
std : : vector < Bullet * > bulletsLower , bulletsUpper ;
std : : vector < Bullet * > bulletsLower , bulletsUpper ;
std : : vector < Effect * > backgroundEffectsLower , backgroundEffectsUpper , foregroundEffectsLower , foregroundEffectsUpper ;
std : : vector < Effect * > backgroundEffectsLower , backgroundEffectsUpper , foregroundEffectsLower , foregroundEffectsUpper ;
Player & pl = player ;
Player * pl = GetPlayer ( ) ;
PopulateRenderLists ( monstersBeforeLower , monstersBeforeUpper , monstersAfterLower , monstersAfterUpper , bulletsLower , bulletsUpper , backgroundEffectsLower , backgroundEffectsUpper , foregroundEffectsLower , foregroundEffectsUpper ) ;
PopulateRenderLists ( monstersBeforeLower , monstersBeforeUpper , monstersAfterLower , monstersAfterUpper , bulletsLower , bulletsUpper , backgroundEffectsLower , backgroundEffectsUpper , foregroundEffectsLower , foregroundEffectsUpper ) ;
if ( player . GetZ ( ) > 0 ) {
if ( player - > GetZ ( ) > 0 ) {
vf2d shadowScale = vf2d { 8 / 3.f , 1 } / std : : max ( 1.f , player . GetZ ( ) / 4 ) ;
vf2d shadowScale = vf2d { 8 / 3.f , 1 } / std : : max ( 1.f , player - > GetZ ( ) / 4 ) ;
view . DrawDecal ( player . GetPos ( ) - vf2d { 3 , 3 } * shadowScale / 2 + vf2d { 0 , 6 } , GFX_Circle . Decal ( ) , shadowScale ) ;
view . DrawDecal ( player - > GetPos ( ) - vf2d { 3 , 3 } * shadowScale / 2 + vf2d { 0 , 6 } , GFX_Circle . Decal ( ) , shadowScale ) ;
}
}
for ( Effect * e : backgroundEffectsLower ) {
for ( Effect * e : backgroundEffectsLower ) {
e - > Draw ( ) ;
e - > Draw ( ) ;
@ -548,20 +548,20 @@ void Crawler::RenderWorld(float fElapsedTime){
for ( Monster * m : monstersBeforeLower ) {
for ( Monster * m : monstersBeforeLower ) {
m - > Draw ( ) ;
m - > Draw ( ) ;
}
}
vf2d playerScale = vf2d ( player . GetSizeMult ( ) , player . GetSizeMult ( ) ) ;
vf2d playerScale = vf2d ( player - > GetSizeMult ( ) , player - > GetSizeMult ( ) ) ;
vf2d playerPosition = player . GetPos ( ) ;
vf2d playerPosition = player - > GetPos ( ) ;
# define RENDER_PLAYER \
# define RENDER_PLAYER \
if ( player . teleportAnimationTimer > 0 ) { \
if ( player - > teleportAnimationTimer > 0 ) { \
playerScale . x = 120 * abs ( pow ( player . teleportAnimationTimer - 0.175 , 3 ) ) ; \
playerScale . x = 120 * abs ( pow ( player - > teleportAnimationTimer - 0.175 , 3 ) ) ; \
playerPosition = player . teleportStartPosition . lerp ( player . teleportTarget , ( 0.35 - player . teleportAnimationTimer ) / 0.35 ) ; \
playerPosition = player - > teleportStartPosition . lerp ( player - > teleportTarget , ( 0.35 - player - > teleportAnimationTimer ) / 0.35 ) ; \
view . DrawPartialRotatedDecal ( playerPosition + vf2d { 0 , - player . GetZ ( ) } , player . GetFrame ( ) . GetSourceImage ( ) - > Decal ( ) , player . GetSpinAngle ( ) , { 12 , 12 } , player . GetFrame ( ) . GetSourceRect ( ) . pos , player . GetFrame ( ) . GetSourceRect ( ) . size , playerScale , 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 ) ; \
view . DrawPartialRotatedDecal ( playerPosition + vf2d { 0 , - player - > GetZ ( ) } , player - > GetFrame ( ) . GetSourceImage ( ) - > Decal ( ) , player - > GetSpinAngle ( ) , { 12 , 12 } , player - > GetFrame ( ) . GetSourceRect ( ) . pos , player - > GetFrame ( ) . GetSourceRect ( ) . size , playerScale , 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 ) ; \
} else { view . DrawPartialRotatedDecal ( playerPosition + vf2d { 0 , - player . GetZ ( ) } , player . GetFrame ( ) . GetSourceImage ( ) - > Decal ( ) , player . GetSpinAngle ( ) , { 12 , 12 } , player . GetFrame ( ) . GetSourceRect ( ) . pos , player . GetFrame ( ) . GetSourceRect ( ) . size , playerScale , 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 ) ; }
} else { view . DrawPartialRotatedDecal ( playerPosition + vf2d { 0 , - player - > GetZ ( ) } , player - > GetFrame ( ) . GetSourceImage ( ) - > Decal ( ) , player - > GetSpinAngle ( ) , { 12 , 12 } , player - > GetFrame ( ) . GetSourceRect ( ) . pos , player - > GetFrame ( ) . GetSourceRect ( ) . size , playerScale , 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 ) ; }
//define end
//define end
if ( ! player . upperLevel ) {
if ( ! player - > upperLevel ) {
RENDER_PLAYER
RENDER_PLAYER
}
}
if ( player . GetState ( ) = = State : : BLOCK ) {
if ( player - > GetState ( ) = = State : : BLOCK ) {
view . DrawDecal ( player . GetPos ( ) - vf2d { 12 , 12 } , GFX_BLOCK_BUBBLE . Decal ( ) ) ;
view . DrawDecal ( player - > GetPos ( ) - vf2d { 12 , 12 } , GFX_BLOCK_BUBBLE . Decal ( ) ) ;
}
}
for ( Monster * m : monstersAfterLower ) {
for ( Monster * m : monstersAfterLower ) {
m - > Draw ( ) ;
m - > Draw ( ) ;
@ -575,7 +575,7 @@ void Crawler::RenderWorld(float fElapsedTime){
# pragma region Foreground Rendering
# pragma region Foreground Rendering
for ( TileGroup & group : foregroundTileGroups ) {
for ( TileGroup & group : foregroundTileGroups ) {
if ( view . IsRectVisible ( group . GetRange ( ) . pos , group . GetRange ( ) . size ) ) {
if ( view . IsRectVisible ( group . GetRange ( ) . pos , group . GetRange ( ) . size ) ) {
if ( geom2d : : overlaps ( group . GetFadeRange ( ) , player . pos ) ) {
if ( geom2d : : overlaps ( group . GetFadeRange ( ) , player - > pos ) ) {
group . playerBehind = true ;
group . playerBehind = true ;
group . fadeFactor = std : : min ( group . fadeFactor + fElapsedTime , TileGroup : : FADE_TIME ) ;
group . fadeFactor = std : : min ( group . fadeFactor + fElapsedTime , TileGroup : : FADE_TIME ) ;
} else {
} else {
@ -621,7 +621,7 @@ void Crawler::RenderWorld(float fElapsedTime){
for ( Monster * m : monstersBeforeUpper ) {
for ( Monster * m : monstersBeforeUpper ) {
m - > Draw ( ) ;
m - > Draw ( ) ;
}
}
if ( player . upperLevel ) {
if ( player - > upperLevel ) {
RENDER_PLAYER
RENDER_PLAYER
}
}
for ( Monster * m : monstersAfterUpper ) {
for ( Monster * m : monstersAfterUpper ) {
@ -635,7 +635,7 @@ void Crawler::RenderWorld(float fElapsedTime){
}
}
# pragma region Upper Foreground Rendering
# pragma region Upper Foreground Rendering
for ( TileGroup & group : upperForegroundTileGroups ) {
for ( TileGroup & group : upperForegroundTileGroups ) {
if ( geom2d : : overlaps ( group . GetFadeRange ( ) , player . pos ) ) {
if ( geom2d : : overlaps ( group . GetFadeRange ( ) , player - > pos ) ) {
group . playerBehind = true ;
group . playerBehind = true ;
group . fadeFactor = std : : min ( group . fadeFactor + fElapsedTime , TileGroup : : FADE_TIME ) ;
group . fadeFactor = std : : min ( group . fadeFactor + fElapsedTime , TileGroup : : FADE_TIME ) ;
} else {
} else {
@ -665,8 +665,8 @@ void Crawler::RenderWorld(float fElapsedTime){
}
}
}
}
Player & Crawler : : GetPlayer ( ) {
Player * Crawler : : GetPlayer ( ) {
return player ;
return player . get ( ) ;
}
}
void Crawler : : RenderHud ( ) {
void Crawler : : RenderHud ( ) {
@ -679,10 +679,10 @@ void Crawler::RenderHud(){
return newName ;
return newName ;
} ;
} ;
std : : vector < Ability > cooldowns {
std : : vector < Ability > cooldowns {
player . rightClickAbility ,
player - > rightClickAbility ,
player . ability1 ,
player - > ability1 ,
player . ability2 ,
player - > ability2 ,
player . ability3
player - > ability3
} ;
} ;
std : : vector < Ability > activeCooldowns ;
std : : vector < Ability > activeCooldowns ;
std : : copy_if ( cooldowns . begin ( ) , cooldowns . end ( ) , std : : back_inserter ( activeCooldowns ) , [ ] ( Ability a ) {
std : : copy_if ( cooldowns . begin ( ) , cooldowns . end ( ) , std : : back_inserter ( activeCooldowns ) , [ ] ( Ability a ) {
@ -706,23 +706,23 @@ void Crawler::RenderHud(){
}
}
DrawDecal ( { 2 , 2 } , GFX_Heart . Decal ( ) ) ;
DrawDecal ( { 2 , 2 } , GFX_Heart . Decal ( ) ) ;
DrawDecal ( { 2 , 20 } , GFX_Mana . Decal ( ) ) ;
DrawDecal ( { 2 , 20 } , GFX_Mana . Decal ( ) ) ;
std : : string text = player . GetHealth ( ) > 0 ? std : : to_string ( player . GetHealth ( ) ) : " X " ;
std : : string text = player - > GetHealth ( ) > 0 ? std : : to_string ( player - > GetHealth ( ) ) : " X " ;
std : : string text_mana = std : : to_string ( player . GetMana ( ) ) ;
std : : string text_mana = std : : to_string ( player - > GetMana ( ) ) ;
DrawShadowStringPropDecal ( { 20 , 3 } , text , WHITE , BLACK , { 2 , 2 } ) ;
DrawShadowStringPropDecal ( { 20 , 3 } , text , WHITE , BLACK , { 2 , 2 } ) ;
DrawShadowStringPropDecal ( { 24 , 23 } , text_mana , { 192 , 192 , 255 } , BLACK , { 1.5 , 1.5 } ) ;
DrawShadowStringPropDecal ( { 24 , 23 } , text_mana , { 192 , 192 , 255 } , BLACK , { 1.5 , 1.5 } ) ;
if ( player . notEnoughManaDisplay . second > 0 ) {
if ( player - > notEnoughManaDisplay . second > 0 ) {
std : : string displayText = " Not enough mana for " + player . notEnoughManaDisplay . first + " ! " ;
std : : string displayText = " Not enough mana for " + player - > notEnoughManaDisplay . first + " ! " ;
DrawShadowStringPropDecal ( vf2d { float ( ScreenWidth ( ) / 2 ) , float ( ScreenHeight ( ) / 4 ) } - GetTextSizeProp ( displayText ) / 2 , displayText , DARK_RED , VERY_DARK_RED ) ;
DrawShadowStringPropDecal ( vf2d { float ( ScreenWidth ( ) / 2 ) , float ( ScreenHeight ( ) / 4 ) } - GetTextSizeProp ( displayText ) / 2 , displayText , DARK_RED , VERY_DARK_RED ) ;
}
}
if ( player . notificationDisplay . second > 0 ) {
if ( player - > notificationDisplay . second > 0 ) {
std : : string displayText = player . notificationDisplay . first ;
std : : string displayText = player - > notificationDisplay . first ;
DrawShadowStringPropDecal ( vf2d { float ( ScreenWidth ( ) / 2 ) , float ( ScreenHeight ( ) / 4 ) - 24 } - GetTextSizeProp ( displayText ) / 2 , displayText , BLUE , VERY_DARK_BLUE ) ;
DrawShadowStringPropDecal ( vf2d { float ( ScreenWidth ( ) / 2 ) , float ( ScreenHeight ( ) / 4 ) - 24 } - GetTextSizeProp ( displayText ) / 2 , displayText , BLUE , VERY_DARK_BLUE ) ;
}
}
std : : string versionStr ( " v " + std : : to_string ( VERSION_MAJOR ) + " . " + std : : to_string ( VERSION_MINOR ) + " . " + std : : to_string ( VERSION_PATCH ) + " . " + std : : to_string ( VERSION_BUILD ) ) ;
std : : string versionStr ( " v " + std : : to_string ( VERSION_MAJOR ) + " . " + std : : to_string ( VERSION_MINOR ) + " . " + std : : to_string ( VERSION_PATCH ) + " . " + std : : to_string ( VERSION_BUILD ) ) ;
DrawShadowStringDecal ( vf2d { GetScreenSize ( ) } - vf2d { GetTextSize ( versionStr ) } * 0.4 , versionStr , WHITE , BLACK , { 0.4 , 0.4 } , 0.4 ) ;
DrawShadowStringDecal ( vf2d { GetScreenSize ( ) } - vf2d { GetTextSize ( versionStr ) } * 0.4 , versionStr , WHITE , BLACK , { 0.4 , 0.4 } , 0.4 ) ;
# ifdef DEBUG_POS
# ifdef DEBUG_POS
DrawShadowStringDecal ( { 0 , 128 } , player . GetPos ( ) . str ( ) ) ;
DrawShadowStringDecal ( { 0 , 128 } , player - > GetPos ( ) . str ( ) ) ;
# endif
# endif
}
}
@ -745,7 +745,7 @@ vf2d Crawler::GetWorldMousePos(){
void Crawler : : SetupWorldShake ( float duration ) {
void Crawler : : SetupWorldShake ( float duration ) {
worldShakeTime = duration ;
worldShakeTime = duration ;
worldShake = player . GetPos ( ) ;
worldShake = player - > GetPos ( ) ;
camera . SetTarget ( worldShake ) ;
camera . SetTarget ( worldShake ) ;
}
}
@ -878,8 +878,8 @@ void Crawler::LoadLevel(MapName map){
}
}
counter + + ;
counter + + ;
}
}
player . upperLevel = false ; //Assume player starts on lower level.
player - > upperLevel = false ; //Assume player starts on lower level.
player . SetPos ( MAP_DATA [ map ] . MapData . playerSpawnLocation ) ;
player - > SetPos ( MAP_DATA [ map ] . MapData . playerSpawnLocation ) ;
pathfinder . Initialize ( ) ;
pathfinder . Initialize ( ) ;
}
}
@ -969,6 +969,30 @@ std::map<std::string,std::vector<geom2d::rect<int>>>&Crawler::GetZoneData(MapNam
return MAP_DATA [ map ] . ZoneData ;
return MAP_DATA [ map ] . ZoneData ;
}
}
void Crawler : : ChangePlayerClass ( Class cl ) {
switch ( cl ) {
case WARRIOR : {
player . reset ( new Warrior ( ) ) ;
} break ;
case THIEF : {
player . reset ( new Thief ( ) ) ;
} break ;
case TRAPPER : {
player . reset ( new Trapper ( ) ) ;
} break ;
case RANGER : {
player . reset ( new Ranger ( ) ) ;
} break ;
case WIZARD : {
player . reset ( new Wizard ( ) ) ;
} break ;
case WITCH : {
player . reset ( new Witch ( ) ) ;
} break ;
}
GetPlayer ( ) - > UpdateIdleAnimation ( DOWN ) ;
}
int main ( )
int main ( )
{
{
Crawler demo ;
Crawler demo ;