コード例 #1
0
ファイル: WaveMaster.cs プロジェクト: Amatsugu/Temp
 // Update is called once per frame
 void Update()
 {
     if (!_loadFail)
     {
         if (!_levelClear)
         {
             CountEnemies();
             if (!_enemySpawned && _nextWaveTime <= Time.time && !_waveClear)
             {
                 _waveClear = false;
                 Wave thisWave = _currentLevel.Waves[_curWave];
                 int  c        = 0;
                 _spawnedEnemies.Clear();
                 foreach (int i in thisWave.UnitID)
                 {
                     GameObject spawn = Instantiate(enemyUnits[i], new Vector3(thisWave.UnitPos[c].x, thisWave.UnitPos[c].y, 0), Quaternion.identity) as GameObject;
                     _spawnedEnemies.Add(spawn);
                     c++;
                 }
                 _enemySpawned = true;
                 CountEnemies();
             }
             if (_enemyCount == 0 && !_waveClear && _enemySpawned)
             {
                 _nextWaveTime = Time.time + waveDelay;
                 _waveClear    = true;
                 _curWave++;
             }
             if (_waveClear && _nextWaveTime <= Time.time)
             {
                 _enemySpawned = false;
                 _waveClear    = false;
             }
         }
         if (_curWave > _currentLevel.Waves.Count - 1)
         {
             _levelClear = true;
         }
         if (_levelClear || _gameOver)
         {
             if (_controls.GetKeyDown("Advance"))
             {
                 Application.LoadLevel("MainMenu");
             }
         }
     }
 }
コード例 #2
0
ファイル: PlayerController.cs プロジェクト: Amatsugu/Temp
 // Update is called once per frame
 void Update()
 {
     if (_isPaused == false)
     {
         if (_mouseMode)
         {
             RaycastHit hit;
             Vector3    rawPos = Input.mousePosition;
             //Vector3 mPos = new Vector3(rawPos.x, Screen.height - rawPos.y, 0);
             Physics.Raycast(Camera.main.ScreenPointToRay(rawPos), out hit);
             if (hit.point != Vector3.zero)
             {
                 Vector3 hp = new Vector3(hit.point.x, hit.point.y, 0);
                 _curPosition = Vector3.Lerp(_curPosition, hp, MouseSpeed * Time.deltaTime);
             }
         }
         else
         {
             if (_controls.GetKeyDown("Percise Move"))
             {
                 if (_controls.GetKeyDown("Up"))
                 {
                     _curPosition.y += MoveSpeed * Time.deltaTime;
                 }
                 if (_controls.GetKeyDown("Down"))
                 {
                     _curPosition.y -= MoveSpeed * Time.deltaTime;
                 }
                 if (_controls.GetKeyDown("Left"))
                 {
                     _curPosition.x -= MoveSpeed * Time.deltaTime;
                 }
                 if (_controls.GetKeyDown("Right"))
                 {
                     _curPosition.x += MoveSpeed * Time.deltaTime;
                 }
             }
             else
             {
                 if (_controls.GetKeyDown("Up"))
                 {
                     _curPosition.y += MoveSpeed * Time.deltaTime * 2;
                 }
                 if (_controls.GetKeyDown("Down"))
                 {
                     _curPosition.y -= MoveSpeed * Time.deltaTime * 2;
                 }
                 if (_controls.GetKeyDown("Left"))
                 {
                     _curPosition.x -= MoveSpeed * Time.deltaTime * 2;
                 }
                 if (_controls.GetKeyDown("Right"))
                 {
                     _curPosition.x += MoveSpeed * Time.deltaTime * 2;
                 }
             }
         }
         ClampPos();
         transform.position = _curPosition;
         //Fire Bullets
         if (canShoot)
         {
             if (Time.time >= _nextFireTime)
             {
                 Fire();
                 _nextFireTime = Time.time + fireRate;
             }
         }
         _curPower += (int)Input.GetAxisRaw("Mouse ScrollWheel");
         if (_curPower > 3)
         {
             _curPower = 0;
         }
         if (_curPower < 0)
         {
             _curPower = 3;
         }
         if (_controls.GetKeyDown("Ability"))
         {
             UsePower();
         }
         //Debug.Log(_curPower);
         if (_powerEndTime <= Time.time)
         {
             canShoot          = true;
             _bGunner.isFiring = false;
         }
         if (_curPosition.y < 0)
         {
             _paralax = paralaxAmmount * (_curPosition.y / upperBound.y);
         }
         if (_curPosition.y > 0)
         {
             _paralax = paralaxAmmount * (_curPosition.y / lowerBound.y) * -1;
         }
         _cam.position = new Vector3(_cam.position.x, _paralax, _cam.position.z);
     }
 }
