Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (476)
Games in Android Showcase (106)
games submitted by our members
Games in WIP (533)
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  
  A* Pathfinding guidance please =)  (Read 1955 times)
0 Members and 1 Guest are viewing this topic.
Offline lolliver0342

Junior Newbie





« Posted 2011-04-14 14:12:04 »

Firstly, hi everyone! This is my first post =D

Right. I'm writing a 3D Tower Defense game at the minute using Java and LWJGL/Slick, everything's working well so far; I've got the map displaying, the tower placement sorted etc. but I'm now beginning to consider putting in some bad guys.

(project current state: http://img857.imageshack.us/img857/1959/loldefv10.png probably my biggest accomplishment with OpenGL to date, so be nice please ^^)

My map's drawn using a 2D array of shorts (0 for gravel, 1 for grass etc.) but I have no idea how to implement A* Pathfinding using just this array.

Any help at all would be much appreciated!

Regards,

Ollie.
Offline kappa
« League of Dukes »

JGO Kernel


Medals: 74
Projects: 15


★★★★★


« Reply #1 - Posted 2011-04-14 14:15:31 »

have a read of this article. It'll run you through the main pathfinding techniques and how to implement them in java.
Offline lolliver0342

Junior Newbie





« Reply #2 - Posted 2011-04-14 14:17:16 »

Wow, quick reply!

Cheers man, I'll have a read.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline lolliver0342

Junior Newbie





« Reply #3 - Posted 2011-04-14 14:54:11 »

have a read of this article. It'll run you through the main pathfinding techniques and how to implement them in java.

Hi Kappa.

Thanks for the link, that definitely clarified some things.

I've read through that tutorial and I (by hand) wrote down the source code from page 3 (the AStarNode and AStarSearch classes), and I understand the theory behind A* now. However I still have no clue how to convert my 2D array into connected nodes, or even how to implement the abstract methods defined in AStarNode.

I'm sorry if this is a trivial problem but I'm genuinely stuck on how to convert my array to nodes (with neighbours  Huh)

Regards,

Ollie.
Offline ReBirth
« Reply #4 - Posted 2011-04-14 15:10:03 »

^ I have same question too Evil

Offline kappa
« League of Dukes »

JGO Kernel


Medals: 74
Projects: 15


★★★★★


« Reply #5 - Posted 2011-04-14 15:21:15 »

You need to rethink the structure of your game and whether an array of short will work in this case (unlikely Smiley). There is no fixed way on how you should structure a game and it varies widely from genre.

Just of the top of my head, I say you could use a 2d array of custom objects to represent the map. So create your own object for example called MapTile. Each MapTile object will contain information on what type of tile it is and what Node it represents.

e.g.
1  
2  
3  
4  
class MapTile {
    int type;
    Node node;
}


1  
MapTile[] map = new MapTile[10];
Offline lolliver0342

Junior Newbie





« Reply #6 - Posted 2011-04-14 15:33:42 »

That's a good idea, thank you! I'll have a crack at it and get back to you.

Cheers for the assistance so far, you're a gentleman and a scholar. =)

Ollie.
Offline lolliver0342

Junior Newbie





« Reply #7 - Posted 2011-04-20 02:26:10 »

Heyy, I guess I can mark this thread as "solved" now!

The finished product (for now!) is here: http://www.youtube.com/watch?v=3q999sUC60o

Cheers for the help guys!
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.

pw (18 views)
2014-07-24 01:59:36

Riven (17 views)
2014-07-23 21:16:32

Riven (14 views)
2014-07-23 21:07:15

Riven (17 views)
2014-07-23 20:56:16

ctomni231 (45 views)
2014-07-18 06:55:21

Zero Volt (41 views)
2014-07-17 23:47:54

danieldean (32 views)
2014-07-17 23:41:23

MustardPeter (36 views)
2014-07-16 23:30:00

Cero (51 views)
2014-07-16 00:42:17

Riven (50 views)
2014-07-14 18:02:53
HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43

Experimental Toys
by Roquen
2014-04-28 13:24:22
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!