slyte33 Posted December 15, 2009 Share Posted December 15, 2009 Hello, I am displaying an 11x by 11y map for my game. I have a map 50x and 50y coords in my mysql DB with 2,500 rows, then I have in another table all the players information, including the x and y coords they are currently at. The problem is that if a player is at 1X, 50Y it will not show the correct amount of squares on the map, so I need a formula that will allow this. I do have a formula made for the player being less than 6X/6Y, but I need one for being over 44 out of 50. This is probably hard to understand, and if so, here is the code explaining it: if ($player->x < 6) { $xx = 12 - $player->x; // THIS CODE TAKES 12 AND SUBTRACTS FROM THE PLAYERS X COORDS $x = $player->x + $xx; // THIS CODE ADDS WHATEVER $XX IS TO THEIR CURRENT X COORD POSITION }else{ $x = $player->x + 6; // IF THEIR X COORD IS GREATER THAN 6, JUST ADD SIX TO SHOW 6 SQUARES } if ($player->y < 6) { $yy = 12 - $player->y; // THIS CODE TAKES 12 AND SUBTRACTS FROM THE PLAYERS Y COORDS $y = $player->y + $yy; // THIS CODE ADDS WHATEVER $YY IS TO THEIR CURRENT Y COORD POSITION }else{ $y = $player->y + 6; // IF THEIR Y COORD IS GREATER THAN 6, JUST ADD SIX TO SHOW 6 SQUARES } if ($player->x > 44) { //A CODE HERE THAT WILL ALWAYS EQUAL 11 WHEN PLAYERS X COORDS ARE GREATER THAN 44 }else{ $x2 = $player->x - 6; } if ($player->y > 44) { //A CODE HERE THAT WILL ALWAYS EQUAL 11 WHEN PLAYERS Y COORDS ARE GREATER THAN 44 }else{ $y2 = $player->y - 6; } $query = $db->execute("select * from travel where x<$x and y<$y and x>$x2 and y>$y2"); I hope you understand, all help is much appreciated, thanks Link to comment https://forums.phpfreaks.com/topic/185247-showing-11-squares-verical-and-horizontal-based-on-players-coords-for-map/ Share on other sites More sharing options...
teynon Posted December 21, 2009 Share Posted December 21, 2009 Ok, it's kind of hard to follow what you're asking, but if I am understanding correctly, here is what I see: If you are trying to display 11 rows and 11 columns, then thats too easy. You know your limits and you know your current row. Left_X=Current_X-5 Right_X=Current_X+5 if LEFT_X < 0 LEFT_X = 0 RIGHT_X = 11 (No math necessary) if RIGHT_X > 50 RIGHT_X = 50 LEFT_X = 50 - 11 (OR just 39) Then when you draw it out, use the left X and right X instead. Link to comment https://forums.phpfreaks.com/topic/185247-showing-11-squares-verical-and-horizontal-based-on-players-coords-for-map/#findComment-981796 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.