Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
562 views
in Technique[技术] by (71.8m points)

path - Pathfinding 2D Java game?

I'm currently writing a very basic Java game based on the idea of Theme Hospital.

I'm quite new to Java and am currently studying at the university my first year. I have done Java for nearly two years now on and off, but I'm finally devoting my time to a decent project.

I'm at the stage where I need to create a person (patient) to be admitted to the hospital. They need to go to the reception desk, then GP's office, and then back to their starting position.

I have looked into A* path finding, but it seems really complicated to me. I understand how it works I think, but am unsure how to implement it into my game.

So far, the user can place a reception desk, and build a GP's office. Each of these has a "point of usage" which will be the place the patient has to get to. The grid squares can only be full or not, there will be no different terrain.

I'm hesitant to paste any code yet, as it's messy as I've learn a lot of new techniques to do with GUI in the past few months. My plan is to get to the milestone 1, making the patient go to the desk then the office and then leave. Once I have this, I will tidy up the code more.

I've seen many implementations of A* and many different types. Can someone give me a starting point I can work with? Should I try and adapt an already written set of classes, or try to write my own from the scratch?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You do want A*, it is the optimal implementation for grid based pathfinding.

This might help you out:

http://www.cokeandcode.com/main/tutorials/path-finding/

EDIT: The preceeding link is good for both as an implementable set of classes and as a guide for customizing the path finding methods to meet your satisfaction.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...