Sonic and Sega Retro Message Board: Generating a 2D Map - Sonic and Sega Retro Message Board

Jump to content

Hey there, Guest!  (Log In · Register) Help
Page 1 of 1
    Locked
    Locked Forum

Generating a 2D Map The best way to build a map

#1 User is offline lotzi 

Posted 12 November 2017 - 09:09 PM

  • Posts: 4
  • Joined: 24-September 17
  • Gender:Male
What is the best way to build a 2D tile map using code? My idea is to have a file that contains the layout of a map. My code then reads each line from the file and places the specific tile in the correct row/column depending on the character at the specific spot. Is there an easier way to build a map than the idea I suggested?

#2 User is offline Aerosol 

Posted 12 November 2017 - 11:08 PM

  • FML and FU2
  • Posts: 9822
  • Joined: 27-April 08
  • Gender:Male
  • Location:Not where I want to be.
  • Project:Sonic (?): Coming summer of 2055...?
Tilengine. Too lazy to hyperlink it for you. Practice your Szechuan-style Google Fu.

#3 User is offline Liraxus 

Posted 13 November 2017 - 05:33 AM

  • Some shmuck
  • Posts: 82
  • Joined: 03-May 12
  • Gender:Male
  • Location:Idiotville
  • Project:Nothing, really.

View PostAerosol, on 12 November 2017 - 11:08 PM, said:

Tilengine. Too lazy to hyperlink it for you. Practice your Szechuan-style Google Fu.

This was the last place I was expecting to laugh this hard.

#4 User is offline Kharen 

Posted 13 November 2017 - 02:52 PM

  • Posts: 600
  • Joined: 29-October 11
  • Gender:Male
  • Location:Eastern Washington University
Okay, here's a similar question.

Which would be more efficient for a game made in Game Maker?

1: Small Tiles, along the lines of 16x16 or 32x32, used to make a level on par with the Classic games length-wise
2: Level Chunks, built to the same size as the classic games (either the large chunks in Sonic 1 or the smaller ones used in S3+K)
3: Fully pre-made single-image background map used for the entire level

I've been messing with making some really nice graphics, but I'm not sure how well they'd work in a traditional tileset without making hundreds of seemingly-identical tiles with minute shading differences. If I break it down into small tiles, I may have to start simplifying and removing stuff to make it easier to work with. If I go with level chunks, I'll have the same issue, albeit to a much lesser extent. If I just keep the entire level's graphics as a single massive image, I have really nice hand-made shading on the graphics, but I'm not sure if that will hurt level performance very much.

#5 User is offline Techokami 

Posted 13 November 2017 - 04:13 PM

  • For use only on NTSC Genesis systems
  • Posts: 1278
  • Joined: 19-November 05
  • Gender:Male
  • Location:HoleNet!
  • Project:Sonic Edge
  • Wiki edits:63
Chunks is the smartest way to go, really. If you have gargantuan image files serving as the full level layout, it would be rough on the GPU. And since Game Maker doesn't offer safety nets for everything, it could get ugly real quick.

#6 User is offline Kharen 

Posted 13 November 2017 - 04:45 PM

  • Posts: 600
  • Joined: 29-October 11
  • Gender:Male
  • Location:Eastern Washington University
Alright, thanks. I wasn't even originally planning on doing a game with these graphics, I was just having some fun screwing around with Paint.NET and adding a bunch of transparency gradients and shading, and realized that it actually looked pretty cool. Then I realized just how complicated it was going to be to try and break it up into something usable if I went the traditional tile-based route.

#7 User is offline lotzi 

Posted 13 November 2017 - 07:11 PM

  • Posts: 4
  • Joined: 24-September 17
  • Gender:Male

View PostAerosol, on 12 November 2017 - 11:08 PM, said:

Practice your Szechuan-style Google Fu.


Thank you for giving me my new "About Me" description

#8 User is offline lotzi 

Posted 14 November 2017 - 08:44 PM

  • Posts: 4
  • Joined: 24-September 17
  • Gender:Male
Since I did a terrible job explaining my idea at the beginning of this post, I've decided to explain my idea with better detail.

I'm going to be writing my map generator using C++ and SFML. The idea is to read a txt file that contains characters that represent different types of tiles. For example, X could represent a wall, O can be the floor, and D can be a door. My txt file can look like the following:

