Exemplo n.º 1
0
    void Update()
    {
        //Nicely move the caracter
        Vector3 position = transform.position;

        if (mTargetPosition != position.x)
        {
            mMovementTime     += GameLogic.GameDeltaTime * GameLogic.PlayerSpeed;
            position.x         = Mathf.SmoothStep(mStartPosition, mTargetPosition, mMovementTime);
            transform.position = position;
        }

        //Search for powerups
        int CollectedPowerup = PowerupFactory.DetectCollisions(transform.position);

        if (CollectedPowerup >= 0)
        {
            Inventory[CollectedPowerup]++;
            TriggerTutorial(16);
        }
    }
Exemplo n.º 2
0
    void Update()
    {
        GameDeltaTime = Paused ? 0.0f : Time.deltaTime;

        if (mGameStatus == State.Level)
        {
            mDistanceTravelled += ScenerySpeed * GameDeltaTime;
            if (mDistanceTravelled != 0f)
            {
                UpdateText(string.Format("Distance: {0:0.0} m", mDistanceTravelled));
            }

            mLevelTimeLeft -= GameDeltaTime;

            if (!GameFrozen)
            {
                if (mLevelTimeLeft > 0f)
                {
                    //Get a bit pattern and spawn enemies according to it
                    int enemies = mCurrentDifficulty.SpawnPattern();
                    for (int ColumnCount = 0; ColumnCount < 3; ColumnCount++)
                    {
                        if ((enemies & (1 << ColumnCount)) != 0)
                        {
                            EnemyFactory.Dispatch((EnemyFactory.Column)ColumnCount);
                        }
                    }

                    PowerupFactory.DetectCollisions(mPlayerCharacter.transform.position);
                }
                else if (mActiveEnemies.Count == 0)
                {
                    switch (SlowDownStage)
                    {
                    case 0:     //We are just now starting to slow down
                        mCurrentDifficulty.SlowDown();
                        break;

                    //For case 1 - slowing down in progress - nothing is to be done
                    case 2:     //Slowing down has finished; switch to boss state
                        mGameStatus = State.Boss;
                        boss        = new Boss(GameplayCamera, EnemyMaterial);
                        mCurrentDifficulty.TriggerTutorial(11);
                        break;
                    }

                    //At this point, we know there are no enemies to check, so it is OK to skip the loop below
                    return;
                }
            }

            /* Traverse the list descendingly so that removals of already visited elements does not affect the
             * elements yet to be visited.
             */
            for (int count = mActiveEnemies.Count - 1; count >= 0; count--)
            {
                Vector3 ThisPosition = mActiveEnemies[count].transform.position;

                //Update each enemy's position according to the game speed
                ThisPosition.y -= GameDeltaTime * EnemySpeed;
                mActiveEnemies[count].transform.position = ThisPosition;

                //Check if the enemy has flown off screen. If so, return it to the factory and count it as missed.
                if (ThisPosition.y < ScreenHeight * -0.5f)
                {
                    EnemyFactory.Return(mActiveEnemies[count]);
                    mMissedEnemies++;
                }

                //Check if the enemy is too close to the player. If so, end the game.
                else if ((mPlayerCharacter.transform.position - ThisPosition).sqrMagnitude < PlayerKillDistance)
                {
                    GameOver("You died!");
                }

                //Check if the enemy has been hit by a bullet
                else
                {
                    for (int bullet = 0; bullet < mPlayerCharacter.Weapon.ActiveBullets.Count; bullet++)
                    {
                        if (mPlayerCharacter.Weapon.ActiveBullets[bullet].CheckHit(ThisPosition, BulletKillDistance, false))
                        {
                            EnemyFactory.Return(mActiveEnemies[count]);
                            break;
                        }
                    }
                }
            }

            //Check if the player has been "invaded" (too many enemies were missed
            if (mMissedEnemies >= MaxMissedEnemies)
            {
                GameOver("You have been invaded!");
            }
        }

        else if (mGameStatus == State.Boss)
        {
            if (boss != null)
            {
                //Only if the boss is allowed to move
                if (!GameFrozen)
                {
                    //Move and rotate boss to point to player's position
                    boss.Update(mPlayerCharacter.transform.position);

                    //Check if boss has eaten the player and if so end the game
                    if (boss.HasEaten(mPlayerCharacter.transform.position))
                    {
                        GameOver("You have been eaten!");
                    }
                }

                //Check wether boss was hit by a bullet
                foreach (Bullet bullet in mPlayerCharacter.Weapon.ActiveBullets)
                {
                    if (bullet.CheckHit(boss.Position(), BossHitDistance, true))
                    {
                        if (boss.Hit(bullet.DamageValue))
                        {
                            boss = null;
                            mCurrentDifficulty.TriggerTutorial(13);
                        }
                        break;
                    }
                }
            }

            //No more boss, transitioning to normal
            else
            {
                mDistanceTravelled += ScenerySpeed * GameDeltaTime;
                UpdateText(string.Format("Distance: {0:0.0} m", mDistanceTravelled));

                if (mCurrentDifficulty.LevelUp())
                {
                    mGameStatus    = State.Level;
                    mMissedEnemies = 0;
                    mLevelTimeLeft = DifficultyCurve.LevelDuration;
                }
            }
        }

        else if (mGameStatus == State.TapToStart)
        {
            mCurrentDifficulty.TriggerTutorial(1);
            if (mCurrentDifficulty.TutorialStage != 0)
            {
                mGameStatus = State.Level;
            }
            else
            {
                GameText.text = "Tap the screen or press W to start";
            }
        }
    }