예제 #1
0
    //The spawn of the enemy doesn't belong anymore to update, it belong now to the scenario
    void Update()
    {
        //Checks whether  button was pressed per update
        //This button also correspond to touch screen
        if (Input.GetMouseButtonDown(0))
        {
            HandleTouch();
        }

        //Check if the player have lost
        if (playerHealth <= 0 && startingPlayerHealth > 0) //we check if the sarting player health is > 0 for debug reason, we will set starting life at 0 to try the game
        {
            Debug.Log("Defeat!");
            BeginNewGame();
        }

        //Check if player have win ( no more enemies to spawn and on the board)
        if (!activeScenario.Progress() && enemies.IsEmpty)
        {
            Debug.Log("Victory!");
            BeginNewGame();
            activeScenario.Progress();
        }

        //Update
        enemies.GameUpdate();
        Physics.SyncTransforms();
        board.GameUpdate();
        nonEnemies.GameUpdate();
    }
예제 #2
0
파일: Game.cs 프로젝트: BVaflick/gemtd
    void Update()
    {
        handleInput();
        if (playerHealth <= 0)
        {
            Debug.Log("Defeat!");
            BeginNewGame();
        }

        if (scenarioIsInProgress && !activeScenario.Progress() && enemies.IsEmpty)
        {
            Debug.Log("Victory!");
            BeginNewGame();
        }
        else if (scenarioIsInProgress && !activeScenario.WaveIsInProgress() && enemies.IsEmpty)
        {
            if (!isBuildPhase)
            {
                isBuildPhase    = true;
                availableBuilds = 5;
            }
        }

        nonEnemies.GameUpdate();
        enemies.GameUpdate();
        Physics.SyncTransforms();
        board.GameUpdate();
    }
예제 #3
0
    void Update()
    {
        if (Input.GetMouseButtonDown(0))
        {
            HandleTouch();
        }
        else if (Input.GetMouseButtonDown(1))
        {
            HandleAlternativeTouch();
        }

        if (Input.GetKeyDown(KeyCode.V))
        {
            board.ShowPaths = !board.ShowPaths;
        }

        if (Input.GetKeyDown(KeyCode.Alpha1))
        {
            selectedTowerType = TowerType.Laser;
        }
        else if (Input.GetKeyDown(KeyCode.Alpha2))
        {
            selectedTowerType = TowerType.Mortar;
        }

        if (Input.GetKeyDown(KeyCode.Space))
        {
            // "espaço" pausa o jogo
            Time.timeScale = Time.timeScale > pausedTimeScale ? pausedTimeScale : 1f;
        }
        else if (Time.timeScale > pausedTimeScale)
        {
            Time.timeScale = playSpeed;
        }

        if (Input.GetKeyDown(KeyCode.B))
        {
            // "b" começa um novo jogo
            playerHealth = startingPlayerHealth;
            BeginNewGame();
        }
        if (playerHealth <= 0 && startingPlayerHealth > 0)
        {
            // sem vida = fim de jogo
            Debug.Log("Derrota!");
            BeginNewGame();
        }
        if (!activeScenario.Progress() && enemies.IsEmpty)
        {
            // cenário acabou e não existem inimigos = vitória
            Debug.Log("Vitoria!");
            BeginNewGame();
            activeScenario.Progress();
        }

        activeScenario.Progress();

        enemies.GameUpdate();
        Physics.SyncTransforms();
        board.GameUpdate();
        nonEnemies.GameUpdate();
    }
