diff options
author | Patrick Davison <snapwilliam@gmail.com> | 2013-04-09 01:08:02 -0700 |
---|---|---|
committer | Patrick Davison <snapwilliam@gmail.com> | 2013-04-09 01:08:02 -0700 |
commit | df11c5da2c6e91a2c079308d62110995352d76f5 (patch) | |
tree | 2063df473aa608fcb29002ad2fd2cae722c78c89 | |
parent | c805c944aa93641dfacf7724dec8716096d4072e (diff) | |
download | pathery-df11c5da2c6e91a2c079308d62110995352d76f5.tar.xz |
MapEditor improvements
-rw-r--r-- | includes/mapclass.php | 3 | ||||
-rw-r--r-- | includes/maps.php | 1 | ||||
-rw-r--r-- | pages/mapeditor.php | 64 |
3 files changed, 59 insertions, 9 deletions
diff --git a/includes/mapclass.php b/includes/mapclass.php index 24b9108..c4d95e9 100644 --- a/includes/mapclass.php +++ b/includes/mapclass.php @@ -295,6 +295,9 @@ class map { $oldNames['r'] = 'r'; $oldNames['r2'] = 'R'; + + $oldNames['q'] = 'q'; + $oldNames['p'] = 'p'; for( $i = 0; $i < $this->height; $i++) { for( $j = 0; $j < $this->width; $j++) { diff --git a/includes/maps.php b/includes/maps.php index 1af64a2..ec338d7 100644 --- a/includes/maps.php +++ b/includes/maps.php @@ -355,6 +355,7 @@ function GenerateMap($rows, $cols, $rockchance, $numBlocks = -1, $cp = -1, $tp = if ($tp == -1)
$tp = rand(0, 2);
$tp = $tp * 2; //Requires an out-teleport.
+ if ($rockchance < 2) $rockchance = 2;
//== Possibility of inf loop here, if the map is too small.
do {
diff --git a/pages/mapeditor.php b/pages/mapeditor.php index 0d6cf94..3134d51 100644 --- a/pages/mapeditor.php +++ b/pages/mapeditor.php @@ -23,6 +23,17 @@ if ($_REQUEST['mapByMap']) { exit; } +if ($_REQUEST['genMap']) { +//function GenerateMap($rows, $cols, $rockchance, $numBlocks = -1, $cp = -1, $tp = -1, $mapName = '') { + $map = GenerateMap($_REQUEST['width'], $_REQUEST['height'], $_REQUEST['rockChance'], $_REQUEST['wallCount'], $_REQUEST['checkpoints'] % 6, $_REQUEST['teleports'] % 6); + //$map = GenerateMap($_REQUEST['height'], $_REQUEST['width'], $_REQUEST['rockChance'], 0, 0, 0); + //$map = insertPoint($map, $_REQUEST['points'], 'o'); + $code = GenerateMapCode($map); + $map = new map($code); + echo json_encode($map); + exit; +} + htmlHeader(array('stats', 'mapeditor'), 'Map Editor', 'Map Editor', @@ -113,16 +124,20 @@ function minusWalls() { reloadMap(); } function plusWidth() { - changeDimensions(testMap.width - 0 + 1, testMap.height) + changeDimensions(testMap.width - 0 + 1, testMap.height); } function minusWidth() { - changeDimensions(testMap.width - 1, testMap.height) + changeDimensions(testMap.width - 1, testMap.height); } function plusHeight() { - changeDimensions(testMap.width, testMap.height - 0 + 1) + changeDimensions(testMap.width, testMap.height - 0 + 1); } function minusHeight() { - changeDimensions(testMap.width, testMap.height - 1) + changeDimensions(testMap.width, testMap.height - 1); +} +function updateName() { + testMap.name = $('#mapName').val(); + mapHasChanged = true; } function changeDimensions(width, height) { @@ -151,12 +166,13 @@ function loadPlayableMap() { if (isLoadingMap == true) return; isLoadingMap = true; - var URLString = 'mapeditor?mapByMap='+JSON.stringify(testMap); + //var URLString = 'mapeditor?mapByMap='+JSON.stringify(testMap); + var URLString = 'mapeditor'; $.ajax({ - type: "GET", + type: "POST", url: URLString, cache: true, - data: '', + data: 'mapByMap='+JSON.stringify(testMap), fail: function() { alert("error"); }, complete: function(data) { playableMap = decryptJSON(data.responseText); @@ -179,6 +195,20 @@ function loadMap(by) { } else if (by == 'code') { mapCode = $('#mapCode').val(); URLString = 'mapeditor?mapByCode='+mapCode; + } else if (by == 'gen') { + mapCode = $('#mapCode').val(); + URLString = 'mapeditor?genMap=true'+mapCode; + var height = $('#genMapHeight').val(); + var width = $('#genMapWidth').val(); + var rockChance = $('#genMapRockChance').val(); + var checkpoints = $('#genMapCheckpoints').val(); + var teleports = $('#genMapTeleports').val(); + URLString += '&height='+height; + URLString += '&width='+width; + URLString += '&wallCount='+testMap.walls; + URLString += '&rockChance='+rockChance; + URLString += '&checkpoints='+checkpoints; + URLString += '&teleports='+teleports; } $.ajax({ type: "GET", @@ -233,6 +263,17 @@ function constructTiles(width, height, baseMap) { <div class='plusMinus' style='width:300px;'> Load map by code:<input id='mapCode' size="30" type="text" value="" class="forminput"/> <input type="button" value="Load" class="forminput" onclick='loadMap("code")'/> + </div> + + <div class='plusMinus' style='width:300px;'> + Generate a random map: + <br />Height:<input id='genMapHeight' size="4" type="number" value="" class="forminput"/> + <br />Width:<input id='genMapWidth' size="4" type="number" value="" class="forminput"/> + <br />Rockchance 1 in:<input id='genMapRockChance' size="4" type="number" value="" class="forminput"/> + <br />Checkpoints:<input id='genMapCheckpoints' size="4" type="number" value="" class="forminput"/> (Max 5) + <br />Teleports:<input id='genMapTeleports' size="4" type="number" value="" class="forminput"/> (Max 5) + + <input type="button" value="Generate" class="forminput" onclick='loadMap("gen")'/> </div> </fieldset> @@ -241,10 +282,15 @@ function constructTiles(width, height, baseMap) { </div> <form><div> - <div class='' id='' style='float:left; width:340px;height:350px;'> + <div class='' id='' style='float:left; width:340px;height:450px;'> <fieldset style='width:300px'> <legend>Settings:</legend> + <div class='plusMinus' style='width:270px'> + Map Name:<input onchange='updateName()' id='mapName' style='width:260px;' size="10" type="text" value="" class="forminput"/> + </div> + + <div class='plusMinus'> Height:<input type="button" value="+" class="forminput" onclick='plusHeight()'/> <input type="button" value="-" class="forminput" onclick='minusHeight()'/> @@ -262,7 +308,7 @@ function constructTiles(width, height, baseMap) { <?PHP $tilesArray = array( - 's', 's2', 'f', 'w', + 's', 's2', 'f', 'p', 'space', 'r', 'r2', 'o', 'q', 'x', 'x2', 'space', |