diff --git a/README.md b/README.md index fb671ae..147b001 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,3 @@ -# Template +# 2D Map +Простейший пример генерации карты для игр. \ No newline at end of file diff --git a/map.csv b/map.csv new file mode 100644 index 0000000..0f2a8ac --- /dev/null +++ b/map.csv @@ -0,0 +1,20 @@ +x;w;x;w;w;w;x;w;w;w;w;w;w;w;w;w;w;w;w;g;w;x;x;x;x;x;x;x;x;x;x;x;x;x;x;x;x;g;x;x; +x;x;x;w;x;x;x;x;g;g;g;g;g;g;g;g;g;w;g;g;g;g;g;g;g;x;x;x;g;g;g;g;x;x;x;g;g;g;g;x; +g;g;x;w;w;x;g;x;g;w;w;w;w;g;w;w;g;g;g;w;w;w;w;w;g;g;g;g;g;w;w;g;x;x;x;g;w;w;g;x; +x;g;x;w;m;x;g;g;g;g;g;g;w;g;w;g;g;w;g;g;g;g;g;w;w;g;w;g;w;w;g;g;g;g;g;g;g;w;g;w; +x;g;g;g;g;x;x;g;o;o;g;w;w;w;w;g;w;w;g;w;g;w;w;w;w;w;w;w;w;w;w;w;g;w;w;w;w;w;w;w; +x;x;g;x;g;g;g;g;g;o;g;w;g;w;w;w;w;w;g;w;g;g;g;w;g;w;g;w;g;w;g;w;g;w;g;g;g;g;w;w; +x;x;x;x;g;o;o;o;o;o;g;g;g;g;g;w;g;w;w;w;w;w;w;w;g;w;g;g;g;w;g;w;g;w;w;g;w;w;w;w; +g;g;g;g;g;g;g;g;g;o;o;g;o;o;g;g;g;g;g;w;g;w;g;w;g;w;g;w;w;w;g;w;g;g;g;g;g;w;x;w; +x;x;x;x;x;g;o;g;o;o;o;g;o;o;o;g;w;w;w;w;g;w;g;g;g;g;g;g;g;w;g;w;g;w;w;w;w;w;w;x; +x;g;x;g;g;g;o;o;o;g;o;g;g;g;o;g;w;g;w;w;g;g;g;w;w;w;w;w;g;g;g;g;g;w;g;g;g;g;g;g; +g;g;g;g;x;g;g;g;o;g;o;o;g;o;o;g;g;g;g;g;g;w;w;w;w;g;w;w;w;w;w;w;w;w;g;o;o;o;o;o; +x;x;x;g;x;g;o;o;o;g;g;o;g;o;o;o;o;o;o;o;g;g;g;g;g;g;g;g;g;g;g;g;g;g;g;g;g;o;o;w; +x;g;g;g;x;g;g;g;g;g;o;o;g;g;g;g;g;g;o;g;g;o;o;o;o;o;g;g;o;o;o;o;o;o;o;o;o;o;o;w; +x;x;g;x;x;x;g;o;g;o;o;o;o;o;o;o;o;g;o;o;g;g;g;g;g;o;g;g;g;g;g;g;g;g;g;g;g;o;g;o; +x;x;x;x;g;x;g;o;o;o;o;g;o;o;g;g;o;g;o;g;g;o;g;o;o;o;g;g;o;o;o;o;o;g;o;o;o;o;g;g; +x;x;g;g;g;g;g;g;o;g;g;g;g;g;g;o;o;o;o;g;o;o;g;g;g;o;g;g;o;x;x;x;o;g;g;g;g;g;g;o; +x;m;g;x;g;x;x;g;g;g;x;g;o;o;o;o;o;g;g;g;o;o;g;g;g;o;g;g;o;x;m;o;o;g;o;g;o;o;o;o; +x;x;g;x;g;x;x;g;x;g;x;g;g;g;g;g;o;g;o;o;o;o;g;o;o;o;g;g;o;x;x;x;o;g;o;g;o;g;g;g; +x;x;m;x;x;x;x;g;x;g;x;x;x;o;o;o;o;g;o;o;o;o;o;o;o;o;g;g;o;o;x;o;o;o;o;g;g;g;o;o; +x;x;x;x;x;x;x;x;x;x;x;x;x;x;x;x;o;o;o;o;o;o;o;o;o;o;g;g;o;o;o;o;o;o;o;g;o;o;o;o; \ No newline at end of file diff --git a/map.php b/map.php new file mode 100644 index 0000000..1cd3872 --- /dev/null +++ b/map.php @@ -0,0 +1,104 @@ + +error_reporting(E_ALL); +session_start(); + +if (!isset($_GET["name"])) $_GET["name"] ="map"; +//Читаем карту +$handle = fopen(htmlspecialchars($_GET["name"]).".csv", "r"); +while (($data = fgetcsv($handle, 1000, ";")) !== FALSE){ + $map[]=$data; +} +fclose($handle); +//Карта в двухмерном массиве $map + +//информация о квадрате +$infodot["g"]["status"] = "allow"; +$infodot["m"]["status"] = "allow"; + +if ($_POST['action']=='down' AND $infodot[$map[$_SESSION["y"]+1][$_SESSION["x"]]]["status"]=='allow'){ + $_SESSION["y"]++; +} +if ($_POST['action']=='up' AND $infodot[$map[$_SESSION["y"]-1][$_SESSION["x"]]]["status"]=='allow'){ + $_SESSION["y"]--; +} +if ($_POST['action']=='left' AND $infodot[$map[$_SESSION["y"]][$_SESSION["x"]-1]]["status"]=='allow'){ + $_SESSION["x"]--; +} +if ($_POST['action']=='right' AND $infodot[$map[$_SESSION["y"]][$_SESSION["x"]+1]]["status"]=='allow'){ + $_SESSION["x"]++; +} + +//если первый заход на карту +if (!isset($_SESSION["y"]) OR !isset($_SESSION["x"])){ + $_SESSION["y"]=5; + $_SESSION["x"]=5; +} +if ($_GET["name"]=="map2") { + $_SESSION["y"]=4; + $_SESSION["x"]=2; + +} + +//Строим квадрат 5Х5 вокруг игрока +$y = $_SESSION["y"]-2; +$y_end = $_SESSION["y"]+2; +$x = $_SESSION["x"]-2; +$x_end = $_SESSION["x"]+2; +$q = $x; +print "
"; + print ""; + print " | "; + } + else{ + print ""; + print ""; + print " | "; + } + $x++; + } + print "
+
+
+/*
+//Описываем свойство отдельной клетки с координатами 2,2
+if ($_SESSION["y"] == 2 AND $_SESSION["x"] == 2){
+ print "В этой клетке c координатами 2,2 находится магазин";
+}
+else{
+ print "В этой клетке нет активных элементов";
+}
+*/
+
+//Описываем свойство целого класса клеток
+if ($map[$_SESSION["y"]][$_SESSION["x"]] == "m"){ print "В этой клетке класса m находится магазин"; }
+
+//Бежим на вторую карту с первой.
+if ($_SESSION["y"] == 2 AND $_SESSION["x"] == 0){
+ print "Сменить локацию.";
+}
+
+?>
\ No newline at end of file
diff --git a/map2.csv b/map2.csv
new file mode 100644
index 0000000..af816c0
--- /dev/null
+++ b/map2.csv
@@ -0,0 +1,7 @@
+x;x;x;x;x
+x;m;w;w;x
+x;g;w;g;g
+x;g;w;g;x
+x;g;g;g;x
+x;w;g;g;x
+x;x;x;x;x
diff --git a/mapimg/end.png b/mapimg/end.png
new file mode 100644
index 0000000..68e1005
Binary files /dev/null and b/mapimg/end.png differ
diff --git a/mapimg/g.png b/mapimg/g.png
new file mode 100644
index 0000000..5f70678
Binary files /dev/null and b/mapimg/g.png differ
diff --git a/mapimg/m-e.png b/mapimg/m-e.png
new file mode 100644
index 0000000..28372c7
Binary files /dev/null and b/mapimg/m-e.png differ
diff --git a/mapimg/m-n.png b/mapimg/m-n.png
new file mode 100644
index 0000000..33fa9d4
Binary files /dev/null and b/mapimg/m-n.png differ
diff --git a/mapimg/m-s.png b/mapimg/m-s.png
new file mode 100644
index 0000000..2bdb44e
Binary files /dev/null and b/mapimg/m-s.png differ
diff --git a/mapimg/m-w.png b/mapimg/m-w.png
new file mode 100644
index 0000000..508cbfc
Binary files /dev/null and b/mapimg/m-w.png differ
diff --git a/mapimg/m.png b/mapimg/m.png
new file mode 100644
index 0000000..47f0f2d
Binary files /dev/null and b/mapimg/m.png differ
diff --git a/mapimg/o.png b/mapimg/o.png
new file mode 100644
index 0000000..e3a46e1
Binary files /dev/null and b/mapimg/o.png differ
diff --git a/mapimg/point.gif b/mapimg/point.gif
new file mode 100644
index 0000000..c325f48
Binary files /dev/null and b/mapimg/point.gif differ
diff --git a/mapimg/w.png b/mapimg/w.png
new file mode 100644
index 0000000..f94a28d
Binary files /dev/null and b/mapimg/w.png differ
diff --git a/mapimg/x.png b/mapimg/x.png
new file mode 100644
index 0000000..9feafc5
Binary files /dev/null and b/mapimg/x.png differ
diff --git a/showmap.php b/showmap.php
new file mode 100644
index 0000000..879d51b
--- /dev/null
+++ b/showmap.php
@@ -0,0 +1,103 @@
+
+session_start();
+
+if (!isset($_GET["name"])) $_GET["name"] ="map";
+
+//Читаем карту
+$handle = fopen(htmlspecialchars($_GET["name"]).".csv", "r");
+while (($data = fgetcsv($handle, 1000, ";")) !== FALSE){
+ $map[]=$data;
+}
+fclose($handle);
+//Карта в двухмерном массиве $map
+
+//информация о квадрате
+/*
+$infodot["g"]["status"] = "allow";
+$infodot["m"]["status"] = "allow";
+
+if ($_GET['action']=='down' AND $infodot[$map[$_SESSION["y"]+1][$_SESSION["x"]]]["status"]=='allow'){
+ $_SESSION["y"]++;
+}
+if ($_GET['action']=='up' AND $infodot[$map[$_SESSION["y"]-1][$_SESSION["x"]]]["status"]=='allow'){
+ $_SESSION["y"]--;
+}
+If ($_GET['action']=='left' AND $infodot[$map[$_SESSION["y"]][$_SESSION["x"]-1]]["status"]=='allow'){
+ $_SESSION["x"]--;
+}
+if ($_GET['action']=='right' AND $infodot[$map[$_SESSION["y"]][$_SESSION["x"]+1]]["status"]=='allow'){
+ $_SESSION["x"]++;
+}
+*/
+//если первый заход на карту
+if (!isset($_SESSION["y"]) OR !isset($_SESSION["x"])){
+ $_SESSION["y"]=5;
+ $_SESSION["x"]=5;
+}
+
+//Строим квадрат 5Х5 вокруг игрока
+#$y = $_SESSION["y"]-10;
+#$y_end = $_SESSION["y"]+10;
+#$x = $_SESSION["x"]-20;
+#$x_end = $_SESSION["x"]+20;
+#$q = $x;
+
+$y = -1;
+$y_end = 20;
+$x = -1;
+$x_end = 40;
+$q = $x;
+
+
+print "";
+while ($y <= $y_end){
+ print "
";
+//квадрат построен
+/*
+?>
+
+ ";
+ $x = $q;
+ while ($x <= $x_end){
+ if (@$map[$y][$x] == ""){ // ползут ошибки!
+ $map[$y][$x] = "end";
+ }
+ if ($y == $_SESSION["y"] AND $x == $_SESSION["x"]){
+ print " ";
+ $y++;
+}
+print "";
+ print "";
+ print " ";
+ }
+ else{
+ print "";
+ print "";
+ print " ";
+ }
+ $x++;
+ }
+ print "
+
+
+
+ + +*/ +/* +//Описываем свойство отдельной клетки с координатами 2,2 +if ($_SESSION["y"] == 2 AND $_SESSION["x"] == 2){ + print "В этой клетке c координатами 2,2 находится магазин"; +} +else{ + print "В этой клетке нет активных элементов"; +} +*/ + +//Описываем свойство целого класса клеток +/* +if ($map[$_SESSION["y"]][$_SESSION["x"]] == "m"){ + print "В этой клетке класса m находится магазин"; +} +*/ +?> \ No newline at end of file