MATLAB: How to reference when an image touches another

gameimages

I am essentially creating a game within MATLAB. Currently I am having an issue with causing something to happen if two objects touch.
An example of how the world is set up is a 10×10 cell named World.
so if World{x, y} = Player; World{5, 5} = Monster;
How would I be able to decrease Health by 1 if the player touches the monster? A simple Player == Monster doesn't work and I need advice.

Best Answer

You can save the positions of the player and the monster in separate position vectors (then you can use sqrt((x_p-x_m)^2+(y_p-y_m)^2) to calculate the distance). This would support non-integer locations.
You could also use binary matrices for location, which would enable you to check for a collision with any(monster_loc & player_loc). This method supports multiple monsters.
Which of these is the best approach depends on what the rest of you program does/needs.
Related Question