Skip to main content
GameDev.net gamedev.net
🔒 Locked

2d map for an rpg

Started by stein102 Jan 9, 2012 at 12:27 AM 43 replies 9.1k views
Original Post
stein102
stein102
I want to make a 2d rpg game, I'm stuck on how to make the map. I want to make a map with a grid, where you use the arrow keys to go from square to square. What is the best way to do this?

Thanks
bpx95
bpx95
One way is to make just a map file with contents that may look something like:

0 1 2 5 0 1
2 3 4 1 0 2
1 0 3 4 1 0
1 2 5 3 0 1

Where each of the numbers is the id of a type of square. So '0' might be dirt, '2' might be rock, etc. The file could look like a grid so that you can easily look at it and see what everything represents.

You can also use a tool such as Mappy: http://tilemap.co.uk/mappy.php
Or just make your own tile editor.

You just need a file that has a list of all the tiles in your world, and probably some info such as width and height of the world in tiles. Then your program can just open up the file, read the info it needs (width and height), then read in the tiles one-by-one. You can organize the tiles in an array.
stein102
stein102
I'm just starting my game now. I'm really not 100% on where to start, I thought doing the graphics would be a good start so I could see my progress as I moved on. If this is a bad idea, can you please point me in the right direction?

Thanks
Alpha_ProgDes
Alpha_ProgDes
Before you get hung up on maps, if I were you, I'd get a character (or any object) on the screen and move him around with the arrow keys first. That's normally the first thing to accomplish.
Beginner in Game Development?  Read here. And read here.  
stein102
stein102
After that, what is the next step? Because that doesn't take much time at all? I can get that done in a few minutes.
Alpha_ProgDes
Alpha_ProgDes

  1. After that get a static background on the screen and have the character/object move around in it.
  2. Add another character (NPC) that randomly moves around the screen.
  3. Get your character/object to shoot a projectile in the direction you are facing.

When you get those three things up and running, then you should be able to move on to maps. Feel free to post the code after you're done
Beginner in Game Development?  Read here. And read here.  
stein102
stein102
Thanks I'll get to work!
stein102
stein102
Okay, got that done, now I guess I'll add collision to everything? That would be my next step?
Alpha_ProgDes
Alpha_ProgDes
After you add collision, do the following:

  1. Have a file that has 20 letters across and 20 down. In all the grid should have 400 letters all together.
  2. Load that file, read the file one letter at a time and display each letter.
  3. Now associate a grass graphic with the letter g, rock graphic with the letter r, bush graphic with the letter b.
  4. Now create another 20 x 20 file filled with all r, g, and b's.
  5. Having the association of letter to graphic and reading that file should create a 20 x 20 map of rocks, grass, and bushes.
  6. You may or may not want to use a 2-dimensional array for this, depending on your approach.


Again, feel free to post code when you're done. But there people far more knowledgeable and experience than me that can help you with your approach, architecture, and code.


Note: see you tomorrow.
BeerNutts
BeerNutts
What i would suggest is either writing your own map editor, or use a tile-map tool. Considering, typical RPG's have large worlds, just using a text file with numbers representing tiles is not going to be easy or fun.

What you want is your world laid out in a map-tile editor, and you can actually see what it's going to look like on screen.

So, check out Mappy, or Tiled (google them), and port the output into your game, or you're going to write your own map.

FWIW, I'd suggest using Mappy or Tiled, but creating your own can have benefits as well. If you create your own, be sure most of the functionality will be re-used in your game.
My Gamedev Journal: 2D Game Making, the Easy Way

---(Old Blog, still has good info): 2dGameMaking
-----
"No one ever posts on that message board; it's too crowded." - Yoga Berra (sorta)
Alpha_ProgDes
Alpha_ProgDes
Well I agree with you BeerNutts that in the long run he should use a tool to do the job. But since it's his first go-around (I'm assuming) having hiim do this gets him familiar with the basic concepts.
Beginner in Game Development?  Read here. And read here.  
Toadhead
Toadhead
Wouldnt it be a good idea to use TileObjects instead of numbers?
These TileObjects can store the type of image being displayed (background and possible images on top like trees or 3d effects), the type of tile (passable or not), possibly the movements costs and a pointer to the object currently on it (a nullptr in case the tile is not occupied). Although I have to admit not having any experience in these kind of games, so I'm not sure about the performance using a system like this. This way you won't have to use collision detection, you can just use if(RelativeTile(1,0)->IsPassible() && RelativeTile(1,0)->Occupier() == nullptr) {moveRight()}

You do have to write your own map editor in that case.
Alpha_ProgDes
Alpha_ProgDes
Before we start getting real fancy with the tile data structures, we may want him to finish this up. He is still new to this.
Beginner in Game Development?  Read here. And read here.  
stein102
stein102
Have a file that has 20 letters across and 20 down. In all the grid should have 400 letters all together.

  1. Load that file, read the file one letter at a time and display each letter.
  2. Now associate a grass graphic with the letter g, rock graphic with the letter r, bush graphic with the letter b.
  3. Now create another 20 x 20 file filled with all r, g, and b's.
  4. Having the association of letter to graphic and reading that file should create a 20 x 20 map of rocks, grass, and bushes.
  5. You may or may not want to use a 2-dimensional array for this, depending on your approach.




I'm kinda lost on how to do that.

So, create a text file with 400 characters, load it, read it. That's about as far as I got.
stein102
stein102
I'm using Eclipse with Java.
Alpha_ProgDes
Alpha_ProgDes
Do you know how to load a graphic file in Java? (Honestly, I don't know the libraries that well, so don't take offense)
Beginner in Game Development?  Read here. And read here.  
stein102
stein102
I know how to load an image.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.