Witam,

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:

  1. <?php
  2. //game map test
  3.  
  4. //set the grid size
  5. $grid_y = (int)30;
  6. $grid_x = (int)30;
  7.  
  8. //x and y rows to display at once
  9. $display_rows = (int)10;
  10.  
  11. //default display cordinate
  12. $x = (int)1;
  13. $y = (int)1;
  14.  
  15. $param_x = $_REQUEST["xcord"];
  16. $param_y = $_REQUEST["ycord"];
  17.  
  18. if (isset($param_x) && isset($param_y)) {
  19. //validate that the parameter is a legit point
  20. if (($param_x <= $grid_x) && ($param_x >= 1) && ($param_y <= $grid_y) &&($param_y >= 1)) {
  21. $x = (int)$param_x;
  22. $y = (int)$param_y;
  23. }
  24. }
  25.  
  26. //the grid position desired will be set to display in the center of the viewable grid
  27. $display_half = round($display_rows / 2);
  28. $other_half = $display_rows - $display_half;
  29.  
  30. //to display the target in the middle, you have to get the number of rows to display before and after it.
  31. //some simple math to take care of that.
  32. $start_x = ($x - $display_half) +1;
  33. $end_x = $x + $other_half;
  34.  
  35. //if the $start_x variable is less than 1 the grid would be in the negatives. so set it to 1
  36. if ($start_x < 1) {
  37. $start_x = 1;
  38. $end_x = $display_rows;
  39. } else
  40. //if $end_x is off the grid we have to compensate and add the remaining rows to the start.
  41. if ($end_x > $grid_x) {
  42. $extra = $end_x - $grid_x;
  43. $end_x = $grid_x;
  44.  
  45. $start_x = $start_x - $extra;
  46. }
  47.  
  48. //same applies for the y axis
  49. $start_y = ($y - $display_half) +1;
  50. $end_y = $y + $other_half;
  51.  
  52. if ($start_y < 1) {
  53. $start_y = 1;
  54. $end_y = $display_rows;
  55. } else
  56. if ($end_y > $grid_y) {
  57. $extra = $end_y - $grid_y;
  58. $end_y = $grid_y;
  59.  
  60. $start_y = $start_y - $extra;
  61. }
  62.  
  63. //showing the current parameters
  64. echo "X $x - Y $y<br>";
  65. ?>
  66.  
  67. <!--grid table-->
  68. <table width="750" cellspacing="0" cellpadding="2" border="1">
  69. <?php
  70. //these 2 for loops represent the y and x axis
  71. //using the data collected above the loops will properly display the grid
  72. for ($Ty = $start_y; $Ty <= $end_y; $Ty++) {
  73. //start new row
  74. echo '<tr>';
  75. for ($Tx = $start_x; $Tx <= $end_x; $Tx++) {
  76. //show grid
  77. DisplayGrid($Tx,$Ty);
  78. }
  79. echo '</tr>';
  80. }
  81. ?>
  82. </table>
  83.  
  84.  
  85. <?php
  86.  
  87. function DisplayGrid($gridx,$gridy) {
  88. global $x, $y;
  89.  
  90. $bgcolor = null;
  91. //highlight current select grid coordinate
  92. if ($gridx == $x && $gridy == $y) {
  93. $bgcolor = 'bgcolor="#c00000"';
  94. }
  95.  
  96. 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>";
  97. }
  98. ?>