The structure stores each cell’s x and y position (of its top-left corner), and the type of object in it. For example, in the example above, there are blocks sitting in the 1st row, 3rd column, and 2nd row, 1st column. All other cells are blank.
I have events that allow balls to fall through the grid, stopping when the cell below them has a block in it. All this works nicely.
The problem I have is when trying to have a ball collect a bonus object as it falls. When the ball occupies the same cell as the bonus, the bonus object should be removed and the score updated (and the ball can carry on falling). However, I can’t work out how to only delete the specific bonus object the ball collides with… The closest I can find is the generic/sprite collision conditions, but they seem to muck up my grid-based movement (the ball skips the cell directly above the bonus).
What I need is an action that gets (or removes) an object at a specific position. E.g. Get object at x & y. Then I can delete just that object.
Alternatively, if there’s a way to store an object’s unique instance ID in my structure (as opposed to just a string representing its type) and then get an object instance based on a unique ID, that’d work too.
I think the problem is that the event that checks for a “collision” with a bonus tile doesn’t actually select a specific bonus object instance, so they all get deleted. Perhaps the simplest way to achieve this would be to add a condition to your bonus event to check the distance between the ball object and the bonus object using Common conditions>Distance between two objects and choosing 1 pixel.
There seems to be a similar problem with selecting the right ball object when changing the value of the moving variable as sometimes multiple balls will move. If you alter the events to be like this, it seems to work more like I would expect:
Thanks for the tip about using the Distance condition, that seems to do the trick! It’s a bit hack-ish, but I guess until there’s a ‘Get object at position’ action, it’ll have to do
Actually, in setting up your suggestion in my game, I discovered the ‘Pick nearest object’ condition (guess I didn’t see it before as I assumed something like this would be an action, not a condition). It seems to be more or less what I was looking for. I just give it the x and y positions ‘Ball.X()’ and ‘Ball.Y()’ respectively.
Yes, the ‘pick nearest object’ function does sound more like an action than a condition. I was going to suggest it first, but it can be a bit unpredictable when you are deleting objects.