Thread: Text-based spherical map.

  1. #1
    Registered User
    Join Date
    Nov 2010
    Posts
    3

    Text-based spherical map.

    Hey everyone. I must preface this by saying that I am a complete novice.

    Simply put, I am making a silly text based game, and I am trying to find a way to make the world map a sphere.

    By this I mean if the player goes too far to the right, they end up on the left, and too far up, they end up on the bottom.

    I can do this easily enough by making it wrap around, but this isn't technically correct as diagonals are involved.

    Any advice here?

    -Me

  2. #2
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Same as always... give it your best shot, post your code --using code tags please-- and maybe we can help. But until we see code, there's not much we can do.

  3. #3
    Registered User
    Join Date
    Nov 2010
    Posts
    3
    Here goes.

    What I'm trying to do is get the math so that the 'map' array is spherical, and not so... flat?

    -Me

  4. #4
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Code:
    int movedir( int dir )
    {
        switch( dir )
        {
            case NORTH: if( you.ycoord == 0 ) you.ycoord = YSIZE-1; else you.ycoord--; break;
            case EAST: you.xcoord = (you.xcoord + 1) % XSIZE; break;
            case SOUTH: you.ycoord = (you.ycoord + 1) % YSIZE; break;
            case WEST: if( you.xcoord == 0 ) you.xcoord = XSIZE-1; else you.xcoord--; break;
            default: return -1;
        }
        return 0;
    }
    Something like that.


    Quzah.
    Hope is the first step on the road to disappointment.

  5. #5
    Registered User
    Join Date
    Nov 2010
    Posts
    3
    Would that give spherical movement, or just loop from the left side to the right, or the top side to the bottom, etc?

  6. #6
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    That wraps around. You aren't really saying how your map is "spherical". Do you have an actual map that's shorter at the poles than the equator? How are you splitting it up? If you're just using a 2D array to store the whole thing, then do something like I've mentioned. You can have alternate sizes for each row, and then just keep track of the particular row size, and call that any place I've used % above.
    Code:
    dir = (dir + 1) % rowtable[ row ];
    You could use hexes or something like a soccer ball instead.


    Quzah.
    Hope is the first step on the road to disappointment.

  7. #7
    Just a pushpin. bernt's Avatar
    Join Date
    May 2009
    Posts
    426
    Would that give spherical movement, or just loop from the left side to the right, or the top side to the bottom, etc?
    I think maybe the effect you're going for is when you get to the world-drawing routine, you'll want that to wrap around too, ie when you get to the edge of the map, it will draw the opposite edge so that there's no visual break when you do the warp. (I feel like I didn't make that last sentence very coherent but I'm really tired so that's why.)

    At least that's what I hope you're going for, rather than attempting to represent a non-euclidean geometry with text graphics... although I've suddenly become interested in making some sort of non-euclidean puzzle game.
    Consider this post signed

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 100
    Last Post: 06-21-2010, 02:22 AM
  2. Smooth walking on tile based map system
    By abraham2119 in forum C Programming
    Replies: 8
    Last Post: 07-10-2009, 10:33 AM
  3. Polynomials and ADT's
    By Emeighty in forum C++ Programming
    Replies: 20
    Last Post: 08-19-2008, 08:32 AM
  4. making a text based game
    By MisterSako in forum C++ Programming
    Replies: 1
    Last Post: 12-05-2004, 01:20 PM
  5. Text Based Game
    By drdroid in forum C++ Programming
    Replies: 2
    Last Post: 02-18-2002, 06:21 PM