@ -609,7 +609,6 @@ void Crawler::HurtEnemies(vf2d pos,float radius,int damage){
void Crawler : : RenderWorld ( float fElapsedTime ) {
Clear ( { 100 , 180 , 100 } ) ;
std : : vector < TileRenderData > foregroundTiles ;
for ( int x = view . GetTopLeftTile ( ) . x / 24 - 1 ; x < = view . GetBottomRightTile ( ) . x / 24 ; x + + ) {
for ( int y = view . GetTopLeftTile ( ) . y / 24 - 1 ; y < = view . GetBottomRightTile ( ) . y / 24 ; y + + ) {
if ( x > = 0 & & x < WORLD_SIZE . x & & y > = 0 & & y < WORLD_SIZE . y ) {
@ -622,9 +621,7 @@ void Crawler::RenderWorld(float fElapsedTime){
int tileSheetIndex = tileID - ( tileSheet . firstgid - 1 ) ;
int tileSheetX = tileSheetIndex % tileSheetWidth ;
int tileSheetY = tileSheetIndex / tileSheetWidth ;
if ( IsForegroundTile ( tileSheet , tileSheetIndex ) ) {
foregroundTiles . push_back ( { tileSheet . tileset . tileset - > Decal ( ) , vi2d { x , y } * 24 , vi2d { tileSheetX , tileSheetY } * 24 } ) ;
} else {
if ( ! IsForegroundTile ( tileSheet , tileSheetIndex ) ) {
view . DrawPartialDecal ( vi2d { x , y } * 24 , { 24 , 24 } , tileSheet . tileset . tileset - > Decal ( ) , vi2d { tileSheetX , tileSheetY } * 24 , { 24 , 24 } ) ;
}
}
@ -665,8 +662,17 @@ void Crawler::RenderWorld(float fElapsedTime){
for ( Bullet & b : PLAYER_BULLET_LIST ) {
b . Draw ( ) ;
}
for ( TileRenderData & foregroundTile : foregroundTiles ) {
view . DrawPartialDecal ( foregroundTile . pos , { 24 , 24 } , foregroundTile . tileset , foregroundTile . tileSheetPos , { 24 , 24 } , { 255 , 255 , 255 , uint8_t ( std : : clamp ( geom2d : : line < float > ( foregroundTile . pos + vi2d { 12 , 12 } , player . GetPos ( ) ) . length ( ) * 5 , 0.f , 255.f ) ) } ) ;
for ( TileGroup & group : foregroundTileGroups ) {
if ( geom2d : : overlaps ( group . GetRange ( ) , player . pos ) ) {
group . playerBehind = true ;
} else {
group . playerBehind = false ;
}
if ( view . IsRectVisible ( group . GetRange ( ) . pos , group . GetRange ( ) . size ) ) {
for ( TileRenderData & tile : group . GetTiles ( ) ) {
view . DrawPartialDecal ( tile . pos , { 24 , 24 } , tile . tileset , tile . tileSheetPos , { 24 , 24 } , { 255 , 255 , 255 , uint8_t ( group . playerBehind ? 128 : 255 ) } ) ;
}
}
}
for ( std : : vector < DamageNumber > : : iterator it = DAMAGENUMBER_LIST . begin ( ) ; it ! = DAMAGENUMBER_LIST . end ( ) ; + + it ) {
DamageNumber & dn = * it ;
@ -798,6 +804,7 @@ void Crawler::InitializeLevel(std::string mapFile,MapName map){
void Crawler : : LoadLevel ( MapName map ) {
SPAWNER_LIST . clear ( ) ;
foregroundTileGroups . clear ( ) ;
currentLevel = map ;
WORLD_SIZE = { MAP_DATA [ map ] . MapData . width , MAP_DATA [ map ] . MapData . height } ;
for ( SpawnerTag & spawner : MAP_DATA [ map ] . SpawnerData ) {
@ -811,6 +818,41 @@ void Crawler::LoadLevel(MapName map){
}
SPAWNER_LIST . push_back ( MonsterSpawner { { spawner . ObjectData . GetFloat ( " x " ) + spawnerRadius . x , spawner . ObjectData . GetFloat ( " y " ) + spawnerRadius . y } , spawnerRadius , monster_list } ) ;
}
for ( int x = 0 ; x < WORLD_SIZE . x ; x + + ) {
for ( int y = 0 ; y < WORLD_SIZE . y ; y + + ) {
for ( LayerTag & layer : MAP_DATA [ currentLevel ] . LayerData ) {
int tileID = layer . tiles [ y ] [ x ] - 1 ;
if ( tileID ! = - 1 ) {
TilesheetData tileSheet = GetTileSheet ( currentLevel , tileID ) ;
int tileSheetWidth = tileSheet . tileset . tileset - > Sprite ( ) - > width / 24 ;
int tileSheetHeight = tileSheet . tileset . tileset - > Sprite ( ) - > height / 24 ;
int tileSheetIndex = tileID - ( tileSheet . firstgid - 1 ) ;
int tileSheetX = tileSheetIndex % tileSheetWidth ;
int tileSheetY = tileSheetIndex / tileSheetWidth ;
if ( IsForegroundTile ( tileSheet , tileSheetIndex ) ) {
TileRenderData tile = { tileSheet . tileset . tileset - > Decal ( ) , vi2d { x , y } * 24 , vi2d { tileSheetX , tileSheetY } * 24 } ;
std : : cout < < " Tile " < < vi2d { x , y } < < " w/Tile ID " < < tileSheetIndex < < " is foreground tile. " < < std : : endl ;
bool foundGroup = false ;
for ( TileGroup & group : foregroundTileGroups ) {
if ( geom2d : : overlaps ( geom2d : : rect < int > { vi2d { x , y } * 24 - vi2d { 1 , 1 } , { 26 , 26 } } , group . GetRange ( ) ) ) {
std : : cout < < " Group found: " < < group . GetRange ( ) . pos < < " / " < < group . GetRange ( ) . size < < std : : endl ;
group . InsertTile ( tile ) ;
std : : cout < < " After: " < < group . GetRange ( ) . pos < < " / " < < group . GetRange ( ) . size < < std : : endl ;
foundGroup = true ;
break ;
}
}
if ( ! foundGroup ) {
TileGroup group ;
group . InsertTile ( tile ) ;
std : : cout < < " No Group found. New group: " < < group . GetRange ( ) . pos < < " / " < < group . GetRange ( ) . size < < std : : endl ;
foregroundTileGroups . push_back ( group ) ;
}
}
}
}
}
}
}
vi2d Crawler : : GetWorldSize ( ) {