Esempio n. 1
0
    // Use this for initialization
    void Start()
    {
        rb        = GetComponent <Rigidbody> ();
        _reloaded = true;
        //respawnTime = 0.2f;
        //_rand = Random.value * _mapManager.mapVertices.Length;
        //_rand = RandomVal ();
        //print(Console.WriteLine(MapManager.mapVertices[1]));
        _audioSource = GetComponent <AudioSource> ();
        _mapManager  = GameObject.Find("MapManager").GetComponent <MapManager> ();

        if (levelNum == 1)
        {
            _straightMovement = true;
        }
        else
        {
            _straightMovement = false;
        }
        Vector3 curDirVec = thisMapLine.GetDirectionVector();
        Vector3 newDirVec = new Vector3(-curDirVec.y, curDirVec.x, 0);

        rb.MoveRotation(Quaternion.LookRotation(new Vector3(0f, 0f, 1f), newDirVec));

        /*
         * if (Random.value > 0.5)
         *      _isCW = 1;
         * else
         *      _isCW = -1;
         */
    }
Esempio n. 2
0
    // Called by ships to get information on what the actual movement should be
    public MapLine UpdateMovement(Vector3 curPos, float relativeMovement, out Vector3 newPos, out MapLine newMapLine)     // , out Quaternion newRotation
    {
        newMapLine = null;

        curPos.z = 0;
        // Get the Vector3 normal that represents the direction in which the movement is
        // Multiply normal by relativeMovement, adding onto curPos to get newPos
        newPos = curPos + _dir.normalized * relativeMovement;

        // If either distance is longer than the length, then it means that curPos is out of bounds
        if (Vector3.Distance(startPos, curPos) > _length || Vector3.Distance(endPos, curPos) > _length)
        {
            // Prevent errors at the edges (when the MapLine is null)
            if (Vector3.Distance(startPos, curPos) > _length && rightLine == null)
            {
                newPos = curPos + _dir.normalized * -0.005f;
                return(null);
            }
            else if (Vector3.Distance(endPos, curPos) > _length && leftLine == null)
            {
                newPos = curPos + _dir.normalized * +0.005f;
                return(null);
            }

            // Length from start to cur longer means that the point is to the right
            if (Vector3.Distance(startPos, curPos) > _length)
            {
                float tempDist = Vector3.Distance(endPos, curPos);
                newMapLine = rightLine;
                // Start from the end of the line, and continue the rest of the distance on the next line
                if (rightLine != null)
                {
                    newPos = endPos + rightLine.GetDirectionVector() * (relativeMovement - tempDist);                     //  - 0.01f
                }
                // Otherwise it is to the left
            }
            else
            {
                float tempDist = Vector3.Distance(startPos, curPos);
                newMapLine = leftLine;
                // Start from the end of the line, and continue the rest of the distance on the next line
                if (leftLine != null)
                {
                    newPos = startPos + leftLine.GetDirectionVector() * (relativeMovement - tempDist);                     //  - 0.01f
                }
                // TODO Prevent errors at the leftmost line (when the MapLine is null)
            }
        }


        // TODO get newRotation

        // TODO assign the newRotation (if new MapLine)

        // Return null, or a new MapLine if out of bounds
        return(newMapLine);
    }
Esempio n. 3
0
    void SpawnFlipper(MapLine newMapLine)
    {
        Vector3    curDirVec = newMapLine.GetDirectionVector();
        Vector3    newDirVec = new Vector3(-curDirVec.y, curDirVec.x, 0);
        GameObject newShip   = Instantiate(flipperPrefab, newMapLine.GetMidPoint() + new Vector3(0, 0, transform.position.z + 1f), Quaternion.LookRotation(new Vector3(0f, 0f, 1f), newDirVec));

        newShip.GetComponent <Flipper>().SetMapLine(newMapLine);
        newShip.GetComponent <Flipper>().movementForce = _gameManager.currentRound * _gameManager.speedMulti;
    }
Esempio n. 4
0
    // Update is called once per frame
    void Update()
    {
        Vector3 curDirVec = curMapLine.GetDirectionVector();
        Vector3 newDirVec = new Vector3(-curDirVec.y, curDirVec.x, 0);

        highlighter.transform.rotation = Quaternion.LookRotation(new Vector3(0f, 0f, -1f), newDirVec);
        highlighter.transform.position = curMapLine.GetMidPoint() + new Vector3(0f, 0f, 20f);
        RectTransform rt = highlighter.GetComponent <RectTransform> ();

        rt.sizeDelta = new Vector2(1.1f * curMapLine.GetLength(), 40);
    }
Esempio n. 5
0
    void Move()
    {
        Vector3 newPos = curMapLine.GetMidPoint();

        newPos = newPos + new Vector3(0f, 0f, transform.position.z - moveSpeed * Time.deltaTime);

        _rigidbody.MovePosition(newPos);

        Vector3 curDirVec = curMapLine.GetDirectionVector();
        Vector3 newDirVec = new Vector3(-curDirVec.y, curDirVec.x, 0);

        //print (Quaternion.Euler(newDirVec));
        _rigidbody.MoveRotation(Quaternion.LookRotation(new Vector3(0f, 0f, 1f), newDirVec));
    }
Esempio n. 6
0
    // Called each update to move sideways
    void Move()
    {
        if (legacyMovement == true)
        {
            Vector3    newPos;
            MapLine    newMapLine;
            Quaternion newQuat;

            curMapLine.UpdateMovement(transform.position, Time.deltaTime * _inputValue * moveSpeed, out newPos, out newMapLine);

            if (movingForward == true)
            {
                newPos = newPos + new Vector3(0f, 0f, transform.position.z + moveSpeed * 0.02f);
            }

            _rigidbody.MovePosition(newPos);

            if (newMapLine != null)
            {
                curMapLine = newMapLine;
            }
        }
        else
        {
            Vector3 newPos = _nextMapLine.GetMidPoint();
            if (movingForward == true)
            {
                newPos = newPos + new Vector3(0f, 0f, transform.position.z + moveSpeed * 0.02f);
            }

            _rigidbody.MovePosition(newPos);

            Vector3 curDirVec = _nextMapLine.GetDirectionVector();
            Vector3 newDirVec = new Vector3(-curDirVec.y, curDirVec.x, 0);
            //print (Quaternion.Euler(newDirVec));
            _rigidbody.MoveRotation(Quaternion.LookRotation(new Vector3(0f, 0f, 1f), newDirVec));

            curMapLine = _nextMapLine;
        }
    }
Esempio n. 7
0
    void Move(bool flip)
    {
        Vector3 newPos = curMapLine.GetMidPoint();

        if (flip == true)
        {
            newPos = _nextMapLine.GetMidPoint();
        }

        if (transform.position.z > 0)
        {
            newPos = newPos + new Vector3(0f, 0f, transform.position.z - moveSpeed * 0.02f);
        }
        else
        {
            newPos = new Vector3(newPos.x, newPos.y, 0);
        }

        _rigidbody.MovePosition(newPos);

        if (flip == true)
        {
            Vector3 curDirVec = _nextMapLine.GetDirectionVector();
            Vector3 newDirVec = new Vector3(-curDirVec.y, curDirVec.x, 0);
            _rigidbody.MoveRotation(Quaternion.LookRotation(new Vector3(0f, 0f, 1f), newDirVec));

            curMapLine = _nextMapLine;

            if (transform.position.z > 0)
            {
                _nextMove = Time.fixedTime + flipCooldown;
            }
            else
            {
                _nextMove = Time.fixedTime + flipCooldown / 2;
            }
        }
    }
Esempio n. 8
0
    // Use this for initialization
    void Start()
    {
        rb        = GetComponent <Rigidbody> ();
        _reloaded = true;
        //respawnTime = 0.2f;
        //_rand = Random.value * _mapManager.mapVertices.Length;
        //_rand = RandomVal ();
        //print(Console.WriteLine(MapManager.mapVertices[1]));
        _audioSource = GetComponent <AudioSource> ();
        _mapManager  = GameObject.Find("MapManager").GetComponent <MapManager> ();
        _gameManager = GameObject.Find("GameManager").GetComponent <GameManager> ();
        levelNum     = _gameManager.currentRound;
        if (levelNum == 1)
        {
            _straightMovement = true;
        }
        else
        {
            _straightMovement = false;
        }
        //_straightMovement = true;
        Vector3 curDirVec = thisMapLine.GetDirectionVector();
        Vector3 newDirVec = new Vector3(-curDirVec.y, curDirVec.x, 0);

        transform.rotation = Quaternion.LookRotation(new Vector3(0f, 0f, 1f), newDirVec);
        //transform.Rotate(newDirVec);
        _finishedSwitch = true;
        StartCoroutine(FirePeriodically());

        /*
         * if (Random.value > 0.5)
         *      _isCW = 1;
         * else
         *      _isCW = -1;
         */
    }
Esempio n. 9
0
    // Update is called once per frame
    void Update()
    {
        if (rb.position.z <= 0)         //In case the player ship is flying in after respawning?
        {
            Vector3 _newPos;
            MapLine _newMapLine, _nextMapLine;
            //transform.position = new Vector3 (transform.position.x, transform.position.y, 0);
            rb.MovePosition(new Vector3(transform.position.x, transform.position.y, 0));
            rb.constraints = RigidbodyConstraints.FreezePositionZ;
            _currPlayerNum = GameObject.Find("Player").GetComponent <PlayerShip> ().curMapLine.GetLineNum();
            if (_isCW == 0)
            {
                int _beCW  = _currPlayerNum - thisMapLine.GetLineNum();
                int _beCCW = _mapManager.mapLines.Length - _currPlayerNum + thisMapLine.GetLineNum();
                if (_beCW > _beCCW)
                {
                    _isCW = 1;
                }
                else if (_beCW < _beCCW)
                {
                    _isCW = -1;
                }
                else                 //Equal distance from player
                {
                    if (Random.value > 0.5)
                    {
                        _isCW = 1;
                    }
                    else
                    {
                        _isCW = -1;
                    }
                }
            }
            //Move (_isCW);
            thisMapLine.UpdateMovement(transform.position, Time.deltaTime * _isCW * movementForce * 0.2f, out _newPos, out _newMapLine);
            rb.MovePosition(new Vector3(_newPos.x, _newPos.y, 0));
            if (_newMapLine != null)
            {
                thisMapLine = _newMapLine;
            }
            if (thisMapLine == GameObject.Find("Player").GetComponent <PlayerShip> ().curMapLine)
            {
                _nextMapLine = thisMapLine;
            }
            else if (_isCW == 1)
            {
                _nextMapLine = thisMapLine.leftLine;
            }
            else
            {
                _nextMapLine = thisMapLine.rightLine;
            }
            Vector3 curDirVec = _nextMapLine.GetDirectionVector();
            Vector3 newDirVec = new Vector3(-curDirVec.y, curDirVec.x, 0);
            //print (Quaternion.Euler(newDirVec));
            rb.MoveRotation(Quaternion.LookRotation(new Vector3(0f, 0f, 1f), newDirVec));
        }
        else if (_straightMovement)
        {
            //Only move in Z direction, aka depth
            //rb.constraints = RigidbodyConstraints.FreezePositionX | RigidbodyConstraints.FreezePositionY;
            //rb.AddForce (-1 * movementForce * transform.forward * Time.deltaTime);

            rb.MovePosition(transform.position + transform.forward * (Time.deltaTime * movementForce * -1));
        }
        else         //Switching lanes
        {
            Vector3 _newPos;
            MapLine _newMapLine, _nextMapLine = thisMapLine.leftLine;
            Vector3 _newPosZ = transform.position + transform.forward * (Time.deltaTime * movementForce * -1);
            //Move forward by one or a few pixels
            thisMapLine.UpdateMovement(transform.position, Time.deltaTime * 1 * movementForce * 0.2f, out _newPos, out _newMapLine);
            rb.MovePosition(new Vector3(_newPos.x, _newPos.y, _newPosZ.z));
            //While moving to next section of map
            Vector3 curDirVec = _nextMapLine.GetDirectionVector();
            Vector3 newDirVec = new Vector3(-curDirVec.y, curDirVec.x, transform.position.z);
            rb.MoveRotation(Quaternion.LookRotation(new Vector3(0f, 0f, 1f), newDirVec));
        }
    }