I am making an evolution simulator where food will spawn in the world and cells will go around and eat the food. However, the "eating" mechanic is going wrong, currently the food won't be deleted when eaten, which leads to infinite food supply and exponential growth of the population. Each food object is marked with a 2 on the 2d matrix world, and is also an element in an array called foodVec. The former issue is fixed(checks if a cell is occupying a marked space and unmarks it):
if(matrix[obj.x][obj.y] == 2){
matrix[obj.x][obj.y] = 0;
}
but I need a reliable way of also removing this value from foodVec so the array doesn't just remark and replace the food particle next frame. How do I remove an object from an array knowing only its contents?