探路 2D Java 游戏? [英] Pathfinding 2D Java game?

查看:26
本文介绍了探路 2D Java 游戏?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在基于主题医院.

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

我对 Java 很陌生,目前正在大学学习第一年.我已经断断续续地使用 Java 近两年了,但我终于把时间花在了一个不错的项目上.

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.

我正处于需要创建一个人(患者)入院的阶段.他们需要去接待处,然后是 GP 的办公室,然后回到他们的起始位置.

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.

我已经研究过 A* 寻路,但对我来说似乎很复杂.我了解它的工作原理,但不确定如何在我的游戏中实现它.

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.

到目前为止,用户可以放置一个接待台,并建立一个 GP 的办公室.每一个都有一个使用点",这将是患者必须到达的地方.格子只能填满或不填,不会有不同的地形.

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.

我还犹豫要不要粘贴任何代码,因为它很混乱,因为我在过去几个月中学习了很多与 GUI 相关的新技术.我的计划是达到里程碑 1,让患者先去办公桌,然后去办公室,然后离开.有了这个,我再整理代码.

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.

我见过许多 A* 和许多不同类型的实现.有人可以给我一个可以与之合作的起点吗?我应该尝试改编一组已经编写好的类,还是尝试从头开始编写自己的类?

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?

推荐答案

你确实想要 A*,它是基于网格的寻路的最佳实现.

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

这可能对您有所帮助:

http://www.cokeandcode.com/main/tutorials/path-发现/

前面的链接既适合作为一组可实现的类,也适合作为自定义寻路方法以满足您的要求的指南.

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.

这篇关于探路 2D Java 游戏?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