Jump to content

  • Log In with Google      Sign In   
  • Create Account

Sphere Looped World Map


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
6 replies to this topic

#1 Barrett   Members   -  Reputation: 152

Like
0Likes
Like

Posted 10 July 2013 - 06:27 AM

Hello to everyone!

 

I want to start a little discussion about looped world map.

In my game I have a world map. It stores in memory as 2d-array of different cells with surface description. It is like an unfolded world map

 

WorldMap.gif

 

As I understand, when player stands at the top of map (on the northest point of Greenland) and tries to go forward, he fall in water at point marked with red cross

 

WorldMap.gif

 

And player's move direction reversed (but for gamer all things normal)

 

Does anyone know the good implementation of cycled world map or some articles about it?

 

Thanks in advance,

Denis



Sponsor:

#2 Norman Barrows   Crossbones+   -  Reputation: 2358

Like
0Likes
Like

Posted 10 July 2013 - 09:49 AM

sounds like you're talking about "wrapping around" from one edge to the opposite. IE when you get to the north edge, you suddenly wrap around to the south edge, and can continue going north forever, wrapping around each time you hit an edge.

 

super simple:

 

say your world is 100x100 in x and y. positive x is east, positive y is south (like the screen). so the player goes north (negative y direction). so you decrement y until y<0. when y goes to <0, you set y=99, which "wraps' you to the south edge of the map, while maintaining your x (east-west) location.

 

so your move routines would be of the form:

 

move_east()

{

x++;

if (x>=100) x=0;   // wrap around if they go off the edge of the map

}

 

 

move_west()

{

x--;

if (x<0) x=99;   // wrap around if they go off the edge of the map

}

 

move_south()

{

y++;

if (y>=99) y=0;   // wrap around if they go off the edge of the map

}

 

move_north()

{

y--;

if (y<0) y=99;   // wrap around if they go off the edge of the map

}


Norm Barrows

Rockland Software Productions

"Building PC games since 1989"

rocklandsoftware.net

 

PLAY CAVEMAN NOW!

http://rocklandsoftware.net/beta.php

 

 


#3 Paradigm Shifter   Crossbones+   -  Reputation: 5441

Like
0Likes
Like

Posted 10 July 2013 - 10:03 AM

sounds like you're talking about "wrapping around" from one edge to the opposite. IE when you get to the north edge, you suddenly wrap around to the south edge, and can continue going north forever, wrapping around each time you hit an edge.

 

super simple:

 

say your world is 100x100 in x and y. positive x is east, positive y is south (like the screen). so the player goes north (negative y direction). so you decrement y until y<0. when y goes to <0, you set y=99, which "wraps' you to the south edge of the map, while maintaining your x (east-west) location.

 

so your move routines would be of the form:

 

move_east()

{

x++;

if (x>=100) x=0;   // wrap around if they go off the edge of the map

}

 

 

move_west()

{

x--;

if (x<0) x=99;   // wrap around if they go off the edge of the map

}

 

move_south()

{

y++;

if (y>=99) y=0;   // wrap around if they go off the edge of the map

}

 

move_north()

{

y--;

if (y<0) y=99;   // wrap around if they go off the edge of the map

}

 

That's how you wrap around on a torus (doughnut).

 

Most world map games don't allow wrapping north and south, they just wrap east-west so they are simulating playing on a cylinder. It's confusing otherwise. Games like Civ have ice blocking movement north and south off the map.

 

EDIT: But if you want to do something that is vaguely realistic, imagine the east-west axis from -1 to +1. Going off the top or bottom of the map changes the sign of your east-west coordinate and the direction of your north-south movement when you hit the boundary. (i.e. reflect your EW coordinate around the Y axis and reflect your NS coordinate around either the top or the bottom of the map (the line X = +1 or X = -1), depending on whether you moved north or south off the map).

 

EDIT2: Visualise it by imagining the map folded in half along the Y axis, when you move off the top or bottom of the map you appear on the opposite side of the fold moving the opposite direction.

 

EDIT3: another way to visualise it is as a cylinder with the north and south caps sewn up (like a pillow).


Edited by Paradigm Shifter, 10 July 2013 - 10:21 AM.

"Most people think, great God will come from the sky, take away everything, and make everybody feel high" - Bob Marley

#4 KnolanCross   Members   -  Reputation: 1369

Like
0Likes
Like

Posted 10 July 2013 - 10:43 AM

You can try to define a center, and move relatively to the center.

 

Lets say you have 20 cells on the horizontal axis, the middle cell would be the 10th cell.

