Jump to content

Recommended Posts

Hi ppl,

 

I need help to draw a random 2D map from hexagonal tiles.

 

I have 5 different types of hex tiles and I want to draw a random map.

 

Any help to randomly distribute the tiles and form an entire map of, for example, 256 hex tiles?

 

Thank u in advance,

 

Daniel

Are the tiles images?

 

Is your info set up in a database?

 

You could run a loop to select the image from the database at random and display it.

 

If you wanted a random map you would also have to insert random row breaks etc.

 

That might be enough to get you started, if you can give me some more info I would be happy to help out further.

Hi and thank u for the help,

 

Yes, the tiles are hexagonal images in jpg, gif, or any needed to work with, thats not the problem.

 

The starting "raw" five types of tiles will be in a database.

 

As we start in the development of this problem we found some others problems:

 

- As we select the tiles randomly and as we display it, we have to know the position the random pattern has assigned to that tile (i.e. coordinates) in order to use the same random-generated map later on.

 

- Also we have to name each tile by a logical pattern (an unique ID for each tile) for later changes of its content.

 

- As well, we have to know the tiles that each tile has around it (hex tiles has another 6 tiles around it).

 

- And once we have the system to know that info we have to save it to a map database.

 

Anyway and in first place I have to manage to random select the tiles from the database and displaying a number of randomly selected tiles to form the map. Later think I can manage to solve almost all the other problems.

 

Ty mate,

 

Daniel

  function ReturnRandomFromArray(&$arr) {  
    $randar = array();
    reset($arr);
    while(list(,$hod)=each($arr)) $randar[] = $hod;

    $randar = array_values($randar);
    $c = count($randar);
    if ($c > 1) {
      --$c;
      $r = rand(0,$c);
      while(empty($randar[$r])) $r = rand(0,$c);
      return $randar[$r];
    } 
    elseif ($c == 1) 
      return $randar[0];
      
    else
      return '';
  }

  // you will probably fill this array from your database
  $ardat = array( 'tile unique id', 'tile unique id'....);

  $armap = array();

  for ($x = 0; $x < 16; ++$x) {
    $xx = $x * 16;
    for ($y = 0; $y < 16; ++$y)
      $armap[$xx + $y] = ReturnRandomFromArray($ardat);
  }
  

 

For the unique id you could just start a count.

 

$count =0;

 

loop

{

 

$count++;

}

 

This would add one to the count variable and you could use that as a unique id.

 

I am not sure I follow your coordinates request. Do you have an example of what you are trying to do?

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.