Пример #1
0
 protected override void Awake()
 {
     base.Awake();
     peopleTrigger = GetComponentInChildren <PeopleTrigger>();
     anim          = transform.GetComponentInChildren <Animation>();
     gameModel     = MVC.GetModel <GameModel>();
 }
Пример #2
0
    IEnumerator DisplayCount()
    {
        int count = 3;

        while (count > 0)
        {
            //显示
            Count.sprite = Numbers[count - 1];

            //自减
            count--;

            //等待1秒
            yield return(new WaitForSeconds(1f));

            if (count <= 0)
            {
                break;
            }
        }

        Hide();

        //倒计时结束
        MVC.GetModel <GameModel>().Dazhao = true;
        SendEvent(Consts.E_CountDownComplete);
    }
Пример #3
0
    //获取Model
    protected T GetModel <T>()
        where T : Model
    {
        T t = MVC.GetModel <T>();

        return(t);
    }
Пример #4
0
    protected override void Awake()
    {
        base.Awake();
        anim = GetComponentInChildren <Animation>();

        gm = MVC.GetModel <GameModel>();
        //StartCoroutine(huishou());
    }
Пример #5
0
    private void SetBtnsState()
    {
        GameModel gm = MVC.GetModel <GameModel>();

        btnFireBall.interactable  = gm.CanUseSkill(SkillType.FireBall);
        btnArrowRain.interactable = gm.CanUseSkill(SkillType.ArrowRain);
        btnLighting.interactable  = gm.CanUseSkill(SkillType.Lighting);
        btnCancel.interactable    = btnFireBall.interactable || btnArrowRain.interactable || btnLighting.interactable;
    }
Пример #6
0
    private void SetBtnsState()
    {
        GameModel gm = MVC.GetModel <GameModel>();

        btnSwordsman.interactable   = gm.CanInsSoldier(Arm.Swordsman);
        btnKnight.interactable      = gm.CanInsSoldier(Arm.Knight);
        btnLanceKnight.interactable = gm.CanInsSoldier(Arm.LanceKnight);
        btnHunter.interactable      = gm.CanInsSoldier(Arm.Hunter);
        btnHorseman.interactable    = gm.CanInsSoldier(Arm.Horseman);
        btnCancel.interactable      = btnSwordsman.interactable || btnKnight.interactable || btnLanceKnight.interactable || btnHunter.interactable || btnHorseman.interactable;
    }
Пример #7
0
    public void OnSwordsmanClick()
    {
        //if (Game.Instance.StaticData.GetSoldierInfo(Arm.Swordsman).Cost > MVC.GetModel<GameModel>().Energy)
        //    return;

        //SpawnSoldierArgs e1 = new SpawnSoldierArgs() { arm = Arm.Swordsman, camp = Camp.YELLOW, pos = new UnityEngine.Vector3(35, 5, 0) };
        //SendEvent(Consts.E_SpawnSoldier, e1);
        //SpawnSoldierArgs e2 = new SpawnSoldierArgs() { arm = Arm.Swordsman, camp = Camp.GREEN, pos = new UnityEngine.Vector3(220, 28.5f, 0) };
        //SendEvent(Consts.E_SpawnSoldier, e2);
        MVC.GetModel <GameModel>().SetCurrentSpawnType(Arm.Swordsman);
        txtCurrentChoice.text = "当前选择:" + "剑客";
    }
Пример #8
0
    protected override void Update()
    {
        //已爆炸跳过
        if (m_IsExploded)
        {
            return;
        }

        //移动
        transform.Translate(Direction * Speed * Time.deltaTime, Space.World);

        //旋转
        transform.Rotate(Vector3.forward, RotateSpeed * Time.deltaTime, Space.World);

        //检测(存活/死亡)
        GameObject[] monsterObjects = GameObject.FindGameObjectsWithTag("Monster");

        foreach (GameObject monsterObject in monsterObjects)
        {
            Monster monster = monsterObject.GetComponent <Monster>();

            //忽略已死亡的怪物
            if (monster.IsDead)
            {
                continue;
            }

            if (Vector3.Distance(transform.position, monster.transform.position) <= Consts.RangeClosedDistance)
            {
                //敌人受伤
                monster.Damage(this.Attack);
                if (monster.Hp <= 0)
                {
                    Random    random = new Random();
                    GameModel gm     = MVC.GetModel <GameModel>();
                    gm.Gold += Random.Range(5, 15);
                }
                //爆炸
                Explode();

                //退出(重点)
                break;
            }
        }

        //边间检测
        if (!m_IsExploded && !MapRect.Contains(transform.position))
        {
            Explode();
        }
    }