예제 #4
0
    void Update()
    {
        if (Input.GetMouseButtonDown(0))
        {
            HandleTouch();
        }
        else if (Input.GetMouseButtonDown(1))
        {
            HandleAlternativeTouch();
        }
        if (Input.GetKeyDown(KeyCode.V))
        {
            board.ShowPaths = !board.ShowPaths;
        }
        if (Input.GetKeyDown(KeyCode.G))
        {
            board.ShowGrid = !board.ShowGrid;
        }
        if (Input.GetKeyDown(KeyCode.Alpha1))
        {
            selectedTowerType = TowerType.Laser;
        }
        else if (Input.GetKeyDown(KeyCode.Alpha2))
        {
            selectedTowerType = TowerType.Mortar;
        }
        if (Input.GetKeyDown(KeyCode.B))
        {
            BeginNewGame();
        }
        if (Input.GetKeyDown(KeyCode.Space))
        {
            Time.timeScale =
                Time.timeScale > pausedTimeScale ? pausedTimeScale : playSpeed;
        }
        else if (Time.timeScale != pausedTimeScale)
        {
            Time.timeScale = playSpeed;
        }
        if (playerHealth <= 0 && startingPlayerHealth > 0)
        {
            Debug.Log("Defeat!");
            if (!defeatCoroutineIsExecuted)
            {
                StartCoroutine(Defeat());
            }
        }
        if (gameIsPlaying)
        {
            if (!activeScenario.Progress() && enemies.IsEmpty)
            {
                Debug.Log("Round won!");
                StartCoroutine(Victory());
            }
        }

        enemies.GameUpdate();
        Physics.SyncTransforms();
        board.GameUpdate();
        nonEnemies.GameUpdate();
    }
예제 #5
0
    void Update()
    {
        if (Input.GetMouseButtonDown(0))
        {
            HandleTouch();
        }
        else if (Input.GetMouseButtonDown(1))
        {
            HandleAlternativeTouch();
        }

        if (Input.GetKeyDown(KeyCode.V))
        {
            board.ShowPaths = !board.ShowPaths;
        }

        if (Input.GetKeyDown(KeyCode.G))
        {
            board.ShowGrid = !board.ShowGrid;
        }

        if (Input.GetKeyDown(KeyCode.Space))
        {
            Time.timeScale = Time.timeScale > pausedTimeScale ? pausedTimeScale : playSpeed;
        }
        else if (Time.deltaTime > pausedTimeScale)
        {
            Time.timeScale = playSpeed;
        }

        if (Input.GetKeyDown(KeyCode.B))
        {
            BeginNewGame();
        }

        if (Input.GetKeyDown(KeyCode.Alpha1))
        {
            selectedTowerType = TowerType.Laser;
        }
        else if (Input.GetKeyDown(KeyCode.Alpha2))
        {
            selectedTowerType = TowerType.Mortar;
        }

        // spawnProgress += spawnSpeed * Time.deltaTime;
        // while (spawnProgress >= 1f)
        // {
        //     spawnProgress -= 1f;
        //     SpawnEnemy();
        // }

        if (palyerHealth <= 0 && startingPlayerHealth > 0)
        {
            Debug.Log("Defate!");
            BeginNewGame();
        }

        if (!activeScenario.Progress() && enemies.IsEmpty)
        {
            Debug.Log("Victory!");
            BeginNewGame();
            activeScenario.Progress();
        }

        activeScenario.Progress();

        enemies.GameUpdate();

        board.GameUpdate();

        noEnemies.GameUpdate();
    }
예제 #6
0
    // checks if mouse was clicked
    void Update()
    {
        if (Input.GetMouseButtonDown(0))
        {
            HandleTouch();
        }
        else if (Input.GetMouseButtonDown(1))
        {
            HandleAlternativeTouch();
        }

        // toggles visualization arrows on 'V' key
        if (Input.GetKeyDown(KeyCode.V))
        {
            board.ShowPaths = !board.ShowPaths;
        }

        // toggles grid on 'G' key
        if (Input.GetKeyDown(KeyCode.G))
        {
            board.ShowGrid = !board.ShowGrid;
        }

        // Switches to laser towers on '1'
        if (Input.GetKeyDown(KeyCode.Alpha1))
        {
            selectedTowerType = TowerType.Laser;
        }
        // Switches to mortar towers on '2'
        else if (Input.GetKeyDown(KeyCode.Alpha2))
        {
            selectedTowerType = TowerType.Mortar;
        }

        if (playerHealth <= 0 && startingPlayerHealth > 0)
        {
            Debug.Log("Defeat!");
            BeginNewGame();
        }

        if (!activeScenario.Progress() && enemies.IsEmpty)
        {
            Debug.Log("Victory!");
            BeginNewGame();
            activeScenario.Progress();
        }

        enemies.GameUpdate();
        Physics.SyncTransforms();
        board.GameUpdate();
        nonEnemies.GameUpdate();

        // pauses game on 'space' press
        if (Input.GetKeyDown(KeyCode.Space))
        {
            Time.timeScale = Time.timeScale > pausedTimeScale ? pausedTimeScale : playSpeed;
        }
        else if (Time.timeScale > pausedTimeScale)
        {
            Time.timeScale = playSpeed;
        }

        // starts a new game on 'b' press
        if (Input.GetKeyDown(KeyCode.B))
        {
            BeginNewGame();
        }
    }
