Esempio n. 1
0
    // Update is called once per frame
    void Update()
    {
        //UpdateFields();

        for (int i = 1; i <= 4; i++)
        {
            if (XCI.GetButtonDown(XboxButton.A, (XboxController)i))
            {
                if (finishedDisplaying)
                {
                    if (gm.gameMode == GameManager.GameMode.Deathmatch || gm.lastRoundWinner.roundsWon > 2)
                    {
                        gm.EndGame();
                        gameObject.SetActive(false);
                    }
                    else
                    {
                        gameObject.SetActive(false);
                        gm.StartRound();
                    }
                }
                else
                {
                    actualStampDelay    = 0.0f;
                    actualStampInterval = 0.0f;
                    soundsPlayed        = 100000;
                    finishedDisplaying  = true;
                    if (killStampSound != null)
                    {
                        killStampSound.PlayEffect();
                    }
                }
            }
        }
    }
Esempio n. 2
0
    public IEnumerator OpenAndWait(float duration)
    {
        SetVisible(true);
        //DebugLogger.Log("Opening");
        if (isResizing)
        {
            DebugLogger.Log("OpenAndWait::StopCoroutine:" + gameObject.name);
            StopCoroutine(currentResize);
            StopCoroutine(currentHorizontalResize);
            StopCoroutine(currentVerticalResize);
        }

        if (duckMusicOnOpen)
        {
            AudioManager.Instance.DuckMusic();
        }

        if (openSound != null && playSound)
        {
            openSound.PlayEffect();
        }

        currentResize = Resize(closedSize, openSize, duration, openStyle);
        yield return(StartCoroutine(currentResize));

        isOpen = true;
        EnableChildren(true);

        if (openedSound != null && playOpenedSound && playSound)
        {
            openedSound.PlayEffect();
        }
    }
Esempio n. 3
0
    public IEnumerator CloseAndWait(float duration)
    {
        //DebugLogger.Log("Closing");
        isOpen = false;
        EnableChildren(false);

        if (isResizing)
        {
            DebugLogger.Log("CloseAndWait::StopCoroutine:" + gameObject.name);
            StopCoroutine(currentResize);
            StopCoroutine(currentHorizontalResize);
            StopCoroutine(currentVerticalResize);
        }

        if (unduckMusicOnClose)
        {
            AudioManager.Instance.UnduckMusic();
        }

        if (closeSound != null && playSound)
        {
            closeSound.PlayEffect();
        }

        currentResize = Resize(openSize, closedSize, duration, closeStyle);
        yield return(StartCoroutine(currentResize));

        if (!visibleWhileClosed)
        {
            SetVisible(false);
        }
    }
Esempio n. 4
0
    public void Cancel()
    {
        if (state == PlayerSelectorState.Joined)
        {
            if (joinedCancelSound != null)
            {
                joinedCancelSound.PlayEffect();
            }
            state = PlayerSelectorState.NameEntry;
            nameEntry.gameObject.SetActive(true);
            nameEntry.DisplayTextEntry();

            readyText.SetActive(false);

            if (playerStatus != null)
            {
                playerStatus.text = "A: Confirm     B: Cancel\r\nY: Random Name";
            }

            Globals.Instance.GameManager.RemovePlayer(pInfo);
        }
        else if (state == PlayerSelectorState.NameEntry)
        {
            if (cancelSound != null)
            {
                cancelSound.PlayEffect();
            }
            Reset();
        }
    }
Esempio n. 5
0
    public virtual IEnumerator DoAttack()
    {
        attackComplete = false;
        isAttacking    = true;

        actualDamage = baseDamage + bonusDamage;

        if (attackerAnimator != null)
        {
            attackerAnimator.SetBool(ANIM_PARAM_ATTACKING, true);
        }

        if (attackSound != null)
        {
            attackSound.PlayEffect();
        }

        doDealDamage           = true;
        weaponCollider.enabled = true;

        yield return(new WaitForSeconds(attackDuration));

        doDealDamage           = false;
        weaponCollider.enabled = false;

        if (attackerAnimator != null)
        {
            attackerAnimator.SetBool(ANIM_PARAM_ATTACKING, false);
        }

        attackComplete = true;
        isAttacking    = false;

        gameObject.SetActive(false);
    }
Esempio n. 6
0
 public override void ActivateEffect(GameObject activator, float value, Collision2D coll, Collider2D other)
 {
     if (soundEffect != null)
     {
         soundEffect.PlayEffect();
     }
 }
