I am trying to create a "Mario" video game, and in order to obtain intersecting objects, our teacher provided us with an example demonstration, which allows the object to detect if it is touching EXACTLY one other object, and the first object that the method finds, is returned. I am trying, instead to return an array of every object that the current object is currently touching. I was capable of returning an array of every object currently touching it, but now I need an easy/efficient way to check if the array contains an object of a required type, such as
if (array.Contains(Mario))
{
//Do Work here
}
The array that is being checked if it Contains(Mario), is the returned array of the intersecting Sprites, but when I ask if it actually contains objects of type Mario, it says "Error 14 'WindowsGame10.Mario' is a 'type' but is used like a 'variable' ". I Know I could do this with a for loop, and ask each individual index within the array if (array[i].GetType() == typeof(Mario))
, but for the amount of times I would need to perform this check within the code, and retype the same code over and over again, I feel that I need to learn a more efficient way to perform this. I am in my first year of Computer Programming, and I am working with C# XNA, and I need to have some solution that I can understand. If there is a better way to do this, please let me know.