Exemplo n.º 1
0
    void Update()
    {
        this.SetIsSaveAndisDebug();
        //重制按鈕
        if (_isReSet)
        {
            this.Restart();
        }
        //換關按鈕
        if (_isNextLevel)
        {
            this.NextLevel();
        }
        //當沒有贏家的時候
        if (_winerFlag < 0)
        {
            _mapMat.setTo(_FogOfWarColor);
            //顯示大小改變
            if (transform.localScale.x != _mapWidth || transform.localScale.y != _mapHeight)
            {
                Debug.Log("update map" + transform.localScale.x + "x" + transform.localScale.y);
                InitBlock();
            }

            //設定角色座標和trigger
            Point[] characterPoint = _matchPointToOutputView.outputPoint.ToArray();

            if (characterPoint.Length != 0)
            {
                //Debug.Log("round: "+_whoRound);
                //Debug.Log(characterPoint[_whoRound]);
                //Debug.Log(_pointPlayer[_whoRound]);
                //判斷在玩家可走範圍內
                if (characterPoint[_whoRound].x <_pointPlayer[_whoRound].x + _pointRange && characterPoint[_whoRound].x> _pointPlayer[_whoRound].x - _pointRange &&
                    characterPoint[_whoRound].y <_pointPlayer[_whoRound].y + _pointRange && characterPoint[_whoRound].y> _pointPlayer[_whoRound].y - _pointRange)
                {
                    //累積移動時間增加
                    _movedTimer += Time.deltaTime;
                    //累積移動時間大於_movedTriggerTime,就移動玩家座標
                    if (_movedTimer > _movedTriggerTime)
                    {
                        _movedTimer = 0f;
                        _moved      = true;
                        Debug.Log("round: " + _whoRound + " Point: " + (int)_pointPlayer[_whoRound].x + "," + (int)_pointPlayer[_whoRound].y);
                    }
                }
                else
                {
                    //累積移動時間歸零,玩家維持原座標
                    _movedTimer             = 0f;
                    _pointPlayer[_whoRound] = characterPoint[_whoRound];
                }
            }

            //顯示玩家目前座標
            _coordinateP1.text = "X:" + _mapData.getPlayerPos(0).x.ToString() + "Y:" + _mapData.getPlayerPos(0).y.ToString();
            _coordinateP2.text = "X:" + _mapData.getPlayerPos(1).x.ToString() + "Y:" + _mapData.getPlayerPos(1).y.ToString();

            //如果滑鼠點擊
            this.ClickMouseUpEvent();

            //讓道具閃爍
            this.Flicker();

            //搜尋兩個玩家可走區塊
            for (int ID = 0; ID < _mapData.getPlayerCount(); ID++)
            {
                CanGo((int)(_mapData.getPlayerPos(ID).x), (int)(_mapData.getPlayerPos(ID).y), _playerCanSee[ID]);
            }

            //確認有沒有玩家碰到道具
            for (int ID = 0; ID < _mapData.getPlayerCount(); ID++)
            {
                if (this.GetTreadsureOrNot(ID))
                {
                    //寶藏
                    _winerFlag      = ID;
                    _roundText.text = "Player " + (ID + 1) + " win!!";
                    _WinTip.transform.localPosition = new Vector3(292, -120, -1);
                    Debug.Log("ID = " + ID + ",X = " + _mapData.getPlayerPos(ID).x + ",Y = " + _mapData.getPlayerPos(ID).y + ", get the treadsure");
                }
                if (this.GetSightOrNot(ID))
                {
                    //視野
                    _playerCanSee[ID]++;
                    _moveState.text = "Get Sight";
                }
                if (this.GetBombOrNot(ID))
                {
                    //爆炸
                    if (ID == 0)
                    {
                        _mapData.setPlayerPos(ID, new Point(0, 4));
                    }
                    if (ID == 1)
                    {
                        _mapData.setPlayerPos(ID, new Point(15, 3));
                    }
                }
            }

            //畫地圖(外框、兩個玩家可走區塊),寶藏
            if (_isDraw)
            {
                this.DrawMap();
                // this.DrawTreadsure();
            }

            //畫寶藏
            for (int i = 0; i < _mapData.getTreadsurePos().Count; i++)
            {
                _treasure.SetActive(_isDraw && _mapData.isExistCanMoveArea(_mapData.getTreadsurePos(i)) || _isFullMap);
            }

            //畫眼睛道具
            //Debug.Log("Num = " + _mapData.getBombPos().Count);
            // Debug.Log("Num = " + _mapData.getSightPos().Count);
            for (int i = 0; i < _mapData.getSightPos().Count; i++)
            {
                _sight[i].SetActive(_isDraw && _mapData.isExistCanMoveArea(_mapData.getSightPos(i)) || _isFullMap);
            }
            for (int i = 0; i < _mapData.getBombPos().Count; i++)
            {
                // _bomb[i].SetActive(_isDraw && _mapData.isExistCanMoveArea(_mapData.getBombPos(i)) ||_isFullMap);
                if (_isFullMap)
                {
                    _bomb[i].SetActive(true);
                }
            }
            //畫玩家
            if (_isDebug)
            {
                for (int ID = 0; ID < _mapData.getPlayerCount(); ID++)
                {
                    DrawPlayer(ID);
                }
            }
            //轉換地圖mat至顯示結果
            Utils.matToTexture2D(_mapMat, _tex);
            gameObject.GetComponent <Renderer>().material.mainTexture = _tex;
        }
        else
        {
            //有贏家的時候
            if (_winRect < 0.5f)
            {
                _winRect += Time.deltaTime;
            }
            this.BlowUp(_WinTip, _winRect);
        }
    }