3D游戏编程与设计7——模型与动画

1、智能巡逻兵
  • 提交要求:
  • 游戏设计要求:
    • 创建一个地图和若干巡逻兵(使用动画);
    • 每个巡逻兵走一个3~5个边的凸多边形,位置数据是相对地址。即每次确定下一个目标位置,用自己当前位置为原点计算;
    • 巡逻兵碰撞到障碍物,则会自动选下一个点为目标;
    • 巡逻兵在设定范围内感知到玩家,则会自动追击玩家;
    • 失去玩家目标后,继续巡逻;
    • 计分:玩家每次甩掉一个巡逻兵计一分,与巡逻兵碰撞游戏结束;
  • 程序设计要求:
    • 必须使用订阅与发布模式传消息
      • subject:OnLostGoal
      • Publisher:?
      • Subscriber:?
    • 工厂模式生产巡逻兵
  • 友善提示1:生产3~5个边的凸多边形
    • 随机生成矩形
    • 在矩形每个边上随机找点,可得到3~4的凸多边形
    • 5?

代码说明:

  • SSDirector:用来管理游戏场景的导演类。
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class SSDirector : System.Object
{
   

    private static SSDirector _instance;
    public ISceneController CurrentScenceController {
    get; set; }
    public static SSDirector GetInstance()
    {
   
        if (_instance == null)
        {
   
            _instance = new SSDirector();
        }
        return _instance;
    }
}
  • FirstController:游戏的第一个场景,用来加载资源。运用观察者模式,在游戏场景中订阅了分数以及游戏结束的事件,并在该类中实现具体事件。此外还提供了UserGUI可以使用的接口。
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public enum GameState : int {
    GAMEOVER, RUNNING, RESTART }

public class FirstController : MonoBehaviour, ISceneController, IUserAction
{
   

    PatrolFactory df = null;
    GameState gamestate;
    private GameObject player;
    private int score;

    void Awake()
    {
   
        SSDirector director = SSDirector.GetInstance();
        director.CurrentScenceController = this;
        df = Singleton<PatrolFactory>.Instance;
        director.CurrentScenceController.LoadResources();
        gamestate = GameState.RUNNING;
        score = 0;

        this.gameObject.AddComponent<UserGUI>();
        this.gameObject.AddComponent<GameEventManager>();
    }

    public void LoadResources()
    {
   
        //产生迷宫
        GameObject maze = Instantiate<GameObject>(Resources.Load<GameObject>("prefabs/maze"));
        maze.name = "maze";

        //产生玩家
        player = Instantiate<GameObject>(Resources.Load<GameObject>("prefabs/FreeVoxelGirlBlackhairPrefab 1"));
        player.name = "player";
        player.transform.position = new Vector3(0, 0, 2);

        df.GetPatrol(new Vector3(-13, 0, 8), PatrolDirection.RIGHT);
        df.GetPatrol(new Vector3(3, 0, 8), PatrolDirection.DOWN);
        df.GetPatrol(new Vector3(13, 0, 2), PatrolDirection.LEFT
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值