When the player is on the top of the map and tries do move up, you get the current cell (let's say he on the 7th cell), so you calculate the relative distance beetween the his cell and the middle cell (in other words: (10 - 7) = 3), and move him by the relative distancem he will end up in cell 13 (10 + 3 = 13) .

I believe this would work in every case, if it was after the middle cell, (for instance on cell 13), you would have a negative relative distance (10 - 13 = -3) and would end up in cell 7 (10 - 3 = 7), which seems somewhat precise.

 

I think this is what you are looking for, but should look at the special cases of first cell, last cell and middle cell. If this is what you need I am sure you can refine algorithm a bit to deal with special cases.


Currently working on a scene editor for ORX (http://orx-project.org), using kivy (http://kivy.org).


#5 Barrett   Members   -  Reputation: 152

Like
0Likes
Like

Posted 10 July 2013 - 01:56 PM

Thanks a lot!

 

Torus is not my variant, I want to model a sphere loop. But I forgot about one thing - I have a 2d graphics like old-style games (FF1, FF2) and I cannot rotate elements at map...

Any Ideas what I can do with this situation?

 

Thanks in advance,

Denis 



#6 Paradigm Shifter   Crossbones+   -  Reputation: 5441

Like
0Likes
Like

Posted 11 July 2013 - 01:05 AM

Who said anything about rotation? I mentioned how to visualise which parts of the map would be connected to give it a topology similar to that of a sphere (either fold the map along the line of 0 latitude and imagine the edges are joined together, or imagine a cylinder with the caps sewn shut).

 

Here's some pseudo-code for that. Map your coordinates into the range -1 to +1 (-1 on the X axis would be the West edge, +1 on the X axis would be the East edge, +1 on the Y axis would be the North edge, -1 on the Y axis would be the South edge).

 

Wrapping East->West:

 

if(x > 1) x = x - 2; // maps x = +1 to x = -1

 

Wrapping West->East:

 

if(x < -1) x = x + 2; // maps x = -1 to x = +1

 

Wrapping by going North:

 

if(y > 1) x = -x, y = 1 - (y - 1); // reflect x coordinate in y axis (i.e. the line x = 0) and reflect y coordinate around line y = 1

 

1 - (y - 1) simplifies to 1 - y + 1 = 2 - y

 

Wrapping by going South:

 

if(y < -1) x = -x, y = -1 - (y - (-1)); // reflect x coordinate in y axis and reflect y coordinate around line y = -1

 

-1 - (y - (-1)) simplifies to -1 - (y + 1) = -2 - y

 

Example: you move off the south edge of the map and your x, y coordinates would have placed you at (0.6, -1.25). Your new coordinates would be (-0.6, -2 - (-1.25)) = (-0.6, -0.75)

 

EDIT: It is possible to cross both east/west and go off the top or bottom in the same move. Solve this by checking for going off the east or west edge first, adjust the x coordinate, and then check the new position against the top and bottom of the map.


Edited by Paradigm Shifter, 11 July 2013 - 01:14 AM.

"Most people think, great God will come from the sky, take away everything, and make everybody feel high" - Bob Marley

#7 Barrett   Members   -  Reputation: 152

Like
0Likes
Like

Posted 12 July 2013 - 07:32 AM

Who said anything about rotation? I mentioned how to visualise which parts of the map would be connected to give it a topology similar to that of a sphere (either fold the map along the line of 0 latitude and imagine the edges are joined together, or imagine a cylinder with the caps sewn shut).

 

Here's some pseudo-code for that. Map your coordinates into the range -1 to +1 (-1 on the X axis would be the West edge, +1 on the X axis would be the East edge, +1 on the Y axis would be the North edge, -1 on the Y axis would be the South edge).

 

Wrapping East->West:

 

if(x > 1) x = x - 2; // maps x = +1 to x = -1

 

Wrapping West->East:

 

if(x < -1) x = x + 2; // maps x = -1 to x = +1

 

Wrapping by going North:

 

if(y > 1) x = -x, y = 1 - (y - 1); // reflect x coordinate in y axis (i.e. the line x = 0) and reflect y coordinate around line y = 1

 

1 - (y - 1) simplifies to 1 - y + 1 = 2 - y

 

Wrapping by going South:

 

if(y < -1) x = -x, y = -1 - (y - (-1)); // reflect x coordinate in y axis and reflect y coordinate around line y = -1

 

-1 - (y - (-1)) simplifies to -1 - (y + 1) = -2 - y

 

Example: you move off the south edge of the map and your x, y coordinates would have placed you at (0.6, -1.25). Your new coordinates would be (-0.6, -2 - (-1.25)) = (-0.6, -0.75)

 

EDIT: It is possible to cross both east/west and go off the top or bottom in the same move. Solve this by checking for going off the east or west edge first, adjust the x coordinate, and then check the new position against the top and bottom of the map.

 

Yes, I got it) Thanks!

 

And what should I do with my camera? I've got a 2d game with non-rotation camera (like old FF). This impementation means that when player crossed -1 point at Y axis, camera and player simply moves into new location? It seems not so seamless as I imagine... But there is only one way to do it?

 

Hoping for your help,

Denis

 

P.S. Sorry for my English =)


Edited by Barrett, 12 July 2013 - 07:39 AM.





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS