コード例 #1
0
    private IEnumerator ChessBoardInitiate(GameObject board, float initialSize, float finalSize, float time, float speedUp)
    {
        var animator = chessBoard.GetComponent <Animator>();

        animator.Play("Drop");

        var clipInfo = animator.GetCurrentAnimatorClipInfo(0);

        yield return(new WaitForSeconds(clipInfo[0].clip.length * 0.4f * initiateTimeMultiplier));

        AudioManager.Instance.PlaySFX("whoosh", 0.45f);
        yield return(new WaitForSeconds(clipInfo[0].clip.length * 0.6f * initiateTimeMultiplier));

        StartCoroutine(Shake(chessBoard.transform, 0.25f, 0.25f * initiateTimeMultiplier));
        AudioManager.Instance.PlaySFX("impact");

        for (int i = -8; i <= 8; i++)
        {
            for (int j = -8; j <= 8; j++)
            {
                var particle = Instantiate(dust, new Vector3(i * 0.5f, j * 0.5f, 0), Quaternion.identity);
                Destroy(particle.gameObject, particle.GetComponent <ParticleSystem>().main.duration);
            }
        }

        yield return(new WaitForSeconds(0.5f * initiateTimeMultiplier));

        StartCoroutine(GetComponent <ChessManager>().InitiateChess(playerTeam, initiateTimeMultiplier));
        chessBoard.GetComponentInChildren <CanvasGroup>().DOFade(1.0f, 3f * initiateTimeMultiplier);

        //AudioManager.Instance.SetMusicVolume(0.5f);
        //AudioManager.Instance.PlayMusicWithFade("theme", 3f);

        yield return(new WaitForSeconds(3f * initiateTimeMultiplier));

        UICanvas.CharacterMoveIn(0.5f);

        // Enable cursor and assign a team for it
        InitiateCursor(playerCursor, playerTeam);
        playerCursor.GetComponent <Input>().SetControlActive(true);
        InitiateCursor(enemyCursor, playerTeam == Team.White ? Team.Black : Team.White);
        enemyCursor.GetComponent <CursorAIInput>().active = true;

        // white start first
        isPlayerTurn = (playerTeam == Team.Black);
        Turn();
    }
コード例 #2
0
    private IEnumerator Event()
    {
        cursor.GetComponent <SpriteRenderer>().color = new Color32(255, 255, 255, 0);
        TurnManager.instance.gameObject.SetActive(false);
        eventPlayed = true;
        loseManager.gameObject.SetActive(false);
        yield return(new WaitUntil(() => !screenDim.activeSelf));

        yield return(new WaitForSeconds(1f));

        cursor.cursorControls.DeactivateInput();
        //Move Ophelia on screen
        opheliaObject.SetActive(true);
        StartCoroutine(MoveUnit(opheliaObject.GetComponent <UnitLoader>(), new Vector2(2f, 10f)));
        yield return(new WaitUntil(() => opheliaObject.transform.localPosition == new Vector3(2, 10)));

        yield return(new WaitUntil(() => !screenDim.activeSelf));

        MapDialogueManager.instance.ClearDialogue();
        yield return(new WaitForSeconds(0.4f));

        //Turn the music off
        MusicPlayer.instance.PauseTrack();
        //Send dialogue to dialogue manager
        MapDialogueManager.instance.WriteMultiple(opheliaDialogue);
        yield return(new WaitUntil(() => !screenDim.activeSelf));

        //Ophelia attacks Roland
        yield return(new WaitForSeconds(0.5f));

        //Move next to Roland
        StartCoroutine(MoveUnit(opheliaObject.GetComponent <UnitLoader>(), new Vector2(rolandObject.transform.localPosition.x - 1, rolandObject.transform.localPosition.y)));
        yield return(new WaitUntil(() => (Vector2)opheliaObject.transform.localPosition == new Vector2(rolandObject.transform.localPosition.x - 1, rolandObject.transform.localPosition.y)));

        yield return(new WaitForSeconds(0.5f));

        //Attack Roland
        CombatManager.instance.EngageAttack(opheliaObject.GetComponent <UnitLoader>(), rolandObject);
        //Ophelia CG appears and the rest of the dialogue is displayed
        yield return(new WaitForSeconds(2f));

        opheliaCG.SetActive(true);
        yield return(new WaitForSeconds(1f));

        MapDialogueManager.instance.WriteMultiple(opheliaDialogue2);
        yield return(new WaitUntil(() => MapDialogueManager.instance.dialogueFinished));

        thanksForPlaying.SetActive(true);
        yield return(new WaitForSeconds(1f));

        EventSystem.current.SetSelectedGameObject(null);
        yield return(new WaitForEndOfFrame());

        cursor.cursorControls.ActivateInput();
        cursor.cursorControls.SwitchCurrentActionMap("UI");
        EventSystem.current.SetSelectedGameObject(restartButton.gameObject);
    }
