Area Calculation
#1
On editing.. wait for a moment
Like our Facebook Page: https://www.facebook.com/spiralmech
Email us for Suggestions or Questions: spiralmech@gmail.com
Reply
#2
Okay this can be done fairly simply, the main hitch is working out the directions and even number targeting. this best works with odd number targets. Here is the basic idea you want to do.

Code:
int range = player.range;
int range_mod = floor(range / 2);

select case player.direction:
case up:
int x_from = player.x - range_mod;
int x_to = player.x + range_mod;
int y_from = (player.y - 1);
int y_to = (player.y - 1) - (range - 1);
break;
case down:
int x_from = player.x - range_mod;
int x_to = player.x + range_mod;
int y_from = (player.y + 1);
int y_to = (player.y + 1) + (range - 1);
break;
case left:
int x_from = (player.x - 1);
int x_to = (player.x - 1) - (range - 1);
int y_from = player.y - range_mod;
int y_to = player.y + range_mod;
break;
case right:
int x_from = (player.x + 1);
int x_to = (player.x + 1) + (range - 1);
int y_from = player.y - range_mod;
int y_to = player.y + range_mod;
break;

var targets = from p in players
where p.x <= x_from && p.x => x_to &&
p.y <= y_from && p.y => y_to
select p as Player

foreach(targets as target)
target.hit(damage);

 There is a way to improve the code but it will take me a bit longer to actually work out. This uses the attacking player's position as to the middle of the attack which would be a better location to do the calculations from, I will post the alternative in a few minutes.
[Image: XerShades-Corner.png]
Reply
#3
This is quite similar to what i made
i guess, i'll just use it then..

Thanks~
Like our Facebook Page: https://www.facebook.com/spiralmech
Email us for Suggestions or Questions: spiralmech@gmail.com
Reply
#4
Here is the revised version using a formula that targets players from the middle out.

 
Code:
int range = player.range;
int range_center = floor(1 + range / 2);
int range_half = floor(range / 2);

select case player.direction
    case up:
        target_x = player.x;
        target_y = player.y - range_center;
        break;
    case down:
        target_x = player.x;
        target_y = player.y + range_center;
        break;
    case left:
        target_x = player.x - range_center;
        target_y = player.y;
        break;
    case right:
        target_x = player.x + range_center;
        target_y = player.y;
        break;
        
var targets = from p in players
                where p.x <= target_x - range_half &&
                      p.x >= target_x + range_half &&
                      p.y <= target_y - range_half &&
                      p.y >= target_y + range_half
                select p as Player
                
foreach(targets as target)
    if(target != player)
        target.attack(damage);
[Image: XerShades-Corner.png]
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)