GameManager.Remove(GameObject)

This commit is contained in:
Ivan Filipenkov 2023-08-17 22:40:30 +03:00
parent b48bec2d6d
commit dd4a5c7fb2

View file

@ -25,7 +25,7 @@ namespace DangerousD.GameCore
public List<Player> players; public List<Player> players;
public List<GameObject> otherObjects = new(); public List<GameObject> otherObjects = new();
public Player GetPlayer1 { get; private set; } public Player GetPlayer1 => players[0];
public GameManager() public GameManager()
{ {
others = new List<GameObject>(); others = new List<GameObject>();
@ -49,7 +49,6 @@ namespace DangerousD.GameCore
{ {
livingEntities.Add(gameObject as LivingEntity); livingEntities.Add(gameObject as LivingEntity);
players.Add(objPl); players.Add(objPl);
GetPlayer1 = players[0];
} }
else if (gameObject is LivingEntity objLE) else if (gameObject is LivingEntity objLE)
{ {
@ -72,6 +71,35 @@ namespace DangerousD.GameCore
} }
} }
public void Remove(GameObject gameObject)
{
GetAllGameObjects.Remove(gameObject);
if (gameObject is Player objPl)
{
livingEntities.Remove(gameObject as LivingEntity);
players.Remove(objPl);
}
else if (gameObject is LivingEntity objLE)
{
livingEntities.Remove(objLE);
}
else if (gameObject is Entity objE)
{
entities.Remove(objE);
}
else if (gameObject is MapObject obj)
{
if (obj.IsColliderOn)
mapObjects.Remove(obj);
else
BackgroundObjects.Remove(obj);
}
else
{
otherObjects.Remove(gameObject);
}
}
public void Draw(SpriteBatch _spriteBatch) public void Draw(SpriteBatch _spriteBatch)
{ {
foreach (var item in BackgroundObjects) foreach (var item in BackgroundObjects)