Esempio n. 7
0
    public void Pause(bool pause)
    {
        return; //disable pause

        if (isQuitting)
        {
            return;
        }

        paused = pause;

        if (paused)
        {
            if (pauseSound != null)
            {
                pauseSound.PlayEffect();
            }
            Time.timeScale        = 0.0f;
            acceptPlayerGameInput = false;
            pauseScreenUI.SetActive(true);
        }
        else
        {
            if (unpauseSound != null)
            {
                unpauseSound.PlayEffect();
            }
            Time.timeScale        = 1.0f;
            acceptPlayerGameInput = true;
            pauseScreenUI.SetActive(false);
        }
    }
Esempio n. 8
0
    public void Shoot()
    {
        if (Time.time > lastShot + shootInterval)
        {
            GameObject bullet = GameObject.Instantiate(projectilePrefab, transform.position, Quaternion.identity);

            bullet.transform.parent = transform;

            bullet.transform.localPosition = spawnOffset;

            bullet.transform.parent = Globals.Instance.dynamicsParent;

            Bullet bulletScript = bullet.GetComponent <Bullet>();
            bulletScript.shooter = shooter;

            Rigidbody2D bulletRB = bullet.GetComponent <Rigidbody2D>();

            bulletRB.AddForce(transform.up * shootForce, ForceMode2D.Impulse);

            GameObject.Destroy(bullet, 5.0f);

            if (shootSound != null)
            {
                shootSound.PlayEffect();
            }

            lastShot = Time.time;
        }
    }
Esempio n. 9
0
 public void StartGame()
 {
     if (gameStartSound != null)
     {
         gameStartSound.PlayEffect();
     }
     StartCoroutine(DoStartGame());
 }
Esempio n. 10
0
    public void StartGame()
    {
        if (mute)
        {
            Camera.main.GetComponent <AudioListener>().enabled = false;
        }

        if (gameStartSound != null)
        {
            gameStartSound.PlayEffect();
        }
        StartCoroutine(DoStartGame());
    }
Esempio n. 11
0
    public bool Hit(int hitBy)
    {
        bool killed = false;

        if (invulnerable)
        {
            return(false);
        }

        if (invincibleTimeLeft == 0)
        {
            //Debug.Log("Preparing to shake " + playerInfo.playerNum);

            invincibleTimeLeft = invincibleTime;

            StartCoroutine(HandleInvincibility());

            shipHitSound.PlayEffect();

            playerHealth--;

            if (playerHealth < 1)
            {
                Kill(hitBy);
                killed = true;
            }
            else if (playerHealth == 2)
            {
                ParticleSystem.MainModule main = shield.main;
                main.simulationSpeed = 3.0f;
                shieldHitSound.PlayEffect();
            }
            else if (playerHealth == 1)
            {
                StartCoroutine(DestroyShield());
            }

            if (playerHealth > 0)
            {
                //killed player portrait updates are handled in Kill()
                portraitShaker.Shake();
                portrait.TakeDamage();
                Globals.Instance.GameManager.characterSounds.PlayVoice(CharacterSoundManager.VoiceType.Grunt, playerInfo.playerNum, false);
            }
        }

        return(killed);
    }
Esempio n. 12
0
    public void Kill(int killedBy)
    {
        portraitShaker.Shake();
        portrait.TakeDamage();

        shipExplodeSound.PlayEffect();

        if (killedBy > 0)
        {
            int rand = UnityEngine.Random.Range(0, 3);
            if (rand == 0)
            {
                Globals.Instance.GameManager.characterSounds.PlayVoice(CharacterSoundManager.VoiceType.Death, playerInfo.playerNum, false);
            }
            else if (rand == 1)
            {
                Globals.Instance.GameManager.characterSounds.PlayVoice(CharacterSoundManager.VoiceType.Grunt, playerInfo.playerNum, false);
            }
            else if (rand == 2)
            {
                Globals.Instance.GameManager.characterSounds.PlayVoice(CharacterSoundManager.VoiceType.Laugh, killedBy, false);
            }
        }

        GameObject explosion = GameObject.Instantiate(playerExplosion, transform.position, Quaternion.identity, Globals.Instance.dynamicsParent);

        ParticleSystem explosionPS = explosion.GetComponent <ParticleSystem>();

        var main = explosionPS.main;

        main.startColor = Globals.Instance.GameManager.GetPlayerColor(playerInfo.playerNum);

        Destroy(gameObject);

        if (Globals.Instance.GameManager.gameMode == GameManager.GameMode.Survival)
        {
            ParticleSystem ps = playerRing.GetComponent <ParticleSystem>();
            ps.Stop();
            Destroy(playerRing, 5.0f);
        }

        Destroy(explosion, 5.0f);

        Globals.Instance.GameManager.KillPlayer(playerInfo.playerNum);
    }
