Esempio n. 1
0
    void FixedUpdate()
    {
        // Determine where we aim to go
        _playerScript = GameObject.Find("Player").GetComponent <PlayerShip>();
        if (_playerScript != null)
        {
            _targetMapLine = _playerScript.curMapLine;
        }

        // Find shortest path and next step (_nextMapLine)
        int rightDist = curMapLine.getShortestDist(curMapLine.leftLine, _targetMapLine);
        int leftDist  = curMapLine.getShortestDist(curMapLine.rightLine, _targetMapLine);

        if (leftDist < rightDist)
        {
            _nextMapLine = curMapLine.leftLine;
        }
        else if (leftDist >= rightDist && leftDist > 0)
        {
            _nextMapLine = curMapLine.rightLine;
        }
        else
        {
            _nextMapLine = curMapLine;
        }

        Move(_nextMove <= Time.fixedTime);
    }
Esempio n. 2
0
    void FixedUpdate()
    {
        if (curMapLine == null)
        {
            curMapLine = _mapManager.mapLines [2];
        }


        if (legacyMovement == true)
        {
            _inputValue = Input.GetAxis(inputAxis);
        }
        else
        {
            Vector3 mousePos = Input.mousePosition;
            _targetMapLine = curMapLine;
            foreach (MapLine ml in _mapManager.mapLines)
            {
                Vector3 MLPos    = camera.WorldToScreenPoint(ml.GetMidPoint());
                Vector3 curMLPos = camera.WorldToScreenPoint(_targetMapLine.GetMidPoint());
                if (Vector3.Distance(mousePos, MLPos) < Vector3.Distance(mousePos, curMLPos))
                {
                    _targetMapLine = ml;
                }
            }
            int rightDist = curMapLine.getShortestDist(curMapLine.leftLine, _targetMapLine);
            int leftDist  = curMapLine.getShortestDist(curMapLine.rightLine, _targetMapLine);
            if (leftDist < rightDist)
            {
                _nextMapLine = curMapLine.leftLine;
            }
            else if (leftDist >= rightDist && leftDist > 0)
            {
                _nextMapLine = curMapLine.rightLine;
            }
            else
            {
                _nextMapLine = curMapLine;
            }
            //curMapLine = _targetMapLine;
        }
        //if (_nextMove <= Time.fixedTime) {
        Move();
        //	_nextMove = Time.fixedTime + moveCooldown;
        //}

        if ((Input.GetMouseButton(0) || Input.GetKey(KeyCode.Space)) && _lastFire + fireCooldown < Time.fixedTime && _curBullets < maxBullets)
        {
            Fire();
            _lastFire = Time.fixedTime;
        }

        if ((Input.GetKey(KeyCode.LeftControl) || Input.GetMouseButton(1)) && _zapperReady == true)
        {
            Zapper();
            _zapperReady = false;
        }
    }
Esempio n. 3
0
 public int getShortestDist(MapLine lastMapLine, MapLine targetMapLine)
 {
     if (targetMapLine == this)
     {
         return(0);
     }
     else if (leftLine == lastMapLine && rightLine != null)
     {
         return(rightLine.getShortestDist(this, targetMapLine) + 1);
     }
     else if (rightLine == lastMapLine && leftLine != null)
     {
         return(leftLine.getShortestDist(this, targetMapLine) + 1);
     }
     else
     {
         Debug.Log("getShortestDist encounters incorrect condition");
         return(1000000000);
     }
 }
Esempio n. 4
0
    void FixedUpdate()
    {
        if (curMapLine == null)
        {
            curMapLine = _mapManager.mapLines [2];
        }


        if (legacyMovement == true)
        {
            _inputValue = Input.GetAxis(inputAxis);
        }
        else
        {
            Vector3 mousePos = Input.mousePosition;
            _targetMapLine = curMapLine;
            float dis = cam.GetComponent <CameraManager> ().distance;
            foreach (MapLine ml in _mapManager.mapLines)
            {
                Vector3 MLPos = cam.WorldToScreenPoint(new Vector3(ml.GetMidPoint().x, ml.GetMidPoint().y, 0));                    //cam.transform.position.z - cam.depth
                if (movingForward == true)
                {
                    MLPos = cam.WorldToScreenPoint(new Vector3(ml.GetMidPoint().x, ml.GetMidPoint().y, cam.transform.position.z - dis));
                }
                Vector3 curMLPos = cam.WorldToScreenPoint(new Vector3(_targetMapLine.GetMidPoint().x, _targetMapLine.GetMidPoint().y, 0));                    //
                if (movingForward == true)
                {
                    curMLPos = cam.WorldToScreenPoint(new Vector3(_targetMapLine.GetMidPoint().x, _targetMapLine.GetMidPoint().y, cam.transform.position.z - dis));
                }
                float mlDist  = Vector3.Distance(mousePos, MLPos);                 //- _mapManager.mapLineDistBonus [ml.GetLineNum ()];
                float curDist = Vector3.Distance(mousePos, curMLPos);              //- _mapManager.mapLineDistBonus [_targetMapLine.GetLineNum ()];
                if (mlDist < curDist)
                {
                    //print ("Line " + ml.GetLineNum () + " (" + Mathf.RoundToInt(mlDist).ToString() + ") is closer than Line " + _targetMapLine.GetLineNum () + " (" + Mathf.RoundToInt(curDist).ToString() + ")");
                    _targetMapLine = ml;
                }
            }

            int rightDist = curMapLine.getShortestDist(curMapLine.leftLine, _targetMapLine);
            int leftDist  = curMapLine.getShortestDist(curMapLine.rightLine, _targetMapLine);
            if (leftDist < rightDist)
            {
                _nextMapLine = curMapLine.leftLine;
            }
            else if (leftDist >= rightDist && leftDist > 0)
            {
                _nextMapLine = curMapLine.rightLine;
            }
            else
            {
                _nextMapLine = curMapLine;
            }
        }

        Move();

        if ((Input.GetMouseButton(0) || Input.GetKey(KeyCode.Space)) && _lastFire + fireCooldown < Time.fixedTime && _curBullets < maxBullets)
        {
            Fire();
            _lastFire = Time.fixedTime;
        }

        if ((Input.GetKey(KeyCode.LeftControl) || Input.GetMouseButton(1)) && _zapperReady == true)
        {
            Zapper();
            _zapperReady = false;
        }
    }