How do I reference when an image touches another?
Show older comments
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 10x10 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.
4 Comments
N.
on 15 Nov 2017
you can check if the player is next to the monster. That means, if the player is on (x,y) and the monster is on (x',y'), you check if (x,y) is equals to (x'-1,y') or (x'+1,y') or (x',y'-1) or (x',y'+1)
Rik
on 15 Nov 2017
Wouldn't it be more straightforward to save position separately? Because now a player can be overwritten by a monster.
Josh Ondayko
on 15 Nov 2017
Image Analyst
on 15 Nov 2017
Why is world a cell array instead of a regular numerical array????? Don't complicate things!
Accepted Answer
More Answers (0)
Categories
Find more on Strategy & Logic in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!