Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (481)
Games in Android Showcase (110)
games submitted by our members
Games in WIP (548)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  .txt map basics  (Read 1478 times)
0 Members and 1 Guest are viewing this topic.
Offline Xeinnex

Junior Newbie





« Posted 2011-10-05 13:39:25 »

well i have some questions about storing maps in .txt files, i've read a lot on the subject and nothing seems to be enough to get me started on it.


well, i've always wanted to be a game developer, and to be honest i thought it would be much easier, but realizing how hard it is only makes me want to learn more.

so a part of the process of realizing how hard it was, was trying to get started in this game developing world by making an isometric game, (like final fantasy tactics (fft)), and well it didnt take too long until i noticed starting with an isometric game wasnt the best idea, so i decided to start with simple stuff and made some really crappy simple games like pong.

so i've got some experience with how the drawing part works on the screen with java, and got more familiar with the way coordinates work and other stuff, and finally i decided to start working on a harder game, yet not as hard as a fft game,  i decided to start making a simple side scroller.

when i say side scroller i mean it like super mario, (not megaman or metroid which are more complex).

so after making some research, i noticed that im going to need something called "tilesets" which contain all different tiles a map would use, (instead of having a single file for each tile, you have all the tiles in one file), so i have read a lot about that and i cant get it.

what i want, is a clear explanation of how it works (how to write/read from a txt file, how to take the parameters there and asign them a tile, and then how to take that tile from the tileset).

and if you cant explain it for some reason, then it might also be helpful if i could get a source code of a game that works with this.

thank you for your patience, i really need to get this mapping technices working so i can advance on my project.
Offline ReBirth
« Reply #1 - Posted 2011-10-05 15:51:30 »

Ah isometric game, should be added to my list Smiley

If you say about txt map, I think you'll create a huge world sized game. For starting, I think it's not necessary if it's not that big. Try to make your game on separate image files first. After done, you can try combine them into one file.

Basiclly, it's just about cropping. You decide the offset and size like drawing rect at g2d. The txt file is (for me) used for indexing.

Quote
when i say side scroller i mean it like super mario, (not megaman or metroid which are more complex).
platformer

Offline loom_weaver

JGO Coder


Medals: 17



« Reply #2 - Posted 2011-10-05 16:03:58 »

Instead of worrying about .txt files I would start by hard-coding the map directly into your code.

For example:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
public class Mapz {

    private char[][] tiles = new char[][] {
        {'*','*','*','*'},
        {'T','.','*','*'},
        {'*','*','*','*'},
        {'*','*','~','~'},
        {'.','.','~','~'},
        {'.','.','~','~'},
    };

    private char getTile(int row, int col) {
        return tiles[row][col];
    }


    public static void main(String args[]) {
        Mapz mapz = new Mapz();

        System.out.println(mapz.getTile(0,0));
        System.out.println(mapz.getTile(1,0));  // T
       System.out.println(mapz.getTile(4,2));  // ~
       System.out.println(mapz.getTile(5,0));  // .
   }
}


Once you have your data structures working then you'll have a better idea of what files you need and can begin implementing them.  It sounds like what you're trying to do could get a bit complicated and thus the recommendation to get files out of the picture for now.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Xeinnex

Junior Newbie





« Reply #3 - Posted 2011-10-05 17:21:04 »

well that sounds like a good idea, to keep the map inside the code while i worry about other stuff, sounds smart, anyways another question that i forgot to add last time:

how does the paint method work for arrays, like how does it know where to paint each square, and if the character moves, how to move all the tiles with it?

thank you
Offline h3ckboy

JGO Coder


Medals: 5



« Reply #4 - Posted 2011-10-06 06:00:01 »

well, u just treat it as your data for your map, its not really your map.

for example u could have a paint method in your map class where you have a double for loop (a loop in a loop), and then u just cycle throught he length and width of the map, drawing each tile.

and as for movement, just do all of your logic, and then change your map (if necessary) accordingly
Offline theagentd
« Reply #5 - Posted 2011-10-06 11:23:53 »

There is a small "bug" in Loom_weavers code. The first array index is the Y position. In the getTile(int row, int col) function it should return tiles[col][row]. The second System.out.println() which prints T should print *, right?

If you flip it that way, not only is it easier to relate the raw map file/code to the actual map, but you can draw the map in a console with just
1  
2  
3  
for(int row = 0; row < tiles.length; row++){
    System.out.println(tiles[row]);
}


If you want to have actual 2D graphics, it's easiest to use an image with a tile map. It's usually a big image with lots of smaller tiles (the ancient standard is 32x32 tiles). You then map each char in your char[][] map to an index in your tile map (in other words, you say that this char means this tile in the image) and draw that tile in its (x, y) position on the screen. To achieve scrolling, just offset the drawing with the character position.

Myomyomyo.
Offline Mads

JGO Ninja


Medals: 26
Projects: 3
Exp: 6 years


One for all!


« Reply #6 - Posted 2011-10-19 02:02:58 »

You can google most basic questions about the java language, if you're unsure of some functionality :-)

Offline ra4king

JGO Kernel


Medals: 345
Projects: 2
Exp: 5 years


I'm the King!


« Reply #7 - Posted 2011-10-19 05:13:13 »

There is a small "bug" in Loom_weavers code. The first array index is the Y position. In the getTile(int row, int col) function it should return tiles[col][row]. The second System.out.println() which prints T should print *, right?
No loom_weaver's code is correct. row = y axis, col = x axis Wink

Offline theagentd
« Reply #8 - Posted 2011-10-19 08:28:31 »

There is a small "bug" in Loom_weavers code. The first array index is the Y position. In the getTile(int row, int col) function it should return tiles[col][row]. The second System.out.println() which prints T should print *, right?
No loom_weaver's code is correct. row = y axis, col = x axis Wink
Yeah. X = Y and Y = X. It's not a bug, but it makes things much harder to read. Should System.in and System.out switch name? xD

Myomyomyo.
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

atombrot (27 views)
2014-08-19 09:29:53

Tekkerue (25 views)
2014-08-16 06:45:27

Tekkerue (23 views)
2014-08-16 06:22:17

Tekkerue (15 views)
2014-08-16 06:20:21

Tekkerue (22 views)
2014-08-16 06:12:11

Rayexar (61 views)
2014-08-11 02:49:23

BurntPizza (39 views)
2014-08-09 21:09:32

BurntPizza (31 views)
2014-08-08 02:01:56

Norakomi (37 views)
2014-08-06 19:49:38

BurntPizza (67 views)
2014-08-03 02:57:17
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!