Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (491)
Games in Android Showcase (112)
games submitted by our members
Games in WIP (556)
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  
  How to read map for A*  (Read 799 times)
0 Members and 1 Guest are viewing this topic.
Offline Bassex96

Senior Member


Medals: 4



« Posted 2013-10-26 01:36:04 »

Hey guys, i'm back to work on my pacman game..I'm trying to implement a star pathfinding for the ghosts to follow the player...I'm using Tiled to load a map..I've got a separate layer for blocked tiles and i'm loading that layer to an array of blocked tiles...

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
   for (int y = 0;y < blockedLayer.getHeight();y++ ) {
         for (int x = 0; x < blockedLayer.getWidth();x++) {
                     
            //Set blocked tiles
           if (blockedLayer.getCell(x,y)!=null) {
            Rectangle tempRect = new Rectangle(x*16,y*16,16,16);
            blockedTiles.add(tempRect);
           
            if (blockedLayer.getCell(x, y)==null) continue;
           
            }


I'm trying to figure out how to get the blocked and non-blocked tiles together so I can start with the a*
Offline opiop65

JGO Kernel


Medals: 154
Projects: 7
Exp: 3 years


JumpButton Studios


« Reply #1 - Posted 2013-10-26 01:56:24 »

I don't understand the problem. Can't you just add all the blocks to one array?

Offline Bassex96

Senior Member


Medals: 4



« Reply #2 - Posted 2013-10-26 02:03:01 »

I'm thinking that may be what I need to do...but i'm not exactly sure how. I wrote this a couple months ago and am coming back to it.

Here is my map class.

http://pastebin.com/mde2gV0d
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline opiop65

JGO Kernel


Medals: 154
Projects: 7
Exp: 3 years


JumpButton Studios


« Reply #3 - Posted 2013-10-26 02:14:10 »

Honestly all you need to do is create a loop that loops through all your tiles in the map, and just add them to an arraylist or array. It shouldn't be that hard.

Offline Bassex96

Senior Member


Medals: 4



« Reply #4 - Posted 2013-10-26 02:29:22 »

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
 for (int y = 0;y < blockedLayer.getHeight();y++ ) {
         for (int x = 0; x < blockedLayer.getWidth();x++) {
                     
            //Set blocked tiles
           if (blockedLayer.getCell(x,y)!=null) {
            Rectangle tempRect = new Rectangle(x*16,y*16,16,16);
            blockedTiles.add(tempRect);
           
            if (blockedLayer.getCell(x, y)==null) continue;
           
            }


That's basically what I do here, except I only add the blocked tiles to an arraylist. I guess I could make another list and add the blocked and non-blocked tiles..I just don't see how I could implement that into the a* algorithm.

This is the first time i've ever attempted pathfinding, so please forgive me if I sound like an idiot. I just can't figure out how to get started.
Offline opiop65

JGO Kernel


Medals: 154
Projects: 7
Exp: 3 years


JumpButton Studios


« Reply #5 - Posted 2013-10-26 02:33:34 »

I think you're over complicating things. The other thing is that in A*, you only want to search for possible paths. That means you really should only have a list of tiles that aren't blocking your path. Any solid tiles don't actually need to be in the list.
Read this:
http://www.policyalmanac.org/games/aStarTutorial.htm

Offline Bassex96

Senior Member


Medals: 4



« Reply #6 - Posted 2013-10-26 02:42:56 »

That's the page i'm getting my a* information from. I see what you're saying. So I can make another array list just for the walkable tiles which makes sense now.

How would I just check the tiles close to the ghost? I can take the x and y of the ghost and then check through the arraylist and find the tile that the ghost is on...but i'm not sure how I would check the 8 tiles surrounding the ghost?
Offline opiop65

JGO Kernel


Medals: 154
Projects: 7
Exp: 3 years


JumpButton Studios


« Reply #7 - Posted 2013-10-26 03:04:50 »

Well do you store the positions of the tiles in the tile class? If not, you'll need an array, not an arraylist to store your tiles in. You can then loop through the tiles and get the current position of the loop. Example:
1  
2  
3  
4  
Tile up = null;
for(int x = 0; x < map_size; x++)
for(int y = 0; y < map_size; y++)
up = tiles[player.position.x][player.position.y + 1]

Obviously you'd need to check for out of bounds exceptions etc... But you really shouldn't use an arraylist as you'll never actually remove tiles. You may just change the tile type. That's why an array is better for these situations.

Offline Bassex96

Senior Member


Medals: 4



« Reply #8 - Posted 2013-10-26 03:14:40 »

See, that's the problem i'm having. It's a tiled tmx map. I've figured out how to add the blocked tiles to the arraylist..but i'm not so sure how to add all tiles to a multidimensional array as I would if I hardcoded the map.
Offline opiop65

JGO Kernel


Medals: 154
Projects: 7
Exp: 3 years


JumpButton Studios


« Reply #9 - Posted 2013-10-26 03:18:09 »

Oh, well there's where I'm of no help at all. I've never used tiled tmx map before sorry!

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Bassex96

Senior Member


Medals: 4



« Reply #10 - Posted 2013-10-26 03:32:47 »

Thanks anyways for the help! lol

I'm just reading away..hopefully I can get it figured out..
Offline opiop65

JGO Kernel


Medals: 154
Projects: 7
Exp: 3 years


JumpButton Studios


« Reply #11 - Posted 2013-10-26 03:36:11 »

Can I see how your tiles are loaded from the map file into the game? Maybe I could help then.

Offline Jimmt
« League of Dukes »

JGO Kernel


Medals: 128
Projects: 4
Exp: 3 years



« Reply #12 - Posted 2013-10-26 03:44:03 »

^ How is this in any way related to A* or pathfinding?
Offline Jimmt
« League of Dukes »

JGO Kernel


Medals: 128
Projects: 4
Exp: 3 years



« Reply #13 - Posted 2013-10-26 03:52:13 »

Yes.
Offline Bassex96

Senior Member


Medals: 4



« Reply #14 - Posted 2013-10-26 03:55:23 »

I was wondering the same thing..Thanks for the attempt at helping though!
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.

Nickropheliac (15 views)
2014-08-31 22:59:12

TehJavaDev (23 views)
2014-08-28 18:26:30

CopyableCougar4 (29 views)
2014-08-22 19:31:30

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

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

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

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

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

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

BurntPizza (48 views)
2014-08-09 21:09:32
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!