Author Topic: text-map  (Read 1559 times)

Offline Sinzygy

  • Level 28
  • **
  • Posts: 420
  • Reputation: +11/-0
    • View Profile
text-map
« on: June 08, 2007, 06:52:57 AM »
Alright!

Here's what I'm trying to do:
Code: [Select]
  _____         _____         _____
 /     \       /     \       /     \
/ (0/0) \_____/ (2/0) \_____/ (4/0) \
\       /     \       /     \       /
 \_____/ (1/1) \_____/ (3/1) \_____/
 /     \       /     \       /     \
/ (0/2) \_____/ (2/2) \_____/ (4/2) \
\       /     \       /     \       /
 \_____/ (1/1) \_____/ (3/3) \_____/
 /     \       /     \       /     \
/ (0/4) \_____/ (2/5) \_____/ (4/4) \
\       /     \       /     \       /
 \_____/ (5/1) \_____/ (3/5) \_____/
 /     \       /     \       /     \
/ (0/6) \_____/ (2/6) \_____/ (4/6) \
\       /     \       /     \       /
 \_____/       \_____/       \_____/

I want to create it on the run and being able to zoom around.
But small steps: What would be a good way to do this?

my thought are using this sequence and just stack it on top of each other:
Code: [Select]
/     \       /     \       /     \
/ (0/0) \_____/ (2/0) \_____/ (4/0) \
\       /     \       /     \       /
 \_____/ (1/1) \_____/ (3/1) \_____/

but how would I go about that the most efficient? Plus adding the coordinates?
« Last Edit: June 08, 2007, 06:56:17 AM by Sinzygy »

Offline Ki Adi Mundi

  • Level 8
  • *
  • Posts: 38
  • Reputation: +0/-0
    • View Profile
Re: text-map
« Reply #1 on: June 08, 2007, 06:50:21 PM »
What kind of game is this map for?

Offline Sinzygy

  • Level 28
  • **
  • Posts: 420
  • Reputation: +11/-0
    • View Profile
Re: text-map
« Reply #2 on: June 09, 2007, 06:46:23 PM »
it's for a round-based strategy game.

Offline Ki Adi Mundi

  • Level 8
  • *
  • Posts: 38
  • Reputation: +0/-0
    • View Profile
Re: text-map
« Reply #3 on: June 10, 2007, 06:16:29 AM »
Kind of like the Civilization franchise games?  If so, I'd be interested in playing once it's ready.

Offline Sinzygy

  • Level 28
  • **
  • Posts: 420
  • Reputation: +11/-0
    • View Profile
Re: text-map
« Reply #4 on: June 10, 2007, 10:15:46 AM »
Haha, it will be a long time before this one is ready to be played. I still need to figure out a lot...

And it might be similar to Civ, but it's actually intended to serve as a port from the old pbem games to pbbgs.

Offline beam

  • Level 15
  • *
  • Posts: 132
  • Reputation: +2/-0
  • Dance Commander
    • View Profile
Re: text-map
« Reply #5 on: June 11, 2007, 03:36:14 PM »
What I would do is write a function called draw_hexagon, and it would just draw individual hexagons. One of the arguments would be scale_factor, so you could scale the map according to zoom distance. To draw a map, just call draw_hexagon repeatedly until the map is filled. It wouldn't be hard to come up with an algorithm to place the hexagons based on size, scale, position, etc.

Edit: oops, didn't realize you were actually doing it with text, I thought it was a diagram :(

Offline Zeggy

  • Global Moderator
  • Level 35
  • *****
  • Posts: 1,187
  • Reputation: +13/-4
    • View Profile
Re: text-map
« Reply #6 on: June 11, 2007, 03:41:37 PM »
I think one of the main problems is getting all the hexagons to tile with each other properly...

Offline beam

  • Level 15
  • *
  • Posts: 132
  • Reputation: +2/-0
  • Dance Commander
    • View Profile
Re: text-map
« Reply #7 on: June 11, 2007, 03:55:14 PM »
http://www-cs-students.stanford.edu/~amitp/Articles/HexLOS.html

This is a great writeup on hexagonal maps in games.

As far as drawing, you could draw the text line by line, and just use repeating patterns. I'll go write a quick script now and get back to you.

Code: [Select]
<pre>

<?php
define
('HEX_ROWS'10);
define('HEX_COLS'10);

echo 
str_repeat(str_repeat("&nbsp;"2) . str_repeat("_"5) . str_repeat("&nbsp;"7), HEX_COLS 2);
echo 
"<br />";

for (
$row 0$row HEX_ROWS$row++)
{
 for (
$line 0$line 4$line++)
 {
  switch (
$line)
  {
   case 
0:
    echo 
str_repeat("&nbsp;/" str_repeat("&nbsp;"5) . "\\" str_repeat("&nbsp;"6), HEX_COLS 2);
    echo 
"<br />";
    break;

   case 
1:
    for (
$col 0$col HEX_COLS$col+=2)
    {
     echo 
"/&nbsp;(" $col "/" $row ")&nbsp;\\_____";
    }
    echo 
"<br />";
    break;

   case 
2:
    echo 
str_repeat("\\" str_repeat("&nbsp;"7) . "/" str_repeat("&nbsp;"5), HEX_COLS 2);
    echo 
"<br />";
    break;

   case 
3:
    for (
$col 1$col HEX_COLS$col+=2)
    {
     echo 
"&nbsp;\\_____/&nbsp;(" $col "/" $row ")";
    }
    echo 
"<br />";
    break;
  }
 }
}
?>


</pre>

This is the basic idea. It still leaves the end tiles unfinished, but you shouldn't have a problem fixing that up, I just wanted to get you started. Good luck
« Last Edit: June 11, 2007, 04:24:08 PM by beam »

Offline Sinzygy

  • Level 28
  • **
  • Posts: 420
  • Reputation: +11/-0
    • View Profile
Re: text-map
« Reply #8 on: June 11, 2007, 04:14:47 PM »
thanks for the link. I'll look into it as soon as I have enough spare time.

[?∂??]
Woha, thanks a lot for this nice piece of code!
« Last Edit: June 11, 2007, 04:38:02 PM by Sinzygy »

 


SimplePortal 2.3.3 © 2008-2010, SimplePortal