ASCII Map

General forum for game-related discussion.

Moderator: Moderators

Post Reply
haeggar
Supporting Member 2008
Posts: 19
Joined: Tue Jan 11, 2005 21:10 pm

ASCII Map

Post by haeggar »

Though I unfortunatly don't have time to play icesus anymore (got a little baby --- now 7 weeks old) i put the ascii map back on the server again.

thx to uzriel who told me twice a day to do so. and since uzriel asked me for the code here is it ... kind of open source now :)

Code: Select all

<html>

<head>

<style>

b &#123;

	font-weight&#58;normal;

&#125;



.lg &#123;

	color&#58;#00FF00;

&#125;



.dg &#123;

	color&#58;#008000;

&#125;



.ye &#123;

	color&#58;#FFFF80;

&#125;



.gr &#123;

	color&#58;#C0C0C0;

&#125;



.ma &#123;

	color&#58;#FF00FF;

&#125;



.db &#123;

	color&#58;#0080FF;

&#125;



.lb &#123;

	color&#58;#00FFFF;

&#125;



.br &#123;

	color&#58;#808000;

&#125;



.re &#123;

	color&#58;#FF0000;

&#125;



.wh &#123;

	color&#58;#FFFFFF;

&#125;



.tz &#123;

	color&#58;#61C3A2;

&#125;

</style>

</head>

<body bgcolor="#000000">

<pre><code style="font-family&#58;'Courier New', Courier, mono; fontSize&#58;11px; color&#58;#FFFF80" >

<?php

	$img = imagecreatefrompng&#40;'http&#58;//www.icesus.org/images/map/map.png'&#41;;

	$convert = array&#40;0 => 'S', 1 =>'*', 2 => 't', 3 => 'd', 4 => 'E',

					 5 => 'z', 6 => '?', 7 => 'g', 8 => 'e', 10 => 's', 11 => 'H', 

					12 => 'C', 13 => '^', 14 => 'D', 15 => 'w', 16 => 'F',

					17 => 'r', 18 => '$', 19 => 'V', 20 => '~', 21 => 'h',

					22 => 'M', 23 => '.', 24 => 'f', 25 => 'i', 26 => '#',

					27 => 'm', 28 => '.', 29 => 'p', 30 => 'R'&#41;;



	$colors = array&#40;'S' => 're', '*' => 'gr', 't' => 'tz', 'd' => 'lg', 'E' => 'dg',

					'z' => 'ma', '?' => 'ma', 'g' => 'wh', 'e' => 'lg', 's' => 're', 

					'H' => 'br', 'w' => 'lg', '^' => 'gr', 'D' => 'dg', 'C' => 'gr',

					'F' => 'dg', 'r' => 'db', '*' => 'gr', 'V' => 're', '~' => 'db',

					'h' => 'br', 'M' => 'ye', '.' => 'gr', 'f' => 'lg', 'i' => 'lb',

					'#' => 'ma', 'm' => 'ye', '$' => 'ma', 'p' => 'ye', 'R' => 'db',

					'|' => 'gr', '-' => 'gr', '+' => 'gr', '/' => 'gr', '\\' => 'gr'&#41;;



	$top = 300;

	$left = 400;

	$width = 800;

	$height = 600;

	

	

	for&#40;$y = $top;$y < &#40;$top + $height&#41; ;++$y&#41;&#123;

       for&#40;$x = $left; $x < &#40;$left+ $width&#41; ;++$x&#41;&#123;

			$map_ascii &#91;$y&#93;&#91;$x&#93; = $convert&#91;ImageColorAt&#40;$img, $x, $y&#41;&#93;;

       &#125;

	&#125;

	

	

	for&#40;$y = $top;$y < &#40;$top + $height&#41; ;++$y&#41;&#123;

       $lastchar = "";

       $lastcolor = "";

       $printstring = "";

       for&#40;$x = $left; $x < &#40;$left+ $width&#41; ;++$x&#41;&#123;

   	   		$actchar = $map_ascii&#91;$y&#93;&#91;$x&#93;;

   	   		

			if &#40;$actchar=="*"&#41;

			&#123;

				if &#40;$map_ascii&#91;$y-1&#93;&#91;$x-1&#93; == "." || 

					$map_ascii&#91;$y-1&#93;&#91;$x&#93; == "." || 

					$map_ascii&#91;$y-1&#93;&#91;$x+1&#93; == "." || 

					$map_ascii&#91;$y&#93;&#91;$x-1&#93; == "." || 

					$map_ascii&#91;$y&#93;&#91;$x+1&#93; == "." || 

					$map_ascii&#91;$y+1&#93;&#91;$x-1&#93; == "." || 

					$map_ascii&#91;$y+1&#93;&#91;$x&#93; == "." || 

					$map_ascii&#91;$y+1&#93;&#91;$x+1&#93; == "."&#41;

				&#123;

					$actchar = "+";

				&#125;

				else if &#40;$map_ascii&#91;$y&#93;&#91;$x-1&#93; == "*" && $map_ascii&#91;$y&#93;&#91;$x+1&#93; == "*"&#41;

				&#123;

					$actchar = "-";

				&#125;

				else if &#40;$map_ascii&#91;$y-1&#93;&#91;$x&#93; == "*" && $map_ascii&#91;$y+1&#93;&#91;$x&#93; == "*"&#41;

				&#123;

					$actchar = "|";

				&#125;

				else if &#40;$map_ascii&#91;$y-1&#93;&#91;$x-1&#93; == "*" && $map_ascii&#91;$y+1&#93;&#91;$x+1&#93; == "*"&#41;

				&#123;

					$actchar = "\\";

				&#125;

				else if &#40;$map_ascii&#91;$y-1&#93;&#91;$x+1&#93; == "*" && $map_ascii&#91;$y+1&#93;&#91;$x-1&#93; == "*"&#41;

				&#123;

					$actchar = "/";

				&#125;

				else 

				&#123;

					$actchar = "+";

				&#125;

			&#125;

   	   		

       		if &#40;$colors&#91;$actchar&#93; == $lastcolor&#41;

       		&#123;

       			$printstring .= $actchar;

       		&#125;

       		else 

			&#123;

				if &#40;$lastchar <> ""&#41;

				&#123;

					if &#40;$colors&#91;$lastchar&#93; <> 'ye'&#41;

						print "<b class=\"".$colors&#91;$lastchar&#93;."\">".$printstring."</b>";

					else

						print $printstring;

					

       			&#125;

    	   		$lastchar = $actchar;

    	   		$lastcolor = $colors&#91;$actchar&#93;;

				$printstring = $actchar;

       			

       		&#125;

       &#125;

		if &#40;$colors&#91;$lastchar&#93; <> 'ye'&#41;

			print "<b class=\"".$colors&#91;$lastchar&#93;."\">".$printstring."</b>";

		else

			print $printstring;

		print "\n";

   &#125;



?>

</code></pre>

</body></html>

have much fun with it and the world of icesus :D
drakken
Posts: 63
Joined: Tue Nov 16, 2004 06:51 am

Post by drakken »

Thanks for the map, that rocks.
Congrats on the baby!
Post Reply