Jump to content

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/233950-browser-game-map/#findComment-1202518
Share on other sites

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?

 

Link to comment
https://forums.phpfreaks.com/topic/233950-browser-game-map/#findComment-1202568
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.