예제 #7
0
파일: Game.cs 프로젝트: nzhul/Unity
    private void Update()
    {
        if (Input.GetMouseButtonDown(0))
        {
            HandleTouch();
        }
        else if (Input.GetMouseButtonDown(1))
        {
            HandleAlternativeTouch();
        }

        if (Input.GetKeyDown(KeyCode.V))
        {
            board.ShowPaths = !board.ShowPaths;
        }

        if (Input.GetKeyDown(KeyCode.G))
        {
            board.ShowGrid = !board.ShowGrid;
        }

        if (Input.GetKeyDown(KeyCode.Alpha1))
        {
            selectedTowerType = TowerType.Laser;
        }
        else if (Input.GetKeyDown(KeyCode.Alpha2))
        {
            selectedTowerType = TowerType.Mortar;
        }

        if (Input.GetKeyDown(KeyCode.B))
        {
            BeginNewGame();
        }

        if (Input.GetKeyDown(KeyCode.Space))
        {
            Time.timeScale = Time.timeScale > pausedTimeScale ? pausedTimeScale : 1f;
        }
        else if (Time.timeScale > pausedTimeScale)
        {
            Time.timeScale = playSpeed;
        }

        if (playerHealth <= 0 && startingPlayerHealth > 0)
        {
            Debug.Log("Defeat!");
            BeginNewGame();
        }

        if (!activeScenario.Progress() && enemies.IsEmpty)
        {
            Debug.Log("Victory!");
            BeginNewGame();
            activeScenario.Progress();
        }

        activeScenario.Progress();

        enemies.GameUpdate();
        ///All seems to work fine, except towers that can target the center of the board are able to acquire targets that should be out of range.
        ///They will fail to track those targets, so they only lock on for a single frame per target.
        ///This happens because the state of the physics engine is not perfectly synchronized with our game state.
        ///All enemies are instantiated at the world origin, which coincides with the center of the board.
        ///We then move them to their spawn point, but the physics engine isn't immediately aware of that.
        Physics.SyncTransforms();
        board.GameUpdate();
        nonEnemies.GameUpdate();
    }
예제 #8
0
    private void Update()
    {
        if (Input.GetMouseButtonDown(0))
        {
            HandleTouch();
        }
        else if (Input.GetMouseButtonDown(1))
        {
            HandleAlternaiveTouch();
        }

        if (Input.GetKeyDown(KeyCode.V))
        {
            board.ShowPaths = !board.ShowPaths;
        }
        if (Input.GetKeyDown(KeyCode.G))
        {
            board.ShowGrid = !board.ShowGrid;
        }

        if (Input.GetKeyDown(KeyCode.Alpha1))
        {
            selectedTowerType = TowerType.Laser;
        }
        else if (Input.GetKeyDown(KeyCode.Alpha2))
        {
            selectedTowerType = TowerType.Mortar;
        }

        if (Input.GetKeyDown(KeyCode.Space))
        {
            Time.timeScale =
                Time.timeScale > pausedTimeScale ? pausedTimeScale : playSpeed;
        }
        else if (Time.timeScale > pausedTimeScale)
        {
            Time.timeScale = playSpeed;
        }

        if (Input.GetKeyDown(KeyCode.B))
        {
            BeginNewGame();
        }

        if (playerHealth <= 0 && startingPlayerHealth > 0)
        {
            Debug.Log("Defeat!");
            BeginNewGame();
        }

        if (!activeScenario.Progress() && enemies.IsEmpty)
        {
            Debug.Log("Victory!");
            BeginNewGame();
            activeScenario.Progress();
        }

        enemies.GameUpdate();
        // 这里是为了解决Enemy是在场景中心创建然后再移动出生点的,但物理引擎有可能会在塔的检测里查询到这个Enemy
        // 这里在更新前强制更新下物理引擎里的Transform
        Physics.SyncTransforms();
        board.GameUpdate();
        nonEnemies.GameUpdate();
    }