游戏设计要求:
创建一个地图和若干巡逻兵(使用动画);
每个巡逻兵走一个3~5个边的凸多边型,位置数据是相对地址。即每次确定下一个目标位置,用自己当前位置为原点计算;
巡逻兵碰撞到障碍物,则会自动选下一个点为目标;
巡逻兵在设定范围内感知到玩家,会自动追击玩家;
失去玩家目标后,继续巡逻;
计分:玩家每次甩掉一个巡逻兵计一分,与巡逻兵碰撞游戏结束;
程序设计要求:
必须使用订阅与发布模式传消息
subject:OnLostGoal
Publisher: ?
Subscriber: ?
工厂模式生产巡逻兵
友善提示1:生成 3~5个边的凸多边型
随机生成矩形
在矩形每个边上随机找点,可得到 3 - 4 的凸多边型
5 ?
友善提示2:参考以前博客,给出自己新玩法
订阅与发布模式
代码结构
巡逻兵的运动
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Com.Patrols;
public class PatrolBehaviour : MonoBehaviour {
private IAddAction addAction;
private IGameStatusOp gameStatusOp;
public int ownIndex;
public bool isCatching;
private float CATCH_RADIUS = 3.0f;
void Start () {
addAction = SceneController.getInstance() as IAddAction;
gameStatusOp = SceneController.getInstance() as IGameStatusOp;
ownIndex = getOwnIndex();
isCatching = false;
}
void Update () {
checkNearByHero();
}
int getOwnIndex() {
string name = this.gameObject.name;
char cindex = name[name.Length - 1];
int result = cindex - '0';
return result;
}
void checkNearByHero () {
if (gameStatusOp.getHeroStandOnArea() == ownIndex) {
if (!isCatching) {
isCatching = true;
addAction.addDirectMovement(this.gameObject);
}
}
else {
if (isCatching) {
gameStatusOp.heroEscapeAndScore();
isCatching