runawaypattern.java
来自「Java games programing--很好的java游戏编程源码」· Java 代码 · 共 38 行
JAVA
38 行
package com.brackeen.javagamebook.ai.pattern;
import java.util.Iterator;
import java.util.Collections;
import com.brackeen.javagamebook.game.GameObject;
import com.brackeen.javagamebook.math3D.Vector3D;
import com.brackeen.javagamebook.bsp2D.BSPTree;
/**
Direct aim at the player. Aim patterns return a direction
to fire, rather than a location.
*/
public class RunAwayPattern extends AIPattern {
public RunAwayPattern(BSPTree tree) {
super(tree);
}
public Iterator find(GameObject bot, GameObject player) {
// dumb move: run in the *opposite* direction of the
// player (will cause bots to run into walls!)
Vector3D goal = new Vector3D(player.getLocation());
goal.subtract(bot.getLocation());
// opposite direction
goal.multiply(-1);
// far, far away
goal.multiply(100000);
calcFloorHeight(goal, bot.getFloorHeight());
// return an iterator
return Collections.singleton(goal).iterator();
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?