This function can be used to tell if one div is in range of another div... both horizontally and vertically!
Took 3 days to figure out, please don't be harsh lmao.
Usage:
This would return true.isInRange("div232","div235",4);
This would return false.isInRange("div230","div235",4);
Code:
(paste into netmap.js)
I will be releasing a lot more of my code from now on.function isInRange(tag1,tag2,sqs) {
/*
If you go up one row in the map, the div tag is += 30 automatically
Likewise, if you go down, the div tag is -= 30, therefore,
the offset is 30
*/
var offset = 30;
//Getting the number on its own; changes 'div213' to '213'
var tag_1 = parseInt(tag1.replace("div", ""));
var tag_2 = parseInt(tag2.replace("div", ""));
var totalOffset = offset * sqs; //The total offset (furthest away)
var currentX = tag_1 - totalOffset; //Furthest north directly above tag1 (default)
//How many loops to go through, e.g sqs=2 .. 2 rows above , 2 below and the 1 middle row
var loops2 = sqs * 2; //
var total_loops = loops2 += 1; //Add on the row tag1 is on (mid row)
//Creating some default variables which are used inside the loop
var minX = 0;
var maxX = 0;
var i=0;
for (i=0;i<=total_loops;i++)
{
minX = currentX - sqs; //The smallest in range for this row
maxX = currentX + sqs; //The largest in range for this row
if(tag_2 >= minX && tag_2 <= maxX)
{
return true; //Houston, we are in range
}
currentX = currentX + offset; //Go up one row for the next loop (30 divs)
}
return false; //Houston, we have a problem
}
I was going to release keyboard movement, but it was already done by somebody.
I also promise to release my combat, chat and possibly trading systems when I finish them.
Toby