Tworze mape do gry browserowej.
Wczesniej miałem system, gdzie każda współrzedna miała przypisaną do siebie grafikę.
Obecnie chciałbym zrobić aby gracz się poruszał po tle.
tzn. mam obrazek 100 pól na 100 pół gdzie każda kratka to 32x32 i gracz chodzi po tej planszy.
Problem mój polega na tym, że nie mam zielonego pojęcia jak zrobić aby tło się przesuwało razem z graczem.
Jak zrobić aby pod to był podłożony rysunek który się przesuwa: http://www.westernlife.pl/mapa.php
Ten uproszczony skrypt wygląda tak:
<?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)10; //default display cordinate $x = (int)1; $y = (int)1; $param_x = $_REQUEST["xcord"]; $param_y = $_REQUEST["ycord"]; //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 $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 ?> <!--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 for ($Tx = $start_x; $Tx <= $end_x; $Tx++) { //show grid DisplayGrid($Tx,$Ty); } } ?> </table> <?php function DisplayGrid($gridx,$gridy) { $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=\"mapa.php?xcord=$gridx&ycord=$gridy\">[X]</a><br><font size=1>($gridx,$gridy)</font></td>"; } ?>