コード例 #3
0
ファイル: GameLoop.cs プロジェクト: carraka/ludumdare42
    private void Start()
    {
        cursor       = GetComponentInChildren <CursorController>();
        db           = GameObject.Find("DataBucket").GetComponent <DataBucket>();
        document     = GetComponentInChildren <Document>();
        textBox      = document.GetComponent <Text>();
        clock        = GameObject.Find("Clock").GetComponent <Text>();
        spaceCounter = GameObject.Find("SpaceCounter").GetComponent <Text>();

        BGM = GameObject.Find("BGM").GetComponent <AudioSource>();
        SFX = GameObject.Find("SFX").GetComponent <AudioSource>();

        error = (AudioClip)Resources.Load("SFX/error", typeof(AudioClip));

        //Fetch the Raycaster from the GameObject (the Canvas)
        m_Raycaster = GameObject.Find("BGCanvas").GetComponent <GraphicRaycaster>();
        //Fetch the Event System from the Scene
        m_EventSystem = GameObject.Find("EventSystem").GetComponent <EventSystem>();

        document.SetUpDocument(db.level);

        GUIStyle style = new GUIStyle();

        style.font     = textBox.font;
        style.fontSize = textBox.fontSize;

        Vector2 fontSize = style.CalcSize(new GUIContent("1\n2\n3\n4\n5\n6\n7\n8\n9\n0"));

        fontWidth  = fontSize.x;
        fontHeight = fontSize.y / 10;

        cursor.SetSize(textBox.fontSize, fontWidth, fontHeight);
        cursorLocation = Vector2Int.zero;
        cursor.MoveCursor(cursorLocation);

        RectTransform monitorRect  = GetComponent <RectTransform>();
        RectTransform documentRect = GameObject.Find("Document").GetComponent <RectTransform>();

        screenDocumentLeft = Camera.main.pixelWidth * monitorRect.anchorMin.x +
                             (Camera.main.pixelWidth * (monitorRect.anchorMax.x - monitorRect.anchorMin.x)) * documentRect.anchorMin.x;

        screenDocumentTop = Camera.main.pixelWidth * 0.75f * monitorRect.anchorMax.y -
                            (Camera.main.pixelWidth * 0.75f * (monitorRect.anchorMax.y - monitorRect.anchorMin.y)) * (1 - documentRect.anchorMax.y) -
                            (Camera.main.pixelWidth * 0.75f - Camera.main.pixelHeight) / 2;

        if (db.levelData.data[db.level].difficulty == Difficulty.easy)
        {
            cursor.GetComponent <Image>().enabled                    = false;
            cursor.GetComponentInChildren <Text>().enabled           = false;
            GameObject.Find("Postit").GetComponent <Image>().enabled = false;
            GameObject.Find("memo").GetComponent <Image>().enabled   = false;
        }

        AudioClip music = null;

        switch (Random.Range(0, 3))
        {
        case 0:
            music = (AudioClip)Resources.Load("Music/game theme 1 fixed-ld42", typeof(AudioClip));
            break;

        case 1:
            music = (AudioClip)Resources.Load("Music/game music 2 loop-ld42", typeof(AudioClip));
            break;

        default:
            music = (AudioClip)Resources.Load("Music/game_music_3", typeof(AudioClip));
            break;
        }

        BGM.clip = music;
        BGM.Play();
        BGM.loop = true;

        playingLevel = false;

        StartCoroutine(LoadLevel());
    }
