• 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
jniblick

Multidimensional Arrays for a Rogue-Like Map?

9 posts in this topic

I am working on a rogue-like RPG and have come to the point where I want to display a map. My first idea was to use a multidimensional array of characters, but I don't know how I would display them and Google hasn't been helping. I am wondering if there might not be an easier method.
0

Share this post


Link to post
Share on other sites
I am thinking of using a 2d array in the style of...
[CODE]
char mapBuild[4][4] = {{###$},{####},{##@$},(##$#}};
[/CODE]
I don't know what kind of code I would to print that array onto the screen.
0

Share this post


Link to post
Share on other sites
First of all, if you use 2D arrays youre going to have to set your size in advance (when you compile) which might be limiting. Its better to dynamically allocate a single dimensional array of size w*h and then access it with x+y*w. As to printing it, cant you just use two nested for loops? Im not sure how youd clear the screen though
1

Share this post


Link to post
Share on other sites
An array of characters? Seriously? Your map tiles are going to be far more complex than one character: in a typical roguelike game they have various properties and flags and lists of things in that space, and when you start caching pathfinding results and querying nearest neighbours and connected components your data structures are probably going to be a bit more rich than a 2D array. Even as a derived intermediate representation of screen output, one character per tile isn't enough to represent colours and bold,italic and other attributes.
1

Share this post


Link to post
Share on other sites
[quote name='zacaj' timestamp='1327449811' post='4905942']
First of all, if you use 2D arrays youre going to have to set your size in advance (when you compile) which might be limiting. Its better to dynamically allocate a single dimensional array of size w*h and then access it with x+y*w. As to printing it, cant you just use two nested for loops? Im not sure how youd clear the screen though
[/quote]

That's not true for most languages. You can't change the size of an array when running, but when you can create it, it can be any variable size.
[CODE]int width, height;
std::cin >> width;
std::cin >> height;
char mapbuilder[width][height];[/CODE]

Granted the OP doesn't mention what language he is using, but it looks like a C based language.

OP: Two for-loops (one nested in the other) does seem the best way to print the array. There is no standard way to clear the screen. You would have to either use a library, or investigate how to clear the screen on each platform you plan to play it on.
0

Share this post


Link to post
Share on other sites
Im fairly certain that only works in C99, not C++, and it also means you cant access the array outside of the function its declared in, which would be fairly limiting. Its also technically possible to dynamically allocate a 2D (or 3D, etc) array, but it involves one allocation for each row, and generally is sort of messy
0

Share this post


Link to post
Share on other sites
[quote name='LorenzoGatti' timestamp='1327483035' post='4906054']
An array of characters? Seriously?[/quote]
Agreed. I was asked by a friend to work on one of his designs. It was very simple at start so I tried using something like a grid-based approach. It did work (sort of) but there was support to provide arbitrary descriptions for each room. 1 char per room is just a no-go. BTW, it is basically binary encoding, the benefits of using [font=courier new,courier,monospace]char [/font]will quickly go away.
Strongly discouraged.

How to display them?
You don't.
You display something else instead based on the data obtained for each new room.
0

Share this post


Link to post
Share on other sites
[quote name='zacaj' timestamp='1327525912' post='4906221']
Im fairly certain that only works in C99, not C++, and it also means you cant access the array outside of the function its declared in, which would be fairly limiting. Its also technically possible to dynamically allocate a 2D (or 3D, etc) array, but it involves one allocation for each row, and generally is sort of messy
[/quote]

It is perfectly valid C++, but you are right about the limitation in passing the data to functions. I will yield that a single dimensional array with bookkeeping is probably the better way to go. Perhaps done in a class that abstracts away the bookkeeping. Either that or a pointer of pointers, which can be passed around.

If the OP happens to be doing this in Java though, he can easily pass multidimensional arrays around.
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