コード例 #3
0
ファイル: LevelEditor.cs プロジェクト: Amatsugu/Temp
    // Update is called once per frame
    void Update()
    {
        if (_controls.GetKeyDown("Toggle Editor"))
        {
            _unitsWindow = !_unitsWindow;
            if (_unitsWindow)
            {
                _updatePointer = false;
            }
            else
            {
                _updatePointer = true;
            }
        }
        if (_controls.GetKeyDown("Cancel"))
        {
            _selectedUnit = -1;
        }

        if (_updatePointer)
        {
            Vector3    mousePos = Input.mousePosition;
            RaycastHit hit;
            Physics.Raycast(cam.ScreenPointToRay(mousePos), out hit);
            _desPoint = new Vector3(Mathf.Round(hit.point.x), Mathf.Round(hit.point.y), 0);
            if (_desPoint.x > 10)
            {
                _desPoint.x = 10;
            }
            if (_desPoint.x < -10)
            {
                _desPoint.x = -10;
            }
            if (_desPoint.y > 7)
            {
                _desPoint.y = 7;
            }
            if (_desPoint.y < -7)
            {
                _desPoint.y = -7;
            }
            pointer.transform.position = _desPoint;
        }
        Vector2 v2Pos = new Vector2(_desPoint.x, _desPoint.y);

        //Update Field
        if (_hasChanged)
        {
            foreach (GameObject g in _feildUnits)
            {
                Destroy(g);
            }
            _feildUnits.Clear();
            for (int i = 0; i < _currentLevel.Waves[_curWave].UnitID.Count; i++)
            {
                Wave       thisWave = _currentLevel.Waves[_curWave];
                Vector3    newPos   = new Vector3(thisWave.UnitPos[i].x, thisWave.UnitPos[i].y, 0);
                GameObject newUnit  = Instantiate(units[thisWave.UnitID[i]], newPos, Quaternion.identity) as GameObject;
                _feildUnits.Add(newUnit);
            }
            _hasChanged = false;
        }
        if (_selectedUnit != -1)
        {
            if ((_curObject == null))
            {
                _curObject = Instantiate(units[_selectedUnit], _desPoint, Quaternion.identity) as GameObject;
                _curObject.GetComponent <UnitStats>().SetGreen();
                _unitStats = _curObject.GetComponent <UnitStats>();
            }
            else if (_unitStats.unitID != units[_selectedUnit].GetComponent <UnitStats>().unitID)
            {
                Destroy(_curObject);
                _curObject = Instantiate(units[_selectedUnit], _desPoint, Quaternion.identity) as GameObject;
                _curObject.GetComponent <UnitStats>().SetGreen();
                _unitStats = _curObject.GetComponent <UnitStats>();
            }
            else
            {
                _curObject.transform.position = _desPoint;
            }
            if (!_thisWave.UnitPos.Contains(v2Pos))
            {
                _unitStats.SetGreen();
                if (Input.GetKeyDown(KeyCode.Mouse0) && !_unitsWindow)
                {
                    _thisWave.UnitID.Add(_unitStats.unitID);
                    _thisWave.UnitPos.Add(v2Pos);
                    _hasChanged = true;
                }
            }
            else
            {
                _unitStats.SetRed();
            }
        }
        else
        {
            if (_updatePointer)
            {
                if (_thisWave.UnitPos.Contains(v2Pos))
                {
                    if (_objectToReset != null)
                    {
                        _objectToReset.SetNone();
                    }
                    _objectToReset = GetFieldObj(_desPoint).GetComponent <UnitStats>();
                    _objectToReset.SetRed();
                    if (Input.GetKeyDown(KeyCode.Mouse0))
                    {
                        int index = _thisWave.UnitPos.IndexOf(v2Pos);
                        _thisWave.UnitPos.RemoveAt(index);
                        _thisWave.UnitID.RemoveAt(index);
                        _hasChanged    = true;
                        _objectToReset = null;
                    }
                }
                else if (_objectToReset != null)
                {
                    _objectToReset.SetNone();
                    _objectToReset = null;
                }

                Destroy(_curObject);
                _curObject = null;
            }
        }
        if (_unitsWindow)
        {
            _unitWinPos = Mathf.Lerp(_unitWinPos, 5, Time.deltaTime * animSpeed);
        }
        else
        {
            _unitWinPos = Mathf.Lerp(_unitWinPos, (_editorWindowH - 64) * -1, Time.deltaTime * animSpeed);
        }
    }