I am basically just checking if the fish are in this map:
//"luuur"
//"llurr"
//"ll.rr"
//"lldrr"
//"ldddr"
where if the '.' char doesn't exist that's where a fish is, so the Shark should point in that direction.
The problem occurs where there are multiple fish.
">....",
"..>..",
"..*..",
".>...",
"..^>.",
I understand what I'm supposed to do, but I have no idea of how to do it, or how to even get started. The goal is just to get the Shark facing the same direction of the nearest fish. So basically the arrow "closest" to the middle.
Can someone help me out to get started with this?
Maybe like a separate function that calculates the distance of each element from the center?
I believe I know what you want to do. To find the distance of the fish, you'd need to calculate the distance. So the fish below for example has a distance of 2, since it has 1 less x and y value. 1 + 1 = 2 distance. The fish above is set on the same x, thus 1 + 0, it has a distance of 1. You could keep the current co-ordinates of the fish and replace them should another fish be closer. Once you've done this, just do what you're doing at the moment for a single fish, except using the co-ordinates of the fish and shark. If you want to get into 2d graphics, I'd recommend you have a look at a graphics library like SDL or SFML.