Author Topic: What's the best way to implement a 3D world with python/libtcod  (Read 13741 times)

gideon_stargrave

  • Newcomer
  • Posts: 11
  • Karma: +0/-0
    • View Profile
If it's possible, that is.


Logically 3D. ASCII display with the ability to move up and down the z-axis.

Whatever pointers/hints you can provide would be appreciated. If you could give a general sketch of the implementation rather than specific code, that would be great - learning experiences are valuable.

Thanks in advance!
« Last Edit: May 08, 2013, 11:07:35 AM by gideon_stargrave »

Ex

  • IRC Communications Delegate
  • Rogueliker
  • ***
  • Posts: 313
  • Karma: +0/-0
    • View Profile
Re: What's the best way to implement a 3D world with python/libtcod
« Reply #1 on: May 08, 2013, 03:00:02 AM »
What do you mean by a 3d world?

You can use noteye if you want quick and easy 3d.

requerent

  • Rogueliker
  • ***
  • Posts: 355
  • Karma: +0/-0
    • View Profile
Re: What's the best way to implement a 3D world with python/libtcod
« Reply #2 on: May 08, 2013, 04:56:05 AM »
Logically 3D (dwarf fortress) or Graphically 3D (Diablo 3)?

gideon_stargrave

  • Newcomer
  • Posts: 11
  • Karma: +0/-0
    • View Profile
Re: What's the best way to implement a 3D world with python/libtcod
« Reply #3 on: May 08, 2013, 10:54:58 AM »
Logically 3D (dwarf fortress) or Graphically 3D (Diablo 3)?

Logically 3D. ASCII display with the ability to move up and down the z-axis.

Ex

  • IRC Communications Delegate
  • Rogueliker
  • ***
  • Posts: 313
  • Karma: +0/-0
    • View Profile
Re: What's the best way to implement a 3D world with python/libtcod
« Reply #4 on: May 08, 2013, 01:29:37 PM »
The easiest thing that comes to mind is just adding another dimension to the array. Using a 3d array for the map instead of a 2d array.

requerent

  • Rogueliker
  • ***
  • Posts: 355
  • Karma: +0/-0
    • View Profile
Re: What's the best way to implement a 3D world with python/libtcod
« Reply #5 on: May 08, 2013, 05:07:52 PM »
You need to make a distinction between the player's view and the game's map. This wouldn't be much different from a logically 2D game.

All you do is use a 3D array
  • [y][z] and store whatever z-value the player is currently viewing from. This is no different from a normal game, where the view target of your proverbial camera can be described as the coordinate from which the viewing area is drawn.


In a fixed view roguelike, such as Brogue, the 'camera' is always pointing at the center of the viewing area, whereas in ToME, which follows the character (to some degree anyways) points at the character.

It can be useful to make the camera it's own entity so that you have the freedom to move it around with a 'look' command or what not- especially for a 3D roguelike.

gideon_stargrave

  • Newcomer
  • Posts: 11
  • Karma: +0/-0
    • View Profile
Re: What's the best way to implement a 3D world with python/libtcod
« Reply #6 on: May 08, 2013, 07:28:30 PM »
You need to make a distinction between the player's view and the game's map. This wouldn't be much different from a logically 2D game.

All you do is use a 3D array
  • [y][z] and store whatever z-value the player is currently viewing from. This is no different from a normal game, where the view target of your proverbial camera can be described as the coordinate from which the viewing area is drawn.


In a fixed view roguelike, such as Brogue, the 'camera' is always pointing at the center of the viewing area, whereas in ToME, which follows the character (to some degree anyways) points at the character.

It can be useful to make the camera it's own entity so that you have the freedom to move it around with a 'look' command or what not- especially for a 3D roguelike.

I tried to do something akin to that, but I couldn;t get libtcod to display anything. I'll take another crack at it.

requerent

  • Rogueliker
  • ***
  • Posts: 355
  • Karma: +0/-0
    • View Profile
Re: What's the best way to implement a 3D world with python/libtcod
« Reply #7 on: May 08, 2013, 08:53:47 PM »
Do the map as a Map[z]
  • [y], and pass the Map[z] into the drawgrid thingy. I haven't used libtcod but I imagine that's the sort of pseudo-code you need.

gideon_stargrave

  • Newcomer
  • Posts: 11
  • Karma: +0/-0
    • View Profile
Re: What's the best way to implement a 3D world with python/libtcod
« Reply #8 on: May 08, 2013, 10:23:48 PM »
Do the map as a Map[z]
  • [y], and pass the Map[z] into the drawgrid thingy. I haven't used libtcod but I imagine that's the sort of pseudo-code you need.
Maybe I'm just thick, but I'm having a little trouble envisioning what you are suggesting here. Could you elaborate a little?

requerent

  • Rogueliker
  • ***
  • Posts: 355
  • Karma: +0/-0
    • View Profile
Re: What's the best way to implement a 3D world with python/libtcod
« Reply #9 on: May 08, 2013, 10:29:59 PM »
err- sorry, the formatting messed up somehow.

Code: [Select]
Make the Z component of your map come first. So that you have a bunch of 2d arrays with respect to a Z-component Array.


In other words, your map is of the form Map[z][x][y].

Now, when you want to draw something, you simply pass Map[z] into your grid-drawing function. The grid-drawing function expects a 2d array of x and y coordinates- Map[z] is a 2d array, whereas Map is a 3d array. Get it?

Edited with tags >_<.
« Last Edit: May 09, 2013, 01:38:41 AM by requerent »

Quendus

  • Rogueliker
  • ***
  • Posts: 447
  • Karma: +0/-0
  • $@ \in \{1,W\} \times \{1,H\}$
    • View Profile
    • Klein Roguelikes
Re: What's the best way to implement a 3D world with python/libtcod
« Reply #10 on: May 08, 2013, 10:57:20 PM »
This might be a good place to use [ code][ /code] tags.

gideon_stargrave

  • Newcomer
  • Posts: 11
  • Karma: +0/-0
    • View Profile
Re: What's the best way to implement a 3D world with python/libtcod
« Reply #11 on: May 09, 2013, 12:48:06 AM »
err- sorry, the formatting messed up somehow.


Make the Z component of your map come first. So that you have a bunch of 2d arrays with respect to a Z-component Array.


In other words, your map is of the form Map[z]
  • [y].


Now, when you want to draw something, you simply pass Map[z] into your grid-drawing function. The grid-drawing function expects a 2d array of x and y coordinates- Map[z] is a 2d array, whereas Map is a 3d array. Get it?

I think so. I'll mess around and see if I get something to work. I think so long as I can get something to show up on the screen I'll be able to jury-rig the rest.