Esempio n. 13
0
    public void OnCollisionEnter2D(Collision2D coll)
    {
        Collider2D other = coll.collider;

        Lootable lootable = other.gameObject.GetComponent <Lootable>();

        if (lootable != null && monsterLoot != null)
        {
            monsterLoot.carrying.Add(lootable.gameObject);
            lootable.transform.parent = monsterLoot.transform;
            lootable.gameObject.SetActive(false);

            if (lootSound != null)
            {
                lootSound.PlayEffect();
            }
        }
    }
Esempio n. 14
0
    public void Confirm()
    {
        if (state == PlayerSelectorState.Unjoined)
        {
            if (confirmSound != null)
            {
                confirmSound.PlayEffect();
            }
            state = PlayerSelectorState.NameEntry;
            nameEntry.gameObject.SetActive(true);
            nameEntry.DisplayTextEntry();

            if (playerStatus != null)
            {
                playerStatus.text = "A: Confirm     B: Cancel\r\nY: Random Name";
            }
        }
        else if (state == PlayerSelectorState.NameEntry)
        {
            if (joinedConfirmSound != null)
            {
                joinedConfirmSound.PlayEffect();
            }
            state = PlayerSelectorState.Joined;
            nameEntry.DisplayName();

            readyText.SetActive(true);

            pInfo.name = nameEntry.GetName();

            Globals.Instance.GameManager.AddPlayer(pInfo);

            if (playerStatus != null)
            {
                playerStatus.text = "Joined!\r\nPress B to cancel...";
            }
        }
    }
Esempio n. 15
0
    IEnumerator DestroyShield()
    {
        shieldFadeSound.PlayEffect();
        shield.gameObject.SetActive(false);
        GameObject     destShield   = GameObject.Instantiate(destShieldPrefab, gameObject.transform);
        SpriteRenderer shieldSprite = destShield.GetComponentInChildren <SpriteRenderer>();
        bool           isFading     = true;

        while (isFading)
        {
            Color newColor = shieldSprite.color;
            newColor.a        -= 0.05f;
            isFading           = newColor.a > 0;
            shieldSprite.color = newColor;

            yield return(new WaitForSecondsRealtime(0.2f));
        }

        //Wait a bit to allow the particle effect to fade
        yield return(new WaitForSecondsRealtime(2.0f));

        Destroy(destShield);
    }
Esempio n. 16
0
    IEnumerator WaitThenPlay(SoundEffectHandler sound, float waitTime)
    {
        yield return(new WaitForSeconds(waitTime));

        sound.PlayEffect();
    }