Пример #9
0
    protected override void Update()
    {
        //已爆炸无需跟踪
        if (m_IsExploded)
        {
            return;
        }

        //目标检测
        if (Target != null)
        {
            if (!Target.IsDead)
            {
                //计算方向
                Direction = (Target.transform.position - transform.position).normalized;
            }

            //角度
            LookAt();

            //移动
            transform.Translate(Direction * Speed * Time.deltaTime, Space.World);

            //打中目标
            if (Vector3.Distance(transform.position, Target.transform.position) <= Consts.DotClosedDistance)
            {
                //敌人受伤
                Target.Damage(this.Attack);
                if (Target.Hp <= 0)
                {
                    Random    random = new Random();
                    GameModel gm     = MVC.GetModel <GameModel>();
                    gm.Gold += Random.Range(5, 15);
                }
                //爆炸
                Explode();
            }
        }
        else
        {
            //移动
            transform.Translate(Direction * Speed * Time.deltaTime, Space.World);

            //边界检测
            if (!m_IsExploded && !MapRect.Contains(transform.position))
            {
                Explode();
            }
        }
    }
Пример #10
0
    void Update()
    {
        //鼠标左键检测
        if (Input.GetMouseButtonDown(0))
        {
            Tile t = GetTileUnderMouse();
            if (t != null)
            {
                //触发鼠标左键点击事件
                TileClickEventArgs e = new TileClickEventArgs(0, t);
                if (OnTileClick != null)
                {
                    OnTileClick(this, e);
                }
            }
        }

        //鼠标右键检测
        if (Input.GetMouseButtonDown(1))
        {
            Tile t = GetTileUnderMouse();
            if (t != null)
            {
                //触发鼠标右键点击事件
                TileClickEventArgs e = new TileClickEventArgs(1, t);
                if (OnTileClick != null)
                {
                    OnTileClick(this, e);
                }
            }
        }
        //大招显示
        GameModel gm = MVC.GetModel <GameModel>();

        if (Time.time - gm.TT > 10 && !gm.Dazhao)
        {
            gm.Dazhao             = true;
            go                    = Game.Instance.ObjectPool.Spawn("dazhao");
            go.transform.position = gm.des;
        }
        else if (gm.Dazhao && go == null)
        {
            go = Game.Instance.ObjectPool.Spawn("dazhao");
            go.transform.position = gm.des;
        }
        if (!gm.Dazhao && go != null)
        {
            Game.Instance.ObjectPool.Unspawn(go);
        }
    }
Пример #11
0
    void OnMouseDown()
    {
        if (m_Tower.IsTopLevel)
        {
            return;
        }
        GameModel gm = MVC.GetModel <GameModel>();

        if (gm.Gold >= m_Tower.Level * m_Tower.BasePrice)
        {
            UpgradeTowerArgs e = new UpgradeTowerArgs()
            {
                tower = m_Tower
            };
            SendMessageUpwards("UpgradeTower", e, SendMessageOptions.DontRequireReceiver);
        }
    }
Пример #12
0
    private void Start()
    {
        DontDestroyOnLoad(gameObject);

        M_ObjectPool = ObjectPool.M_Instance;
        M_Sound      = Sound.M_Instance;
        M_StaticData = StaticData.M_Instance;

        SceneManager.sceneLoaded += LevelLoadedEvent;

        MVC.RegisterModel(new GameModel());
        M_GM = MVC.GetModel <GameModel>();
        M_GM.Init();

        MVC.RegisterController(Consts.E_StartUpController, typeof(StartUpController));
        MVC.SendEvent(Consts.E_StartUpController);

        Game.M_Instance.LoadLevel(1);
    }
Пример #13
0
    public void SpawnSkillOnTouchDown(Vector2 tapPos)
    {
        GameModel gm = MVC.GetModel <GameModel>();

        Debug.Log(gm.CurrentSkillType);
        if (gm.CurrentSkillType == SkillType.NULL)
        {
            return;
        }

        if (gm.GetSkillState(gm.CurrentSkillType))
        {
            return;
        }

        if (gm.GetSkillCount(gm.CurrentSkillType) <= 0)
        {
            return;
        }

        Vector3    spawnPos = Vector3.zero;
        RaycastHit hit;

        if (Physics.Raycast(Camera.main.ScreenPointToRay(tapPos), out hit))
        {
            //if (hit.transform.tag != Tags.GROUND)
            //    return;

            spawnPos = hit.point;
        }

        if (spawnPos != null)
        {
            SpawnSkillArgs e1 = new SpawnSkillArgs()
            {
                skillType = gm.CurrentSkillType, camp = Camp.YELLOW, pos = spawnPos
            };
            MVC.SendEvent(Consts.E_SpawnSkill, e1);
        }
    }
Пример #14
0
    public void SpawnSoldierOnTouchDown(Vector2 tapPos)
    {
        Arm currentSpawnType = MVC.GetModel <GameModel>().CurrentSpawnType;

        if (currentSpawnType == Arm.NULL)
        {
            return;
        }

        if (Game.Instance.StaticData.GetSoldierInfo(currentSpawnType).Cost > MVC.GetModel <GameModel>().Energy)
        {
            return;
        }

        Vector3    spawnPos = Vector3.zero;
        RaycastHit hit;

        if (Physics.Raycast(Camera.main.ScreenPointToRay(tapPos), out hit))
        {
            if (hit.transform.tag != Tags.GROUND)
            {
                return;
            }

            spawnPos = hit.point;
        }

        if (spawnPos != null)
        {
            SpawnSoldierArgs e1 = new SpawnSoldierArgs()
            {
                arm = currentSpawnType, camp = Camp.YELLOW, pos = spawnPos
            };
            MVC.SendEvent(Consts.E_SpawnSoldier, e1);
        }
    }
Пример #15
0
 public void OnLightingClick()
 {
     MVC.GetModel <GameModel>().SetCurrentSkillType(SkillType.Lighting);
     txtCurrentChoice.text = "当前选择:" + "雷电";
 }
Пример #16
0
 protected override void Awake()
 {
     base.Awake();
     carTrigger = GetComponentInChildren <CarTrigger>();
     gameModel  = MVC.GetModel <GameModel>();
 }
Пример #17
0
 //获取Model
 protected T GetModel <T>()
     where T : Model
 {
     return(MVC.GetModel <T>() as T);
 }
Пример #18
0
 public Model GetModel <T>() where T : Model
 {
     return(MVC.GetModel <T>());
 }
Пример #19
0
 protected override void Awake()
 {
     base.Awake();
     gm = MVC.GetModel <GameModel>();
 }
Пример #20
0
 public void OnHorsemanClick()
 {
     MVC.GetModel <GameModel>().SetCurrentSpawnType(Arm.Horseman);
     txtCurrentChoice.text = "当前选择:" + "骑兵";
 }
Пример #21
0
 public void OnCancel()
 {
     MVC.GetModel <GameModel>().SetCurrentSpawnType(Arm.NULL);
     txtCurrentChoice.text = "当前选择:" + "无";
 }
Пример #22
0
 public void OnLanceKnightClick()
 {
     MVC.GetModel <GameModel>().SetCurrentSpawnType(Arm.LanceKnight);
     txtCurrentChoice.text = "当前选择:" + "长矛兵";
 }
Пример #23
0
 public void OnHunterClick()
 {
     MVC.GetModel <GameModel>().SetCurrentSpawnType(Arm.Hunter);
     txtCurrentChoice.text = "当前选择:" + "弓箭手";
 }
Пример #24
0
 void Awake()
 {
     m_Render = GetComponent <SpriteRenderer>();
     gm       = MVC.GetModel <GameModel>();
 }
Пример #25
0
 protected override void Awake()
 {
     base.Awake();
     gm   = MVC.GetModel <GameModel>();
     anim = GetComponentInChildren <Animation>();
 }
Пример #26
0
 //获取模型
 protected T GetModel <T>() where T : Model
 {
     return((T)MVC.GetModel <T>());
 }
Пример #27
0
 private void Start()
 {
     gm           = MVC.GetModel <GameModel>();
     txtGold.text = "拥有金币:" + gm.Gold;
 }
Пример #28
0
 //获取模型
 protected Model GetModel <T>()
     where T : Model
 {
     return(MVC.GetModel <T>());
 }
Пример #29
0
 private void Start()
 {
     gm = MVC.GetModel <GameModel>();
     StartCoroutine(EnergyRecovery());
 }
Пример #30
0
 public void OnArrowRainClick()
 {
     MVC.GetModel <GameModel>().SetCurrentSkillType(SkillType.ArrowRain);
     txtCurrentChoice.text = "当前选择:" + "箭雨";
 }