matthew9090 Posted April 17, 2011 Share Posted April 17, 2011 how would you code a map for a browser game like travian? i know how it works but i cant code that sort of stuff. ive got my database set up like this x y player 1 1 1 2 etc.... so i when you click an arrow it will got to the next square along. Quote Link to comment https://forums.phpfreaks.com/topic/233950-browser-game-map/ Share on other sites More sharing options...
ignace Posted April 17, 2011 Share Posted April 17, 2011 Travian is an AJAX-driven application. So you need to think client-side instead of server-side first. The most notable is that in Travian you can walk your character down a specified path instead of just walking everywhere on the screen. Inspect the source code to find how they did it, and inspect their images. Once you figured out how they did it, you can think of how you will store it server-side. Quote Link to comment https://forums.phpfreaks.com/topic/233950-browser-game-map/#findComment-1202518 Share on other sites More sharing options...
matthew9090 Posted April 17, 2011 Author Share Posted April 17, 2011 the source code is really complicated. but i dont want to use ajax yet. i just need a basic map Quote Link to comment https://forums.phpfreaks.com/topic/233950-browser-game-map/#findComment-1202519 Share on other sites More sharing options...
ignace Posted April 17, 2011 Share Posted April 17, 2011 Then your current approach will suffice. Quote Link to comment https://forums.phpfreaks.com/topic/233950-browser-game-map/#findComment-1202522 Share on other sites More sharing options...
matthew9090 Posted April 17, 2011 Author Share Posted April 17, 2011 so how would you just select the coords from the database and put it into a table Quote Link to comment https://forums.phpfreaks.com/topic/233950-browser-game-map/#findComment-1202525 Share on other sites More sharing options...
matthew9090 Posted April 17, 2011 Author Share Posted April 17, 2011 anyone? Quote Link to comment https://forums.phpfreaks.com/topic/233950-browser-game-map/#findComment-1202564 Share on other sites More sharing options...
matthew9090 Posted April 17, 2011 Author Share Posted April 17, 2011 ive found a cool script now but it doesn't use the database. i need the database so it can get what player is on what square. <?php //game map test //set the grid size $grid_y = (int)30; $grid_x = (int)30; //x and y rows to display at once $display_rows = (int)15; //default display cordinate $x = (int)1; $y = (int)1; $param_x = $_REQUEST["xcord"]; $param_y = $_REQUEST["ycord"]; if (isset($param_x) && isset($param_y)) { //validate that the parameter is a legit point if (($param_x <= $grid_x) && ($param_x >= 1) && ($param_y <= $grid_y) &&($param_y >= 1)) { $x = (int)$param_x; $y = (int)$param_y; } } //the grid position desired will be set to display in the center of the viewable grid $display_half = round($display_rows / 2); $other_half = $display_rows - $display_half; //to display the target in the middle, you have to get the number of rows to display before and after it. //some simple math to take care of that. $start_x = ($x - $display_half) +1; $end_x = $x + $other_half; //if the $start_x variable is less than 1 the grid would be in the negatives. so set it to 1 if ($start_x < 1) { $start_x = 1; $end_x = $display_rows; } else //if $end_x is off the grid we have to compensate and add the remaining rows to the start. if ($end_x > $grid_x) { $extra = $end_x - $grid_x; $end_x = $grid_x; $start_x = $start_x - $extra; } //same applies for the y axis $start_y = ($y - $display_half) +1; $end_y = $y + $other_half; if ($start_y < 1) { $start_y = 1; $end_y = $display_rows; } else if ($end_y > $grid_y) { $extra = $end_y - $grid_y; $end_y = $grid_y; $start_y = $start_y - $extra; } //showing the current parameters echo "X $x - Y $y<br>"; ?> <!--grid table--> <table width="750" cellspacing="0" cellpadding="2" border="1"> <?php //these 2 for loops represent the y and x axis //using the data collected above the loops will properly display the grid for ($Ty = $start_y; $Ty <= $end_y; $Ty++) { //start new row echo '<tr>'; for ($Tx = $start_x; $Tx <= $end_x; $Tx++) { //show grid DisplayGrid($Tx,$Ty); } echo '</tr>'; } ?> </table> <?php function DisplayGrid($gridx,$gridy) { global $x, $y; $bgcolor = null; //highlight current select grid coordinate if ($gridx == $x && $gridy == $y) { $bgcolor = 'bgcolor="#c00000"'; } echo "<td width=\"50\" height=\"50\" $bgcolor align=center valign=center><a href=\"map.php?xcord=$gridx&ycord=$gridy\">[X]</a><br><font size=1>($gridx,$gridy)</font></td>"; } ?> so would i change the first 2 variables to a select? Quote Link to comment https://forums.phpfreaks.com/topic/233950-browser-game-map/#findComment-1202568 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.