Salutations-
I have the following function:
It checks around the player's current X and Y coordinates for two specific events. It works, but IMO it is ugly. Would anyone know if there is a more elegant / efficient way to accomplish what I am attempting?
Thanks in advance.
I have the following function:
JavaScript:
$.IsNearEnough = function(event1_id, event2_id) {
let result = false;
let temp = [];
// get player's coordinates
let px = $gamePlayer.x;
let py = $gamePlayer.y;
// list events within a 3-tile perimeter of player's coordinates
temp[0] = $gameMap.eventIdXy(px, py - 1);
temp[1] = $gameMap.eventIdXy(px, py + 1);
temp[2] = $gameMap.eventIdXy(px - 1, py);
temp[3] = $gameMap.eventIdXy(px + 1, py);
temp[4] = $gameMap.eventIdXy(px - 1, py - 1);
temp[5] = $gameMap.eventIdXy(px + 1, py - 1);
temp[6] = $gameMap.eventIdXy(px - 1, py + 1);
temp[7] = $gameMap.eventIdXy(px + 1, py + 1);
temp[8] = $gameMap.eventIdXy(px, py - 2);
temp[9] = $gameMap.eventIdXy(px, py + 2);
temp[10] = $gameMap.eventIdXy(px - 2, py);
temp[11] = $gameMap.eventIdXy(px + 2, py);
temp[12] = $gameMap.eventIdXy(px - 2, py - 2);
temp[13] = $gameMap.eventIdXy(px + 2, py - 2);
temp[14] = $gameMap.eventIdXy(px - 2, py + 2);
temp[15] = $gameMap.eventIdXy(px + 2, py + 2);
temp[16] = $gameMap.eventIdXy(px, py - 3);
temp[17] = $gameMap.eventIdXy(px, py + 3);
temp[18] = $gameMap.eventIdXy(px - 3, py);
temp[19] = $gameMap.eventIdXy(px + 3, py);
temp[20] = $gameMap.eventIdXy(px - 3, py - 3);
temp[21] = $gameMap.eventIdXy(px + 3, py - 3);
temp[22] = $gameMap.eventIdXy(px - 3, py + 3);
temp[23] = $gameMap.eventIdXy(px + 3, py + 3);
// check if events sought are within that list
for (temp[24] = 0; temp[24] < 24; temp[24]++) {
if (temp[temp[24]] === event1_id) temp[25] = true;
if (temp[temp[24]] === event2_id) temp[26] = true;
};
if (temp[25] == true && temp[26] == true) result = true;
return result;
};
It checks around the player's current X and Y coordinates for two specific events. It works, but IMO it is ugly. Would anyone know if there is a more elegant / efficient way to accomplish what I am attempting?
Thanks in advance.