Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Discussion / Tactical Battle Engine Help...

Author
Message
LordDario
22
Years of Service
User Offline
Joined: 26th Apr 2003
Location:
Posted: 11th Jun 2005 13:19
Im currently working on a 2d tactical battle engine for my game and was hoping for some help with some questions i had reguarding attack range. Basically i'm not sure how I would go about determining if an enemy is in a heroes attack range or not. So that lets say I have an archer he can only attack enemies that are 2 squares away from them, when the players selects attack, how can i determine the range in which the archer can attack, and if an enemy is in its range?

Dario
NanoBrain
20
Years of Service
User Offline
Joined: 20th Jan 2005
Location: Portland, OR
Posted: 11th Jun 2005 14:49
LordDario,

I am not exactly sure how you have your game set up, as when you say "2 squares away". However, you can use a distance formula. The formula, compatible with DarkBasic being sqrt((x1 - x2)^2 + (y1 - y2)^2), y1 being the archer, and y2[/u] being the archer's target, beit a point on the grid or another character's location.




+NanoBrain+
LordDario
22
Years of Service
User Offline
Joined: 26th Apr 2003
Location:
Posted: 12th Jun 2005 01:27
nano you make everything sound so much easier lol. So using the distance formula let me try an example. Lets say that the archers x and y coordinates are (24,15), and the target's x and y coordinates are (22,15) and the archers max range is 2 then using the formula sqrt(24-22)^2 + (15-15)^2 you get a result of 2. now according to your formula 2 is not less than 2 so the code wouldnt execute, but if you put <= 2 then the code would work right?
Robot
20
Years of Service
User Offline
Joined: 27th May 2004
Location:
Posted: 12th Jun 2005 02:43 Edited at: 12th Jun 2005 02:44
That sounds right although I think <3 should work as well unless you are useing floating point numbers.

The happenings of tommorow are behind us now
LordDario
22
Years of Service
User Offline
Joined: 26th Apr 2003
Location:
Posted: 12th Jun 2005 03:00
well i think the formula will work as long as its at <= max range. I really like this formula though for calculating range, Thanks nanobrain for pointing it out. I guess some of my math classes were useful after all lol.
NanoBrain
20
Years of Service
User Offline
Joined: 20th Jan 2005
Location: Portland, OR
Posted: 12th Jun 2005 04:40
LordDario,

Yes, <= will do exactly that. If the enemy is equal or lesser than the specified range.

Speaking on the offtopic, I remember when I use to boast "I'll never use this math stuff in the real world!"...hehe. I was young and yet so wrong.


+NanoBrain+

Login to post a reply

Server time is: 2025-05-22 21:54:17
Your offset time is: 2025-05-22 21:54:17