libgdx API之AI:AI让游戏对象思考

GdxAI是libgdx的一个AI库,里面有各种AI系统和算法,包括有限状态机,状态树,行为算法(追逐,躲避...群聚),路径算法。基于Message和Scheduler两种事件驱动机制。这绝对是个好东西,但要讲这些知识的话,就不是局限于libgdx这个平台了,AI算法是游戏开发通用的,所以以后随着我的学习可能会有这个专题。这里就先贴上状态机的demo。

状态机逻辑:

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.ai.fsm.State;
import com.badlogic.gdx.ai.msg.MessageManager;
import com.badlogic.gdx.ai.msg.Telegram;

/** @author davebaol */
public enum BobState implements State<Bob> {

	ENTER_MINE_AND_DIG_FOR_NUGGET() {
		@Override
		public void enter (Bob bob) {
			// if the miner is not already located at the goldmine, he must
			// change location to the gold mine
			if (bob.getLocation() != Location.GOLD_MINE) {
				talk(bob, "Walkin' to the goldmine");
				bob.setLocation(Location.GOLD_MINE);
			}
		}

		@Override
		public void update (Bob bob) {
			// Now bob is at the goldmine he digs for gold until he
			// is carrying in excess of MAX_NUGGETS. If he gets thirsty during
			// his digging he packs up work for a while and changes state to
			// go to the saloon for a whiskey.
			bob.addToGoldCarried(1);

			bob.increaseFatigue();

			talk(bob, "Pickin' up a nugget");

			// if enough gold mined, go and put it in the bank
			if (bob.isPocketsFull()) {
				bob.getStateMachine().changeState(VISIT_BANK_AND_DEPOSIT_GOLD);
			}

			if (bob.isThirsty()) {
				bob.getStateMachine().changeState(QUENCH_THIRST);
			}
		}

		@Override
		public void exit (Bob bob) {
			talk(bob, "Ah'm leavin' the goldmine with mah pockets full o' sweet gold");
		}
	},

	GO_HOM
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值