Esempio n. 17
0
    // Update is called once per frame
    void Update()
    {
        //if (playerJoined && !Globals.Instance.GameManager.joinedPlayers.Contains(playerNum))
        //{
        //    Leave();
        //}
        if (state == PlayerSelectorState.NameEntry)
        {
            float horizontal = XCI.GetAxisRaw(XboxAxis.LeftStickX, controller);
            float vertical   = XCI.GetAxisRaw(XboxAxis.LeftStickY, controller);

            bool usingStick = false;

            if (Mathf.Abs(horizontal) > 0.8f)
            {
                usingStick = true;
                if (canMoveCursor)
                {
                    nameEntry.MoveCursor(horizontal > 0);
                    canMoveCursor = false;
                    if (moveCursorSound != null)
                    {
                        moveCursorSound.PlayEffect();
                    }
                }
            }
            else
            {
                canMoveCursor = true; //reset moving the cursor each time the user stops pushing a direction
            }

            if (Mathf.Abs(vertical) > 0.3)
            {
                usingStick         = true;
                letterChangeValue += (vertical * Time.deltaTime * nameEntrySensitivity);

                if (vertical > 0 && letterChangeValue > letterChangeThreshold)
                {
                    //move up one letter
                    nameEntry.ChangeLetter(true);
                    letterChangeValue = 0.0f;
                    if (changeLetterNextSound != null)
                    {
                        changeLetterNextSound.PlayEffect();
                    }
                }
                else if (vertical < 0 && letterChangeValue < (letterChangeThreshold * -1))
                {
                    //move down one letter
                    nameEntry.ChangeLetter(false);
                    letterChangeValue = 0.0f;
                    if (changeLetterPrevSound != null)
                    {
                        changeLetterPrevSound.PlayEffect();
                    }
                }
            }
            else
            {
                //letterChangeValue = 0.0f;
            }

            if (!usingStick)
            {
                if (XCI.GetButtonDown(XboxButton.DPadRight, controller))
                {
                    nameEntry.MoveCursor(true);
                    if (moveCursorSound != null)
                    {
                        moveCursorSound.PlayEffect();
                    }
                }
                else if (XCI.GetButtonDown(XboxButton.DPadLeft, controller))
                {
                    nameEntry.MoveCursor(false);
                    if (moveCursorSound != null)
                    {
                        moveCursorSound.PlayEffect();
                    }
                }

                if (XCI.GetButtonDown(XboxButton.DPadUp, controller))
                {
                    nameEntry.ChangeLetter(true);
                    if (changeLetterNextSound != null)
                    {
                        changeLetterNextSound.PlayEffect();
                    }
                }
                else if (XCI.GetButtonDown(XboxButton.DPadDown, controller))
                {
                    nameEntry.ChangeLetter(false);
                    if (changeLetterPrevSound != null)
                    {
                        changeLetterPrevSound.PlayEffect();
                    }
                }
            }

            if (XCI.GetButtonDown(XboxButton.Y, controller))
            {
                nameEntry.SetRandomName();
                if (randomNameSound != null)
                {
                    randomNameSound.PlayEffect();
                }
            }
        }

        if (XCI.GetButtonDown(XboxButton.A, controller))
        {
            Confirm();
        }

        if (XCI.GetButtonDown(XboxButton.B, controller))
        {
            Cancel();
        }

        if (XCI.GetButtonDown(XboxButton.Start, controller))
        {
            if (state == PlayerSelectorState.Joined && Globals.Instance.GameManager.isRoundReady)
            {
                //start game!
                Globals.Instance.GameManager.StartRound();
            }
        }
    }
Esempio n. 18
0
    public void StartRound()
    {
        isRoundReady = false;

        playerSelect.gameObject.SetActive(false);

        if (newGame && showHowToPlay)
        {
            newGame = false;
            howToPlayScreen.SetActive(true);
            isShowingHowToPlay = true;
            welcomeToSound.PlayEffect();
            canDismissTutorialTime = Time.time + tutorialMinDisplayTime;
            return;
        }

        blackHoleBulletSound.PlayEffect();

        isRoundActive = true;
        allowRespawn  = true;

        joinedPlayers = joinedPlayers.Where(p => p.playerNum > 0).OrderBy(p => p.playerNum).ToList();

        numPlayers = joinedPlayers.Count;

        for (int i = 0; i < numPlayers; i++)
        {
            SpawnPlayer(joinedPlayers[i], i + 1);
            playerPortraits[joinedPlayers[i].playerNum - 1].transform.parent.gameObject.SetActive(true);
            playerPortraits[joinedPlayers[i].playerNum - 1].SlideIn();
        }

        switch (numPlayers)
        {
        case 2:
            //shields enabled
            //kill goal = 5
            break;

        case 3:
            //shields disabled
            //kill goal = 10
            break;

        case 4:
            //shields disabled
            //kill goal = 10
            break;

        default:
            break;
        }

        if (numPlayers == 4)
        {
            //swap 3 and 4 positions to read left->right instead of clockwise around a circle
            livingPlayers[2].playerPosition = 4;
            livingPlayers[3].playerPosition = 3;
        }

        if (showPrompts && gameMode == GameMode.Deathmatch)
        {
            foreach (PlayerInput pi in livingPlayers)
            {
                pi.canShoot = false;
            }
            deathMatchPrompt.gameObject.SetActive(true);
            deathMatchPrompt.Display();
        }
    }
Esempio n. 19
0
 public void EndGame()
 {
     CleanupGame();
     victory.gameObject.SetActive(true);
     endGameSound.PlayEffect();
 }
