Making cursor work in radius around character (SOLVED)

Started by timlump, Sat 06/05/2006 12:18:09

Previous topic - Next topic

timlump

In my game i'm using a cursor as a weapon, but its a little unrealistic when you can just click an enemy through a wall and kill him,

How would I make this particular cursor work only in say a 100 pixel radius around him.

Ashen

You could either add a check to on_mouse_click, or to whatever you call to calculate the hit, that compares the target's location to the players. At it's most basic:
Code: ags

if (cTarget.x > player.x-50 && cTarget.x < player.x+50 && cTarget.y > player.y-50 && cTarget.y < player.y+50) {
  // Do attack
}
else Display ("Out of range");


Although that's a square checking area. KhrisMUC came up with a circular check, over in the RPG thread (scroll down a few posts for SSH's cleaned up, working version). I used something like it in a coding contest entry, that might also give you some ideas. [/self-promotion]
I know what you're thinking ... Don't think that.


SMF spam blocked by CleanTalk