• 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
Diogo Abreu

C++ with SDL, help on how to create a 2D map

8 posts in this topic

Hey guys,

 

I'll begin by telling you exactly what I'm doing and then telling what kind of help I need.

 

What I'm doing:

I've been learning C++ and I've been learning how to do a text-based RPG game. It's something simple, you have a storyline to follow, classes, NPC's to talk to, combat system, menu system, equipping items system, etc etc.

 

- I have a fair knowledge of C++;

- I don't know how to, like, do checkpoints through I/O files (i think that's the correct term, forgive me if not).

- I have yet to start learning SDL.

 

What I want help with:

In that game, I want to have a simple 2D map that will help the player to know where he/she is to make the game much less confusing. This map will appear above the text and I want it to change as the player advances in the game, like:

 

|___|

|  o  |

|___|       (Player Location is "o")

 

You wake up in the middle of a forest bla bla bla a path goes North.

1: Go north

 

(player presses 1)

 

|      |

| __ |

|  o  |

|___|

|      |

|___|

 

bla bla bla bla the path continues to the north.

1: Go north

 

 

Get it?

Now I want to do this with SDL to make it easier so i don't have to build the map in C++ everytime I write a new area.

 

How can you help me:

 

I need a good tutorial (text or video, it's indifferent) that explains me how to build this kind of map for this purpose in SDL.

 

Does anyone know such a thing?

Can I learn how to do this by simply learning SDL?

Is there any other (preferrably simpler) way of doing this?

 

Thank you so much in advance.

0

Share this post


Link to post
Share on other sites

"You are likely to be eaten by a grue."  Couldn't resist. :)

 

Anyway, the details will depend on further information.  But in general it doesn't really matter if it is SDL or not, it will be more important to find a method of describing the map in a data description method.  In the most simplistic case you could start with:

 

6 6  # width and height
X X X O X X
O O O O X X
X X O X X X
... etc

 

Now a simple text reader can read in the file, allocate an array of 6*6 elements and then fill them in by reading the lines.  X's would be "solid" areas and the O's would be open areas (rooms).  Obviously this is exceptionally simple and you will want more information in most cases.  So, you may need to think in terms of graphs instead of a rectangular region of simple open/closed areas.  You also probably want to put things "in" the rooms so you want more detail.  You could do something like the following (lua based text style):

 

Rooms =
{
  "Room1" =
  {
    "Connections" = {{"North", "Room2"}, {"South", "RoomXXX"}},
    "Objects" = {{"Chest", GoldChest}}
     .... etc ...
  },
  "Room2" = .. etc ..
}

 

Reading in the more complex style description takes a bit more work of course and perhaps others would know of tutorials and such which may cover this.  In general though, SDL wouldn't help, SDL would be appropriate for the rendering side which is another subject all together.

2

Share this post


Link to post
Share on other sites

1. The feature you are trying to implement is called "Automapping".

2. SDL is used for opening a window with a context to display stuff on it and handles also the input. You have to think about if you want to use the SDL integrated 2D draw library or if you want to use OpenGL to draw your stuff. I can recommend you used OpenGL as it is easy to begin with, but also has endless level of complexity if you want to. Also there are a lot of tutorials for SDL+OpenGL 2D

3. The next problem would be you need to draw text in an SDL context, with OpenGL it could be hard for you to do text rendering. If you pick the SDL drawing library just use SDL_ttf.

4. I would do automapping with std::vector, so you have "dynamic arrays" and your level can grow

struct Location
{
	int x;
	int y;
};

vector<Location> automap;

void moveTo(int xPos, int yPos)
{	
	//Check if you already exploared this location
	bool alreadyAdded = false;
	for (unsigned int i = 0; i < automap.size; i++)
	{
			if (automap[i].x == xPos)
			{
				if (automap[i].y == yPos)
				{
					alreadyAdded = true;
				}
			}
	}
	if (!alreadyAdded)
	{
		Location tmpPos;
		tmpPos.x = xPos;
		tmpPos.y = yPos;
		automap.push_back(tmpPos);
	}
}

Lets say the location "middle in the forrest" is on position x:0 y:0 and if you start the game you call "moveTo(0,0);"

Your Player moves to the north then call "moveTo(0,1);".

Also its better if you make variables for the player-position and just call "moveTo(player.x,player.y)" every time you move to another location and also change the postion so if you go to the north just do "player.y++;" and call "moveTo(player.x,player.y);".

The only thing you need to do now is draw the actual map(which should be correctly automapped with my theorie of automapping).

But this is your decision on how to do that, if you choose OpenGL, i can help you again.

 

Hope this helps you a bit biggrin.png

2

Share this post


Link to post
Share on other sites

@AllEightUp the problem is that I want something drawed like in my example, not just with symbols like x's and o's, if I understood correctly what you were trying to say.

 

@ViX3LG0N that helped a bit, I would like to do it just with the SDL drawing library because I'm trying to learn SDL (and by trying I mean I nearly started) and learning even another "language" would be even more confusing for me. But that example you gave me left me a bit lost there ;D

0

Share this post


Link to post
Share on other sites

@theseven I believe @AllEightUp was trying to show you have to how he would "serialize" your data. Serialization is when you turn your in-memory data into file on the HD or SSD or Cloud Drive or whatever. SDL and OpenGL are both librarys and neither deal with data or data structures. I would probably either make a structure  called a graph (the boost library has a good one if you want to use that) and store the contents of the room in a struct/class in the graph and then you can setup your rendering from that.

1

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