C++ map

Need help with an engine or coding not on the list? Need help with a game or the website and forums here? Direct all questions here.
Post Reply
pvtlink
Posts: 6
Joined: Thu Oct 15, 2009 11:07 pm

C++ map

Post by pvtlink »

Hello i was wonder how to make a map for my rpg that im going to code in c++
as in a map i want an environment that you can move a character like a "o"
but the map should look something like
**********************************************
* !!!!!!! !!!!!!!! *
* !! !! [------] *
* ^^^ [ ] *
* [------] *
* ^^ *
* ^ ^^^^ *
* ^ ^ o *
* ^^ ^^ ^^^ ~~~ *
* ~~ ~~~ *
* ~~ ~~ *
**********************************************

and the "o" can move around and if it enter something like the !! !! then it goes to a town.
User avatar
Perry
Posts: 409
Joined: Tue Jun 23, 2009 4:26 pm

Re: C++ map

Post by Perry »

Is this a text based/console type application? I would probably use a two dimensional array, then a for loop to draw the characters. I would give you an example but I can't spend much time at the computer right now because I am getting stuff ready for me to go on vacation. I will see what I can do though.
pvtlink
Posts: 6
Joined: Thu Oct 15, 2009 11:07 pm

Re: C++ map

Post by pvtlink »

Yeah it is a text based console application you cant really see the map because it got screwed up somehow but ok ill try to do that. thx =]
User avatar
Perry
Posts: 409
Joined: Tue Jun 23, 2009 4:26 pm

Re: C++ map

Post by Perry »

Here is what I have for the map drawing.

Code: Select all

#include <iostream>
#include <string>
using namespace std;

int main ()
{
	char map[10][10] ={
				  {'0', '0', '0', '0', '0', '0', '0', '0', '0', '0'},
                  {'0', '0', '0', '0', '0', '0', '0', '0', '0', '0'},
			      {'0', '0', '0', '0', '0', '0', '0', '0', '0', '0'},
                  {'0', '0', '0', '0', '0', '0', '0', '0', '0', '0'},
                  {'0', '0', '0', '0', '0', '0', '0', '0', '0', '0'},
                  {'0', '0', '0', '0', '0', '0', '0', '0', '0', '0'},
			      {'0', '0', '0', '0', '0', '0', '0', '0', '0', '0'},
                  {'0', '0', '0', '0', '0', '0', '0', '0', '0', '0'},
			      {'0', '0', '0', '0', '0', '0', '0', '0', '0', '0'},
                  {'0', '0', '0', '0', '0', '0', '0', '0', '0', '0'}
				};

		for(int y = 0; y < 10; y++)
         {
              for(int x = 0; x < 10; x++)
                   {
					  if(x == 9) cout << "\n";
					  else cout << map[y][x];
                   } 
		 }


system("PAUSE");
return 0;
}
You can just change the 0s to whatever you want and resize the map how ever you want by adjusting the values. When it comes to movement that is a little more tricky. I haven't done that in awhile and I am going to have to think about how it is done and do some testing. I hope to be able to help you by tonight but I leave very early in the morning so I need to get to sleep early.

EDIT: Well I thought about it and looked around and all I can come up with is to draw the character at an x and y position in the grid and edit the value after input. Sorry I can't come up with an example but I have a few things to do before I go and I need to do them before I work on this anymore.
pvtlink
Posts: 6
Joined: Thu Oct 15, 2009 11:07 pm

Re: C++ map

Post by pvtlink »

Thanks for the help cant wait for the moving thats what i really need so that i can make my text based rpg a little more fun and entertaining. :)
Post Reply

Return to “Advanced Help and Support”