Esempio n. 20
0
    // Update is called once per frame
    void Update()
    {
        if (isRoundActive)
        {
            if (CheckForExitInput((XboxController)1))
            {
                SetupGame();
            }
            else
            {
                //still playing
                if (gameMode == GameMode.Survival)
                {
                    if (livingPlayers.Count == 1)
                    {
                        livingPlayers[0].invulnerable = true;
                        lastRoundWinner = livingPlayers[0].playerInfo;
                        lastRoundWinner.roundsWon++;
                        StartCoroutine(EndRound());
                    }
                    else if (livingPlayers.Count == 0)
                    {
                        lastRoundWinner = null;
                        StartCoroutine(EndRound());
                    }
                }
                else if (gameMode == GameMode.Deathmatch)
                {
                    List <int> winners = kills.Where(kvp => kvp.Value.Count() >= killGoal).Select(kvp => kvp.Key).ToList();

                    int winnerCount = winners.Count;
                    if (winnerCount > 0)
                    {
                        //todo: what if we have more than one winner - increase the kill goal?
                        //for now, just pick the first index
                        if (winnerCount == 1)
                        {
                            //we have a winner!
                            int winner = winners[0];
                            //get playerInfo for winner and increase rounds won, set lastRoundWinner
                            PlayerInfo pi = joinedPlayers.First(p => p.playerNum == winner);

                            lastRoundWinner = pi;
                            lastRoundWinner.roundsWon++;

                            List <PlayerInput> killPlayers = new List <PlayerInput>();

                            foreach (PlayerInput player in livingPlayers)
                            {
                                if (player.playerInfo.playerNum == winner)
                                {
                                    player.invulnerable = true;
                                }
                                else
                                {
                                    killPlayers.Add(player);
                                }
                            }

                            foreach (PlayerInput player in killPlayers)
                            {
                                player.Kill(0);
                            }

                            //stop respawning of players
                            allowRespawn = false;

                            //end round
                            StartCoroutine(EndRound());
                        }
                        else
                        {
                            int        highestKills = kills.Max(kvp => kvp.Value.Count());
                            List <int> mostKills    = kills.Where(kvp => kvp.Value.Count() == highestKills).Select(kvp => kvp.Key).ToList();

                            if (mostKills.Count == 1)
                            {
                                //winner!
                                int winner = mostKills[0];

                                PlayerInfo pi = joinedPlayers.First(p => p.playerNum == winner);

                                lastRoundWinner = pi;
                                lastRoundWinner.roundsWon++;

                                List <PlayerInput> killPlayers = new List <PlayerInput>();

                                foreach (PlayerInput player in livingPlayers)
                                {
                                    if (player.playerInfo.playerNum == winner)
                                    {
                                        player.invulnerable = true;
                                    }
                                    else
                                    {
                                        killPlayers.Add(player);
                                    }
                                }

                                foreach (PlayerInput player in killPlayers)
                                {
                                    player.Kill(0);
                                }

                                //stop respawning of players
                                allowRespawn = false;

                                //end round
                                StartCoroutine(EndRound());
                            }
                        }
                    }
                }
            }
        }
        else
        {
            if (CheckForExitInput((XboxController)1))
            {
                Globals.Instance.DoQuit();
            }

            if (isShowingHowToPlay)
            {
                if (Input.anyKeyDown && Time.time > canDismissTutorialTime)
                {
                    howToPlayScreen.SetActive(false);
                    isShowingHowToPlay = false;
                    newGame            = false;
                    StartRound();
                }
            }

            //if (isRoundReady && Input.anyKeyDown)
            //{
            //    StartRound();
            //}
        }

        //if (Input.GetKeyDown(KeyCode.S))
        //{
        //    enableShields = !enableShields;
        //}

        if (Input.GetKeyDown(KeyCode.T))
        {
            showHowToPlay = !showHowToPlay;
            if (showHowToPlay)
            {
                startRoundSound.PlayEffect();
            }
            else
            {
                endRoundSound.PlayEffect();
            }
        }

        //if (Input.GetKeyDown(KeyCode.P))
        //{
        //    showPrompts = !showPrompts;
        //}

        //if (Input.GetKeyDown(KeyCode.M))
        //{
        //    if (gameMode == GameMode.Survival)
        //    {
        //        gameMode = GameMode.Deathmatch;
        //    }
        //    else
        //    {
        //        gameMode = GameMode.Survival;
        //    }
        //}
    }