Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: timlump on Sat 06/05/2006 12:18:09

Title: Making cursor work in radius around character (SOLVED)
Post by: timlump on Sat 06/05/2006 12:18:09
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.
Title: Re: how would i make a cursor only work in a radius around a character
Post by: Ashen on Sat 06/05/2006 12:51:11
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:

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 (http://www.adventuregamestudio.co.uk/yabb/index.php?topic=13649.msg305918#msg305918), 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 (http://www.adventuregamestudio.co.uk/yabb/index.php?topic=25282.msg322062#msg322062), that might also give you some ideas. [/self-promotion]
Title: Re: how would i make a cursor only work in a radius around a character(solved)
Post by: timlump on Sat 06/05/2006 12:54:46
thanks