• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
Barrett

Sphere Looped World Map

6 posts in this topic

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

 

[attachment=16724: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

0

Share this post


Link to post
Share on other sites

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

}

0

Share this post


Link to post
Share on other sites

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
0

Share this post


Link to post
Share on other sites

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.

0

Share this post


Link to post
Share on other sites

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 

0

Share this post


Link to post
Share on other sites

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
0

Share this post


Link to post
Share on other sites

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
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0