Esempio n. 1
0
    public void SpawnPowerUp()
    {
        int        index      = Random.Range(1, _mapManager.mapLines.Length - 1);
        MapLine    newMapLine = _mapManager.mapLines[index];
        float      _mapDepth  = _mapManager.depth;
        GameObject powerUp    = Instantiate(powerUpPrefab, newMapLine.GetMidPoint() + new Vector3(0, 0, 1 * _mapDepth), powerUpPrefab.transform.rotation);

        powerUp.GetComponent <PowerUp>().curMapLine = newMapLine;
        powerUp.GetComponent <PowerUp>().moveSpeed *= currentRound * speedMulti;
    }
Esempio n. 2
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. 3
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. 4
0
    //Spawns new flipper enemy on field, associated with map line
    public void SpawnFlipper()
    {
        int        index      = Random.Range(1, _mapManager.mapLines.Length - 1);
        MapLine    newMapLine = _mapManager.mapLines [index];
        float      _mapDepth  = _mapManager.depth;
        GameObject newShip    = Instantiate(flipperPrefab, newMapLine.GetMidPoint() + new Vector3(0, 0, 1 * _mapDepth), flipperPrefab.transform.rotation);

        if (test == true)
        {
            newShip.GetComponent <Flipper_New>().curMapLine = newMapLine;
            newShip.GetComponent <Flipper_New>().moveSpeed *= currentRound * speedMulti;
        }
        else
        {
            newShip.GetComponent <Flipper>().SetMapLine(newMapLine);
            newShip.GetComponent <Flipper>().movementForce = currentRound * speedMulti;
        }
    }
Esempio n. 5
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. 6
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. 7
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;
        }
    }