Created
June 23, 2019 08:30
-
-
Save iamgabrielma/c3cc596dc3c536548119d8e025686c32 to your computer and use it in GitHub Desktop.
Calculates the closest FOV of an entity list
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void CalculateEntityClosestFOV(List<Entity> _listOfEntities) { | |
// We iterate through each item of the Entity list that was passed as an argument | |
foreach (var enemy in _listOfEntities) | |
{ | |
// If entity != null, proceed | |
if (enemy != null) | |
{ | |
// Get its position and set some constants that will create the quadrant around the entity: | |
Vector3 _entityLocation = new Vector3(enemy.entityLocation.x, enemy.entityLocation.y, 0); | |
int _entityVisibilityRadius = 3; | |
int _offsetQuadrant4 = (int)_entityLocation.x - _entityVisibilityRadius; // Top left corner of the entity quadrant. If were a clock, ir would be the 4th quarter. | |
int _offsetQuadrant1 = (int)_entityLocation.y - _entityVisibilityRadius; // Top right corner of the enemy quadrant. If were a clock, ir would be the 1st quarter. | |
// Loop through this quadrant | |
for (int x = _offsetQuadrant4; x < _entityLocation.x + _entityVisibilityRadius; x++) | |
{ | |
for (int y = _offsetQuadrant1; y < _entityLocation.y + _entityVisibilityRadius; y++) | |
{ | |
// If is floor, set a new color | |
if (floorMap.GetTile(new Vector3Int(x, y, 0)) != null && floorMap.tag == "Floor") | |
{ | |
_testing_closestFovMap.SetTile(new Vector3Int(x, y, 0), floorTile); | |
_testing_closestFovMap.SetColor(new Vector3Int(x, y, 0), Color.red); | |
} | |
// If is wall, set a new color | |
else if (wallMap.GetTile(new Vector3Int(x, y, 0)) != null && wallMap.tag == "Wall") | |
{ | |
_testing_closestFovMap.SetTile(new Vector3Int(x, y, 0), wallTile); | |
_testing_closestFovMap.SetColor(new Vector3Int(x, y, 0), Color.red); | |
} | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment