I am making this project that allows the player to push objects. I can test the player against the object array just fine using the “for” loop and I can move the objects around.
What I want to do now is test the objects against each other and have them move each other as well. Like, I want to push a block with the player and then push another block with the block I’m already pushing.
The blocks are all pushed into their own arrays, so how could I test them against each other?
Sure, you can place everything in the same array and use two
forloops:This example code assumes that
Entityis a base class for your objects that can touch each other; all of which are listed withinarray.