Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (522)
Games in Android Showcase (127)
games submitted by our members
Games in WIP (590)
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  
  Tile Based Map Slick2d  (Read 744 times)
0 Members and 1 Guest are viewing this topic.
Offline superhigh

Senior Newbie





« Posted 2013-05-01 06:09:13 »

So I have a tiled map, that is 98x98 in length.(actually it's 99x99, but the whole outside border in unwalkable.)
I'm going through with A* pathfinder to find paths,
and I have set in the .tmx map some tiles blocking to 1, and walkable tiles to 0, that way I can use it with A*
So First of all, I just want to make sure my int[][] gets the right values,
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
public static int[][] mapdata = new int[98][98];

public static void MapInit() throws SlickException {
   TiledMap map = new TiledMap("res/testmap.tmx");
   int tryingx = 0;
   int tryingy = 0;
   System.out.println(map.getHeight() + "" + map.getWidth());
        for (int x=0;x<((int)map.getWidth() / 32);x++) {
        for (int y=0;y<((int)map.getHeight() / 32);y++) {
            System.out.println(x + " " + y);
            int id = map.getTileId(x, y, 0);
            String value = map.getTileProperty(id, "blocked", "true");
            if (value.equalsIgnoreCase("true")) {
               mapdata[tryingx][tryingy] = 1;
            } else {
            mapdata[tryingx][tryingy] = 0;
         }
          }
        }
        for (int x=0;x<98;x++) {
        for (int y=0;y<98;y++) {
                  System.out.println(mapdata[x][y]);
                }
              }

A= the row
B= the tile of the row
I actually want to make mapdata[ A ][ B ],
So, per say:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
mapdata = {
        {1,1,1,1,1,1,1,1,1,1},
        {1,0,0,0,0,0,1,1,1,1},
        {1,0,1,1,1,0,1,1,1,1},
        {1,0,1,1,1,0,0,0,1,1},
        {1,0,0,0,1,1,1,0,1,1},
        {1,1,1,0,1,1,1,0,0,1},
        {1,0,1,0,0,0,0,0,1,1},
        {1,0,1,1,1,1,1,1,1,1},
        {1,0,0,0,0,0,0,0,0,1},
        {1,1,1,1,1,1,1,1,1,1}
    };

The above code is just an example, but I want my mapdata to be read from the tmx file, not hardcoded like that.
I figured storing all of this data in an array would be easier than a text file, because after that is loaded into the array, I want to be able to set entities to something like "2" for interactable, etc. Is there anyway someone can direct me in the right path so i will be able to load the above mapdata correctly?
Offline superhigh

Senior Newbie





« Reply #1 - Posted 2013-05-01 18:57:14 »

bump
Offline Axeman

Senior Devvie


Medals: 7



« Reply #2 - Posted 2013-05-01 20:31:22 »

You´re not really stating a problem. You have a tmx file and then you load the data into an array which sets each tile as blocked or not blocked. What else do you want to do?
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline superhigh

Senior Newbie





« Reply #3 - Posted 2013-05-01 21:11:33 »

I'm not really sure if I'm loading the data in to the array properly?
Offline superhigh

Senior Newbie





« Reply #4 - Posted 2013-05-02 18:38:59 »

bump
Online Jimmt
« League of Dukes »

JGO Kernel


Medals: 138
Projects: 4
Exp: 3 years



« Reply #5 - Posted 2013-05-03 05:43:35 »

I'm not really sure if I'm loading the data in to the array properly?
wayy too vague. Run some tests, debugger, figure out what's wrong, if you can't fix it, then ask here. Anyways, to make .tmx files I'd recommend Tiled: http://www.mapeditor.org/
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.

trollwarrior1 (29 views)
2014-11-22 12:13:56

xFryIx (71 views)
2014-11-13 12:34:49

digdugdiggy (50 views)
2014-11-12 21:11:50

digdugdiggy (44 views)
2014-11-12 21:10:15

digdugdiggy (38 views)
2014-11-12 21:09:33

kovacsa (62 views)
2014-11-07 19:57:14

TehJavaDev (67 views)
2014-11-03 22:04:50

BurntPizza (64 views)
2014-11-03 18:54:52

moogie (80 views)
2014-11-03 06:22:04

CopyableCougar4 (79 views)
2014-11-01 23:36:41
Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

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
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!