public void Update(IAtlas atlas) { List <Vector2I> free = atlas.FreePositionsAround(Position, LayerType.Obstacle | LayerType.Object).ToList(); if (free.Count == 0) { return; } // filter out position with PathTiles free = free.Where(x => atlas.ActorsAt((Vector2)x, LayerType.Background).First().Actor.GetType() != typeof(PathTile)).ToList(); if (free.Count == 0) { return; } Vector2I targetPosition = free[m_rng.Next(free.Count)]; object[] args = { targetPosition }; Fruit fruit = (Fruit)Activator.CreateInstance(typeof(T), args); GameActorPosition fruitPosition = new GameActorPosition(fruit, new Vector2(targetPosition), LayerType.ObstacleInteractable); atlas.Add(fruitPosition); NextUpdateAfter = m_updatePeriod; }