コード例 #4
0
    private IEnumerator Attack(UnitLoader attacker, UnitLoader defender)
    {
        dialoguePlayed = false;

        foreach (UnitLoader unit in FindObjectsOfType <UnitLoader>())
        {
            if (unit.GetComponent <SpriteRenderer>().color == Color.red)
            {
                unit.GetComponent <SpriteRenderer>().color = Color.white;
            }
        }

        cursor.cursorControls.DeactivateInput();
        cursor.GetComponent <Animator>().SetBool("Invisible", true);

        //Check if defender has dialogue for when it's attacked
        if (defender.attackedDialogue != null)
        {
            MapDialogueManager.instance.WriteSingle(defender.attackedDialogue);
            yield return(new WaitForSeconds(0.5f));

            defender.attackedDialogue = null;
        }
        yield return(new WaitUntil(() => !screenDim.activeSelf));

        attackerHealth.GetComponent <RectTransform>().anchoredPosition = WorldToCanvasSpace(attacker.gameObject, defender.gameObject);
        defenderHealth.GetComponent <RectTransform>().anchoredPosition = WorldToCanvasSpace(defender.gameObject, attacker.gameObject);

        combatReadout.SetActive(true);
        yield return(new WaitForSeconds(0.5f));

        AttackAnimation(attacker, defender);
        yield return(new WaitForSeconds(attacker.animator.GetCurrentAnimatorClipInfo(0).Length - 0.2f));

        if (attacker.equippedWeapon.animation)
        {
            PlayEffect(attacker, defender);
            yield return(new WaitForSeconds(0.3f));
        }

        InitiatorAttack(attacker, defender);
        yield return(new WaitForSeconds(0.3f));

        if (CheckForDeaths(attacker, defender) == "Attacker")
        {
            attacker.Death();
            yield return(new WaitForSeconds(0.3f));

            combatReadout.SetActive(false);
            if (attacker.unit.allyUnit)
            {
                cursor.cursorControls.SwitchCurrentActionMap("MapScene");
                cursor.SetState(new MapState(cursor));
            }
            yield return(null);
        }
        else if (CheckForDeaths(attacker, defender) == "Defender")
        {
            //Checks if the defender has dialogue for when its defeated
            if (!dialoguePlayed && defender.defeatedDialogue != null)
            {
                MapDialogueManager.instance.WriteSingle(defender.defeatedDialogue);
                dialoguePlayed = true;
                yield return(new WaitForSeconds(0.5f));
            }
            yield return(new WaitUntil(() => !screenDim.activeSelf));

            defender.Death();
            yield return(new WaitForSeconds(0.2f));

            combatReadout.SetActive(false);
            attacker.Rest();
            if (attacker.unit.allyUnit)
            {
                cursor.cursorControls.SwitchCurrentActionMap("MapScene");
                cursor.SetState(new MapState(cursor));
            }
            yield return(null);
        }
        else
        {
            if (CheckDistance(defender, attacker) <= 1 || defender.equippedWeapon.range >= attacker.equippedWeapon.range)
            {
                AttackAnimation(defender, attacker);
                yield return(new WaitForSeconds((defender.animator.GetCurrentAnimatorClipInfo(0).Length - 0.2f)));

                if (defender.equippedWeapon.animation)
                {
                    PlayEffect(defender, attacker);
                    yield return(new WaitForSeconds(defender.equippedWeapon.animationLength.length));
                }

                DefenderAttack(attacker, defender);
                yield return(new WaitForSeconds(0.3f));
            }

            if (CheckForDeaths(attacker, defender) == "Attacker")
            {
                attacker.Death();
                yield return(new WaitForSeconds(0.2f));

                combatReadout.SetActive(false);
                if (attacker.unit.allyUnit)
                {
                    cursor.cursorControls.SwitchCurrentActionMap("MapScene");
                    cursor.SetState(new MapState(cursor));
                }
                yield return(null);
            }
            else if (CheckForDeaths(attacker, defender) == "Defender")
            {
                //Checks if the defender has dialogue for when its defeated
                if (!dialoguePlayed && defender.defeatedDialogue != null)
                {
                    MapDialogueManager.instance.WriteSingle(defender.defeatedDialogue);
                    dialoguePlayed = true;
                    yield return(new WaitForSeconds(0.5f));
                }
                yield return(new WaitUntil(() => !screenDim.activeSelf));

                defender.Death();
                yield return(new WaitForSeconds(0.2f));

                combatReadout.SetActive(false);
                attacker.Rest();
                if (attacker.unit.allyUnit)
                {
                    cursor.cursorControls.SwitchCurrentActionMap("MapScene");
                    cursor.SetState(new MapState(cursor));
                }
                yield break;
            }
            else
            {
                if (CheckAttackSpeed(attacker, defender))
                {
                    AttackAnimation(attacker, defender);
                    yield return(new WaitForSeconds(attacker.animator.GetCurrentAnimatorClipInfo(0).Length - 0.2f));

                    if (attacker.equippedWeapon.animation)
                    {
                        PlayEffect(attacker, defender);
                        yield return(new WaitForSeconds(attacker.equippedWeapon.animationLength.length));
                    }

                    InitiatorAttack(attacker, defender);
                    yield return(new WaitForSeconds(0.3f));

                    cursor.SetState(new MapState(cursor));
                    yield return(null);
                }
                yield return(new WaitForSeconds(0.3f));

                combatReadout.SetActive(false);
                attacker.Rest();
                if (attacker.unit.allyUnit)
                {
                    cursor.cursorControls.SwitchCurrentActionMap("MapScene");
                    cursor.SetState(new MapState(cursor));
                }
                yield return(null);
            }
            combatReadout.SetActive(false);
            if (CheckForDeaths(attacker, defender) == "Defender" || CheckForDeaths(attacker, defender) == null)
            {
                defender.Death();
                attacker.Rest();
            }
            if (attacker.unit.allyUnit)
            {
                cursor.cursorControls.SwitchCurrentActionMap("MapScene");
                cursor.SetState(new MapState(cursor));
            }
            yield return(null);
        }
        yield return(new WaitForSeconds(0.2f));

        combatReadout.SetActive(false);
        if (CheckForDeaths(attacker, defender) == "Defender" || CheckForDeaths(attacker, defender) == null)
        {
            attacker.Rest();
        }
        if (attacker.unit.allyUnit)
        {
            cursor.cursorControls.SwitchCurrentActionMap("MapScene");
            cursor.SetState(new MapState(cursor));
        }

        //This block checks if an Ally Unit is below 50% health, which if true triggers their battle dialogue
        if (attacker.unit.allyUnit && attacker.currentHealth < (attacker.unit.statistics.health * .5f) && attacker.currentHealth > 0 && !dialoguePlayed)
        {
            MapDialogueManager.instance.WriteSingle(attacker.GetComponent <BattleDialogue>().under50Quote);
            dialoguePlayed = true;
        }
        else if (defender.unit.allyUnit && defender.currentHealth < (defender.unit.statistics.health * .5f) && defender.currentHealth > 0 && !dialoguePlayed)
        {
            MapDialogueManager.instance.WriteSingle(defender.GetComponent <BattleDialogue>().under50Quote);
            dialoguePlayed = true;
        }

        if (TurnManager.instance.currentState.stateType == TurnState.StateType.Player)
        {
            cursor.GetComponent <Animator>().SetBool("Invisible", false);
        }
        yield return(null);
    }