XXXXXXXXXXXXXXXXXX
XOOOOOOOOOOOOOOX
XOOOXXXXXXXXXOOOX
XOOOXOOOOOOXOOOX
XOOOXOOOOOOXOOOX
XOOOXOOOOOOXOOOX
XOOOXOOOOOOXOOOX
XOOOXXXDDXXXXOOOX
XOOOOOOOOOOOOOOX
XXXXXXXXXXXXXXXXXX

I can write a nested loop that will first loop through each line of the txt file, while the second iterates through each character in the line. Depending on the character, a specific type of tile is created with it's own characteristics.

What is your guy's opinion on this idea? Are there better ways of approaching this problem?

#9 User is offline Aerosol 

Posted 14 November 2017 - 09:16 PM

  • FML and FU2
  • Posts: 9822
  • Joined: 27-April 08
  • Gender:Male
  • Location:Not where I want to be.
  • Project:Sonic (?): Coming summer of 2055...?
Why do you want to reinvent the wheel? I mean the idea is sound enough, sure. It might be better to use XML to describe the tilemap, but Tilengine (in conjunction with Tiled Map Editor's map and tileset format, which are just xml's basically) already do these things.

I mean if you use C# it's even easier. I think it includes an XML parsing library now? And if you're adamant on using C++, I'm sure there are XML parsing libraries you can tack onto your project.

Your approach is, as far as I can tell, how tilemaps are usually rendered.

#10 User is offline winterhell 

Posted 15 November 2017 - 05:10 AM

  • Posts: 1126
  • Joined: 16-October 10
  • Gender:Male
Don't use a text editor to edit the levels. That is lazy and counterproductive, and you'll waste more time in the end.
Instead you can integrate the level editor. You set keys that change the position of the current tile you are working on ( say IJKL, but could be WASD or left right up down), and a way to alter that tile, perhaps with a simple +/- key combination, and or with an image showing the list of all tiles. You press F5 and you save to a binary file with 16 bit integers, or press F8 to load the level.
It might take you half an hour or so to add the editor.
Here is an example of how it might look with the tile list on the left and the level on the right. For what is worth it took me about 3-4 hours to dial in the whole MHZ Act 1 with that back in the Sonic 3 HD's tech demo. I used an image from zone0 as a red background blueprints to know what I'm doing.
Posted Image

#11 User is offline Amnimator 

Posted 15 November 2017 - 06:04 AM

  • Posts: 222
  • Joined: 15-April 13
  • Gender:Male
If you're going to store tile data and implement it into a level editor, or what not, you'll probably want to do so by having tile IDs. For the most part, they'd start at 0 at one corner of the image (lower left for example), sweep in the x axis (left to right for example) assigning IDs (0,1,2), then repeating the process by doing it again moving up in the y axis. This way you can just assign what tile you need using IDs.

You can also get the tile's x and y position from an ID using a formula like this: (id % size.x), (id / size.x).
So, let's say there's a 3x3 grid.

ID of 0: Modulo (fancy way of saying the remainder) of 0/3 is 0. Int division of 0/3 is 0. So (0,0).

ID of 1: Modulo of 1/3 is 1. Int division of 1/3 is 0. So (1,0).

ID of 2: Modulo of 2/3 is 2. Int division of 2/3 is 0. So (2,0)

ID of 3: Modulo of 3/3 is 0. Int division of 3/3 is 1. So (0,1).

EDIT: Fixed the formula, had a y instead of an x.
This post has been edited by Amnimator: 29 November 2017 - 04:06 PM

#12 User is offline lotzi 

Posted 15 November 2017 - 10:26 PM

  • Posts: 4
  • Joined: 24-September 17
  • Gender:Male
Would I need to implement my own level editor, or is there software online I can use? Also, does anyone have any books to recommend?
This post has been edited by lotzi: 15 November 2017 - 10:40 PM

#13 User is offline Amnimator 

Posted 16 November 2017 - 07:41 AM

  • Posts: 222
  • Joined: 15-April 13
  • Gender:Male
There are some tilemap editors that would be independent of the engine, like Tiled. Implementing it yourself sounds like it can have its benefits, but I'm not the most knowledgeable person here regarding creating game engines themselves. I follow a strict "learn whatever whenever I need it" case by case basis :V

Page 1 of 1
    Locked
    Locked Forum

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users