New account registration is temporarily disabled.

[2K3] PROXIMITY DETECTION EVENT PROBLEM

Posts

Pages: 1
Trying to code a roguelike system under 2k3. So far I've stumbled upon a proximity detection issue I don't know how to fix.

The event affects enemies and items. When these are within the hero's sight (marked by 3 tile-wide lighter area around the hero), a switch activates to show their sprite. When not within the hero's range of sight, the switch is turned off and the item/enemy sprite disappears.

Here's a screenshot of the issue:

The treasure chest's sprite appears when it stands in the hero's sight except for the 4 tiles I colored red. It currently disappears if within this red area and it should not.

Here is the code:

I added some explanations and boxes in red to help you understand the code.

So the problem is, I don't understand what's wrong with this code that makes the chest's sprite invisible if within the red areas of sight.

Thanks for your help.
That looks like a nifty branch hell you've got there. Probably one of the branches is set wrong... but instead of looking through which it might be, you should change your approach.

After you've subtracted the coordinates of the hero to that of the chest, have 2 branches check if either of the current values are negative. If so, multiply that value by -1, making it positive. Then you add the values into each other and you will now have the value of the range.

In this case, that would mean you'd check if the sum you just got is equal to or less than 4. Should probably weed out the bug as well, since it's lot less code and easier to go through (and lot easier to change if you want to change the range of the hero)
I tried kentona's tutorial meanwhile but the radius didn't match my Sight picture.
Your suggestion fixed the bug though. It now works perfectly. Thanks a bunch!
Pages: 1