Example #1
0
    public void Dust(bool playDust = true, bool removeObject = false)
    {
        if (tag == "enemy" || tag == "bubble")
        {
            throw new CYFException("sprite.Dust(): You can't dust a " + tag + "'s sprite!");
        }

        GameObject go = Object.Instantiate(Resources.Load <GameObject>("Prefabs/MonsterDuster"));

        go.transform.SetParent(UIController.instance.psContainer.transform);
        if (playDust)
        {
            UnitaleUtil.PlaySound("DustSound", AudioClipRegistry.GetSound("enemydust"));
        }
        img.GetComponent <ParticleDuplicator>().Activate(this);
        if (img.gameObject.name == "player")
        {
            return;
        }
        img.SetActive(false);
        if (removeObject)
        {
            Remove();
        }
    }
Example #2
0
    public static void PlaySound(string name, string sound, bool loop = false, float volume = 0.65f)
    {
        if (name == null)
        {
            throw new CYFException("NewAudio.PlaySound: The first argument (the channel name) is nil.\n\nSee the documentation for proper usage.");
        }
        if (sound == null)
        {
            throw new CYFException("NewAudio.PlaySound: The second argument (the sound name) is nil.\n\nSee the documentation for proper usage.");
        }
        if (!audiolist.ContainsKey(name))
        {
            throw new CYFException("The audio channel " + name + " doesn't exist.");
        }

        ((AudioSource)audiolist[name]).Stop();
        ((AudioSource)audiolist[name]).loop   = loop;
        ((AudioSource)audiolist[name]).volume = volume;
        ((AudioSource)audiolist[name]).clip   = AudioClipRegistry.GetSound(sound);
        audiolist[name] = ((AudioSource)audiolist[name]);
        audioname[name] = "sound:" + sound.ToLower();
        if (name == "src")
        {
            MusicManager.filename = "sound:" + sound.ToLower();
        }
        ((AudioSource)audiolist[name]).Play();
    }
Example #3
0
    public void setHP(float newhp, bool forced = false)
    {
        if (newhp <= 0)
        {
            EventManager.instance.luaGeneralOw.GameOver();
            return;
        }
        float CheckedHP = PlayerCharacter.instance.HP;

        UnitaleUtil.PlaySound("CollisionSoundChannel", AudioClipRegistry.GetSound(CheckedHP - newhp >= 0 ? "hurtsound" : "healsound").name);

        newhp = Mathf.Round(newhp * Mathf.Pow(10, ControlPanel.instance.MaxDigitsAfterComma)) / Mathf.Pow(10, ControlPanel.instance.MaxDigitsAfterComma);

        if (forced)
        {
            CheckedHP = newhp > PlayerCharacter.instance.MaxHP * 1.5 ? (int)(PlayerCharacter.instance.MaxHP * 1.5) : newhp;
        }
        else
        {
            CheckedHP = newhp > PlayerCharacter.instance.MaxHP       ? PlayerCharacter.instance.MaxHP              : newhp;
        }

        if (CheckedHP > ControlPanel.instance.HPLimit)
        {
            CheckedHP = ControlPanel.instance.HPLimit;
        }

        PlayerCharacter.instance.HP = CheckedHP;
    }
Example #4
0
    public void Hurt(int damage)
    {
        if (damage >= 0)
        {
            UnitaleUtil.PlaySound("HurtSound", AudioClipRegistry.GetSound("hurtsound"), 0.65f);
        }
        else
        {
            UnitaleUtil.PlaySound("HurtSound", AudioClipRegistry.GetSound("healsound"), 0.65f);
        }

        if (-damage + player.HP > player.MaxHP)
        {
            player.HP = player.MaxHP;
        }
        else if (-damage + player.HP <= 0)
        {
            player.HP = 1;
        }
        else
        {
            player.HP -= damage;
        }
        appliedScript.Call("CYFEventNextCommand");
    }
Example #5
0
 public void setMaxHP(int value)
 {
     if (value == PlayerCharacter.instance.MaxHP)
     {
         return;
     }
     if (value <= 0)
     {
         setHP(0);
         return;
     }
     if (value > ControlPanel.instance.HPLimit)
     {
         value = ControlPanel.instance.HPLimit;
     }
     else if (PlayerCharacter.instance.HP > value)
     {
         PlayerCharacter.instance.HP = value;
     }
     else
     {
         UnitaleUtil.PlaySound("CollisionSoundChannel", AudioClipRegistry.GetSound("healsound").name);
     }
     PlayerCharacter.instance.MaxHPShift = value - PlayerCharacter.instance.BasisMaxHP;
 }
Example #6
0
    public void setHP(float newhp, bool forced = false)
    {
        if (newhp <= 0)
        {
            GameOverBehavior gob = GameObject.FindObjectOfType <GameOverBehavior>();
            if (!MusicManager.IsStoppedOrNull(PlayerOverworld.audioKept))
            {
                gob.musicBefore = PlayerOverworld.audioKept;
                gob.music       = gob.musicBefore.clip;
                gob.musicBefore.Stop();
            }
            else if (!MusicManager.IsStoppedOrNull(Camera.main.GetComponent <AudioSource>()))
            {
                gob.musicBefore = Camera.main.GetComponent <AudioSource>();
                gob.music       = gob.musicBefore.clip;
                gob.musicBefore.Stop();
            }
            else
            {
                gob.musicBefore = null;
                gob.music       = null;
            }
            player.HP = 0;
            gob.gameObject.transform.SetParent(null);
            GameObject.DontDestroyOnLoad(gob.gameObject);
            RectTransform rt = gob.gameObject.GetComponent <RectTransform>();
            rt.position = new Vector3(rt.position.x, rt.position.y, -1000);
            gob.gameObject.GetComponent <GameOverBehavior>().StartDeath();
            return;
        }
        float CheckedHP = player.HP;

        if (CheckedHP - newhp >= 0)
        {
            UnitaleUtil.PlaySound("CollisionSoundChannel", AudioClipRegistry.GetSound("hurtsound").name);
        }
        else
        {
            UnitaleUtil.PlaySound("CollisionSoundChannel", AudioClipRegistry.GetSound("healsound").name);
        }

        newhp = Mathf.Round(newhp * Mathf.Pow(10, ControlPanel.instance.MaxDigitsAfterComma)) / Mathf.Pow(10, ControlPanel.instance.MaxDigitsAfterComma);

        if (forced)
        {
            CheckedHP = newhp > player.MaxHP * 1.5 ? (int)(player.MaxHP * 1.5) : newhp;
        }
        else
        {
            CheckedHP = newhp > player.MaxHP       ? player.MaxHP              : newhp;
        }

        if (CheckedHP > ControlPanel.instance.HPLimit)
        {
            CheckedHP = ControlPanel.instance.HPLimit;
        }

        player.HP = CheckedHP;
    }
Example #7
0
    public static void PlaySound(string name, float volume = 0.65f)
    {
        if (name == null)
        {
            throw new CYFException("Attempted to load a nil value as a sound.");
        }

        UnitaleUtil.PlaySound("MusicPlaySound", AudioClipRegistry.GetSound(name), volume);
    }
Example #8
0
 /// <summary>
 /// Plays a selected sound at a given volume.
 /// </summary>
 /// <param name="sound"></param>
 /// <param name="volume"></param>
 [CYFEventFunction] public void PlaySound(string sound, float volume = 0.65f)
 {
     volume = Mathf.Clamp01(volume);
     if (AudioClipRegistry.GetSound(sound) == null)
     {
         throw new CYFException("General.PlaySound: The given BGM doesn't exist. Please check if you've spelled it correctly.");
     }
     UnitaleUtil.PlaySound("PlaySound", AudioClipRegistry.GetSound(sound), volume);
     //GameObject.Find("Player").GetComponent<AudioSource>().PlayOneShot(AudioClipRegistry.GetSound(sound), volume);
     appliedScript.Call("CYFEventNextCommand");
 }
Example #9
0
    public static void PlaySound(string name, float volume = 0.65f)
    {
        if (name == null)
        {
            UnitaleUtil.WriteInLogAndDebugger("[WARN]Attempted to load a nil value as a sound.");
            return;
        }

        try { UnitaleUtil.PlaySound("MusicPlaySound", AudioClipRegistry.GetSound(name), volume); }
        catch {  }
    }
Example #10
0
 /// <summary>
 /// Built-in Unity function for initialization.
 /// </summary>
 private void Awake()
 {
     self        = GetComponent <RectTransform>();
     selfImg     = GetComponent <Image>();
     playerAbs   = new Rect(0, 0, selfImg.sprite.texture.width - hitboxInset * 2, selfImg.sprite.texture.height - hitboxInset * 2);
     instance    = this;
     playerAudio = GetComponent <AudioSource>();
     hurtSound   = AudioClipRegistry.GetSound("hurtsound");
     healSound   = AudioClipRegistry.GetSound("healsound");
     SetSoul(new RedSoul(this));
     luaStatus = new LuaPlayerStatus(this);
 }
 public void StopAction()
 {
     if (stopped)
     {
         return;
     }
     stopped = true;
     Damage  = getDamage();
     line.SetAnimation(lineAnim, 1 / 12f);
     slice.SetAnimation(sliceAnim, 1 / 6f);
     slice.loop = KeyframeCollection.LoopMode.ONESHOT;
     UIController.playSoundSeparate(AudioClipRegistry.GetSound("slice"));
 }
Example #12
0
 private IEnumerator TitlePhase1()
 {
     Camera.main.GetComponent <AudioSource>().PlayOneShot(AudioClipRegistry.GetSound("intro_noise"));
     while (Camera.main.GetComponent <AudioSource>().isPlaying)
     {
         yield return(0);
     }
     while (phase == 0)
     {
         PressEnterOrZ.color = new Color(255, 255, 255, PressEnterOrZ.color.a == 1 ? 0 : 1);
         yield return(new WaitForSeconds(1));
     }
 }
Example #13
0
 public void StartDeath()
 {
     brokenHeartPrefab = Resources.Load <GameObject>("Prefabs/heart_broken");
     heartShardPrefab  = SpriteRegistry.GENERIC_SPRITE_PREFAB.gameObject;
     gameOverTxt       = GameObject.Find("TextParent").GetComponent <TextManager>();
     heartbreak        = AudioClipRegistry.GetSound("heartbeatbreaker");
     heartsplode       = AudioClipRegistry.GetSound("heartsplosion");
     gameOverImage     = GameObject.Find("GameOver").GetComponent <Image>();
     heartPos          = gameObject.GetComponent <RectTransform>().position;
     heartColor        = gameObject.GetComponent <Image>().color;
     gameObject.transform.SetParent(GameObject.Find("Canvas").transform);
     gameOverMusic = Camera.main.GetComponent <AudioSource>();
     started       = true;
 }
Example #14
0
    public static bool PlaySound(string name, float volume = 0.65f)
    {
        if (name == null)
        {
            UnitaleUtil.WriteInLogAndDebugger("[WARN]Attempted to load a nil value as a sound.");
            return(false);
        }

        try {
            UnitaleUtil.PlaySound("MusicPlaySound", AudioClipRegistry.GetSound(name, GlobalControls.retroMode), volume);
            return(true);
        }
        catch { return(false); }
    }
Example #15
0
    /// <summary>
    /// Hurts the player and makes them invulnerable for invulnerabilitySeconds.
    /// </summary>
    /// <param name="damage">Damage to deal to the player.</param>
    /// <param name="invulnerabilitySeconds">Optional invulnerability time for the player, in seconds.</param>
    /// <param name="isDefIgnored">If false, will use Undertale's damage formula.</param>
    /// <param name="playSound">If false, this function will not play any sound clips.</param>
    /// <returns></returns>
    public virtual void Hurt(float damage = 3, float invulnerabilitySeconds = 1.7f, bool isDefIgnored = false, bool playSound = true)
    {
        if (!isDefIgnored)
        {
            if (allowplayerdef && damage > 0)
            {
                damage = damage + 2 - Mathf.FloorToInt((PlayerCharacter.instance.DEF + PlayerCharacter.instance.ArmorDEF) / 5f);
                if (damage <= 0)
                {
                    damage = 1;
                }
            }
        }
        // Set timer and play the hurt sound if player was actually hurt

        // Reset the hurt timer if the arguments passed are (0, 0)
        if (damage == 0 && invulnerabilitySeconds == 0)
        {
            invulTimer      = 0;
            selfImg.enabled = true;
            return;
        }

        if (damage >= 0 && (invulTimer <= 0 || invulnerabilitySeconds < 0))
        {
            if (soundDelay < 0 && playSound)
            {
                soundDelay = 2;
                PlaySound(AudioClipRegistry.GetSound("hurtsound"));
            }

            if (invulnerabilitySeconds >= 0)
            {
                invulTimer = invulnerabilitySeconds;
            }
            if (damage != 0)
            {
                SetHP(HP - damage, false);
            }
        }
        else if (damage < 0)
        {
            if (playSound)
            {
                PlaySound(AudioClipRegistry.GetSound("healsound"));
            }
            SetHP(HP - damage);
        }
    }
Example #16
0
    /// <summary>
    /// Hurts the player and makes them invulnerable for invulnerabilitySeconds.
    /// </summary>
    /// <param name="damage">Damage to deal to the player</param>
    /// <param name="invulnerabilitySeconds">Optional invulnerability time for the player, in seconds.</param>
    /// <returns></returns>
    public virtual void Hurt(float damage = 3, float invulnerabilitySeconds = 1.7f, bool isDefIgnored = false)
    {
        if (!isDefIgnored)
        {
            if (GlobalControls.allowplayerdef && damage > 0)
            {
                damage = damage + 2 - Mathf.FloorToInt((PlayerCharacter.instance.DEF + PlayerCharacter.instance.ArmorDEF) / 5);
                if (damage <= 0)
                {
                    damage = 1;
                }
            }
        }
        // set timer and play the hurt sound if player was actually hurt
        // TODO: factor in stats and what the actual damage should be
        // TONOTDO: I don't care about stats, lvk :D

        // reset the hurt timer if the arguments passed are (0, 0)
        if (damage == 0 && invulnerabilitySeconds == 0)
        {
            invulTimer      = 0;
            selfImg.enabled = true;
            return;
        }

        if (damage >= 0 && (invulTimer <= 0 || invulnerabilitySeconds < 0))
        {
            if (soundDelay < 0)
            {
                soundDelay = 2;
                PlaySound(AudioClipRegistry.GetSound("hurtsound"));
            }

            if (HP - damage > 0 && invulnerabilitySeconds >= 0)
            {
                invulTimer = invulnerabilitySeconds;
            }
            if (damage != 0)
            {
                setHP(HP - damage, false);
            }
        }
        else if (damage < 0)
        {
            PlaySound(AudioClipRegistry.GetSound("healsound"));
            setHP(HP - damage);
        }
    }
Example #17
0
    private void Awake()
    {
        fightB1 = SpriteRegistry.Get("UI/Buttons/fightbt_1");
        actB1   = SpriteRegistry.Get("UI/Buttons/actbt_1");
        itemB1  = SpriteRegistry.Get("UI/Buttons/itembt_1");
        mercyB1 = SpriteRegistry.Get("UI/Buttons/mercybt_1");

        sndSelect  = AudioClipRegistry.GetSound("menumove");
        sndConfirm = AudioClipRegistry.GetSound("menuconfirm");

        arenaParent  = GameObject.Find("arena_border_outer");
        canvasParent = GameObject.Find("Canvas");
        uiAudio      = GetComponent <AudioSource>();
        uiAudio.clip = sndSelect;

        instance = this;
    }
Example #18
0
 public void StopAction(float atkMult = -2, bool stopCoroutine = false)
 {
     if (!stopCoroutine)
     {
         if (stopped)
         {
             return;
         }
         stopped = true;
         foreach (FightUI fight in boundFightUiInstances)
         {
             fight.StopAction(atkMult);
         }
     }
     line.SetAnimation(lineAnim, 1 / 12f);
     UIController.PlaySoundSeparate(AudioClipRegistry.GetSound("slice"));
 }
Example #19
0
 public static void PlaySound(string name, string sound, bool loop = false, float volume = 0.65f)
 {
     if (!audiolist.ContainsKey(name))
     {
         throw new CYFException("The audio channel " + name + " doesn't exist.");
     }
     ((AudioSource)audiolist[name]).Stop();
     ((AudioSource)audiolist[name]).loop   = loop;
     ((AudioSource)audiolist[name]).volume = volume;
     ((AudioSource)audiolist[name]).clip   = AudioClipRegistry.GetSound(sound);
     audiolist[name] = ((AudioSource)audiolist[name]);
     audioname[name] = "sound:" + sound.ToLower();
     if (name == "src")
     {
         MusicManager.filename = "sound:" + sound.ToLower();
     }
     ((AudioSource)audiolist[name]).Play();
 }
Example #20
0
    public void Hurt(int damage)
    {
        UnitaleUtil.PlaySound("HurtSound", AudioClipRegistry.GetSound(damage >= 0 ? "hurtsound" : "healsound"));

        if (-damage + PlayerCharacter.instance.HP > PlayerCharacter.instance.MaxHP)
        {
            PlayerCharacter.instance.HP = PlayerCharacter.instance.MaxHP;
        }
        else if (-damage + PlayerCharacter.instance.HP <= 0)
        {
            PlayerCharacter.instance.HP = 1;
        }
        else
        {
            PlayerCharacter.instance.HP -= damage;
        }
        appliedScript.Call("CYFEventNextCommand");
    }
Example #21
0
 IEnumerator TitlePhase1()
 {
     Camera.main.GetComponent <AudioSource>().PlayOneShot(AudioClipRegistry.GetSound("intro_noise"));
     while (Camera.main.GetComponent <AudioSource>().isPlaying)
     {
         yield return(0);
     }
     while (phase == 0)
     {
         if (GameObject.Find("PressEnterOrZ").GetComponent <SpriteRenderer>().color.a == 1)
         {
             GameObject.Find("PressEnterOrZ").GetComponent <SpriteRenderer>().color = new Color(255, 255, 255, 0);
         }
         else
         {
             GameObject.Find("PressEnterOrZ").GetComponent <SpriteRenderer>().color = new Color(255, 255, 255, 1);
         }
         yield return(new WaitForSeconds(1));
     }
 }
    public void Dust(bool playDust = true, bool removeObject = false)
    {
        if (tag == "enemy" || tag == "bubble")
        {
            return;
        }
        GameObject go = GameObject.Instantiate(MonsterDusterPrefab);

        go.transform.SetParent(UIController.instance.psContainer.transform);
        if (playDust)
        {
            UnitaleUtil.PlaySound("DustSound", AudioClipRegistry.GetSound("enemydust"));
        }
        img.GetComponent <ParticleDuplicator>().Activate(this);
        if (img.gameObject.name != "player")
        {
            img.SetActive(false);
            if (removeObject)
            {
                img = null;
            }
        }
    }
Example #23
0
 public static void PlaySound(string name)
 {
     AudioSource.PlayClipAtPoint(AudioClipRegistry.GetSound(name), Camera.main.transform.position, 0.65f);
 }
Example #24
0
    private void HandleAction()
    {
        switch (state)
        {
        case UIState.ATTACKING:
            fightUI.StopAction();
            break;

        case UIState.DIALOGRESULT:
            if (!textmgr.lineComplete())
            {
                break;
            }

            if (!textmgr.allLinesComplete() && textmgr.lineComplete())
            {
                textmgr.nextLine();
                break;
            }

            if (textmgr.allLinesComplete())
            {
                textmgr.destroyText();
                SwitchState(stateAfterDialogs);
            }
            break;

        case UIState.ACTIONSELECT:
            switch (action)
            {
            case Actions.FIGHT:
                SwitchState(UIState.ENEMYSELECT);
                break;

            case Actions.ACT:
                SwitchState(UIState.ENEMYSELECT);
                break;

            case Actions.ITEM:
                if (Inventory.container.Count == 0)
                {
                    return;         // prevent sound playback
                }
                SwitchState(UIState.ITEMMENU);
                break;

            case Actions.MERCY:
                SwitchState(UIState.MERCYMENU);
                break;
            }
            playSound(sndConfirm);
            break;

        case UIState.ENEMYSELECT:
            switch (action)
            {
            case Actions.FIGHT:
                // encounter.enemies[selectedEnemy].HandleAttack(-1);
                SwitchState(UIState.ATTACKING);
                break;

            case Actions.ACT:
                SwitchState(UIState.ACTMENU);
                break;
            }
            playSound(sndConfirm);
            break;

        case UIState.ACTMENU:
            textmgr.setCaller(encounter.enabledEnemies[selectedEnemy].script);     // probably not necessary due to ActionDialogResult changes
            encounter.enabledEnemies[selectedEnemy].Handle(encounter.enabledEnemies[selectedEnemy].ActCommands[selectedAction]);
            playSound(sndConfirm);
            break;

        case UIState.ITEMMENU:
            encounter.HandleItem(Inventory.container[selectedItem]);
            playSound(sndConfirm);
            break;

        case UIState.MERCYMENU:
            if (selectedMercy == 0)
            {
                LuaEnemyController[] enabledEnTemp = encounter.enabledEnemies;
                bool sparedAny = false;
                foreach (LuaEnemyController enemy in enabledEnTemp)
                {
                    if (enemy.CanSpare)
                    {
                        enemy.DoSpare();
                        sparedAny = true;
                    }
                }

                if (sparedAny)
                {
                    if (encounter.enabledEnemies.Length == 0)
                    {
                        checkAndTriggerVictory();
                        break;
                    }
                }

                encounter.CallOnSelfOrChildren("HandleSpare");
            }
            else if (selectedMercy == 1)
            {
                PlayerController.instance.GetComponent <Image>().enabled = false;
                AudioClip yay = AudioClipRegistry.GetSound("runaway");
                AudioSource.PlayClipAtPoint(yay, Camera.main.transform.position);
                string fittingLine = "";
                switch (runawayattempts)
                {
                case 0:
                    fittingLine = "...[w:15]But you realized\rthe overworld was missing.";
                    break;

                case 1:
                    fittingLine = "...[w:15]But the overworld was\rstill missing.";
                    break;

                case 2:
                    fittingLine = "You walked off as if there\rwere an overworld, but you\rran into an invisible wall.";
                    break;

                case 3:
                    fittingLine = "...[w:15]On second thought, the\rembarassment just now\rwas too much.";
                    break;

                case 4:
                    fittingLine = "But you became aware\rof the skeleton inside your\rbody, and forgot to run.";
                    break;

                case 5:
                    fittingLine = "But you needed a moment\rto forget about your\rscary skeleton.";
                    break;

                case 6:
                    fittingLine = "...[w:15]You feel as if you\rtried this before.";
                    break;

                case 7:
                    fittingLine = "...[w:15]Maybe if you keep\rsaying that, the\roverworld will appear.";
                    break;

                case 8:
                    fittingLine = "...[w:15]Or not.";
                    break;

                default:
                    fittingLine = "...[w:15]But you decided to\rstay anyway.";
                    break;
                }

                ActionDialogResult(new TextMessage[]
                {
                    new RegularMessage("I'm outta here."),
                    new RegularMessage(fittingLine)
                },
                                   UIState.ENEMYDIALOGUE);
                Camera.main.GetComponent <AudioSource>().Pause();
                musicPausedFromRunning = true;
                runawayattempts++;
            }
            playSound(sndConfirm);
            break;

        case UIState.ENEMYDIALOGUE:
            if (!ArenaSizer.instance.isResizeInProgress())
            {
                doNextMonsterDialogue();
            }
            break;
        }
    }
    // Update is called once per frame
    private void Update()
    {
        if (finishingFade)
        {
            float resizeProg = 1.0f - ArenaSizer.instance.getProgress();
            setAlpha(resizeProg);
            if (resizeProg == 0.0f)
            {
                damageText.destroyText();
                gameObject.SetActive(false);
            }
            return;
        }

        if (shakeInProgress)
        {
            int shakeidx = (int)Mathf.Floor(shakeTimer * shakeX.Length / totalShakeTime);

            if (Damage > 0 && shakeIndex != shakeidx)
            {
                shakeIndex = shakeidx;
                if (shakeIndex >= shakeX.Length)
                {
                    shakeIndex = shakeX.Length - 1;
                }
                Vector2 localEnePos = enemy.GetComponent <RectTransform>().anchoredPosition; // get local position to do the shake
                enemy.GetComponent <RectTransform>().anchoredPosition = new Vector2(localEnePos.x + shakeX[shakeIndex], localEnePos.y);
            }

            damageTextRt.position = new Vector2(damageTextRt.position.x, 80 + enePos.y + 40 * Mathf.Sin(shakeTimer * Mathf.PI * 0.75f));

            shakeTimer += Time.deltaTime;
            if (shakeTimer >= totalShakeTime)
            {
                shakeInProgress = false;
                initFade();
            }
            return;
        }

        if (!shakeInProgress && slice.animcomplete)
        {
            slice.StopAnimation();
            if (Damage > 0)
            {
                AudioSource aSrc = GetComponent <AudioSource>();
                aSrc.clip = AudioClipRegistry.GetSound("hitsound");
                aSrc.Play();
            }
            // set damage numbers and positioning
            string damageTextStr = "";
            if (Damage <= 0)
            {
                damageTextStr = "[color:c0c0c0]MISS";
            }
            else
            {
                damageTextStr = "[color:ff0000]" + Damage;
            }
            // the -14 is to compensate for the 14 characters that [color:rrggbb] is worth until commands no longer count for text length. soon
            int damageTextWidth = (damageTextStr.Length - 14) * 29 + (damageTextStr.Length - 1 - 14) * 3; // lol hardcoded offsets
            foreach (char c in damageTextStr)
            {
                if (c == '1')
                {
                    damageTextWidth -= 12; // lol hardcoded offsets
                }
            }
            damageTextRt.position = new Vector2(enePos.x - 0.5f * damageTextWidth, 80 + enePos.y);
            damageText.setText(new TextMessage(damageTextStr, false, true));

            // initiate lifebar and set lerp to its new health value
            if (Damage > 0)
            {
                int newHP = enemy.HP - Damage;
                if (newHP < 0)
                {
                    newHP = 0;
                }
                lifeBar.GetComponent <RectTransform>().position  = new Vector2(enePos.x, enePos.y + 20);
                lifeBar.GetComponent <RectTransform>().sizeDelta = new Vector2(enemy.GetComponent <RectTransform>().rect.width, 13);
                lifeBar.setInstant((float)enemy.HP / (float)enemy.getMaxHP());
                lifeBar.setLerp((float)enemy.HP / (float)enemy.getMaxHP(), (float)newHP / (float)enemy.getMaxHP());
                lifeBar.setVisible(true);
                enemy.doDamage(Damage);
            }

            // finally, damage enemy and call its attack handler in case you wanna stop music on death or something
            shakeInProgress = true;
            enemy.HandleAttack(Damage);
        }

        if (stopped)
        {
            return;
        }
        float mv = xSpeed * Time.deltaTime;
        targetRt.anchoredPosition = new Vector2(targetRt.anchoredPosition.x + mv, 0);
        if (Finished()) // you didn't press Z or you wouldn't be here
        {
            enemy.HandleAttack(-1);
            StationaryMissScript smc = Resources.Load <StationaryMissScript>("Prefabs/StationaryMiss");
            smc = Instantiate(smc);
            smc.transform.SetParent(GameObject.Find("Canvas").transform);
            smc.setXPosition(320 - enePos.x);
            initFade();
        }
    }
Example #26
0
    // Update is called once per frame
    void Update()
    {
        GlobalControls.lastTitle = true;
        if (GlobalControls.input.Confirm == UndertaleInput.ButtonState.PRESSED && phase == 0)
        {
            phase++;
            Camera.main.GetComponent <AudioSource>().Stop();
            StopCoroutine(TitlePhase1());
        }
        else if (phase == 1)
        {
            if (!initPhase)
            {
                initPhase = true;

                Camera.main.GetComponent <AudioSource>().clip = AudioClipRegistry.GetMusic("mus_menu");
                Camera.main.GetComponent <AudioSource>().Play();
                try {
                    if (!SaveLoad.Load())
                    {
                        SceneManager.LoadScene("EnterName");
                    }
                    else
                    {
                        GameObject.Find("PressEnterOrZ").SetActive(false);
                        GameObject.Find("Title").SetActive(false);
                        GameObject.Find("Title (1)").SetActive(false);
                        GameObject.Find("Back1").SetActive(false);
                        GameObject.Find("TextManagerName").GetComponent <TextManager>().SetHorizontalSpacing(2);
                        GameObject.Find("TextManagerLevel").GetComponent <TextManager>().SetHorizontalSpacing(2);
                        GameObject.Find("TextManagerTime").GetComponent <TextManager>().SetHorizontalSpacing(2);
                        GameObject.Find("TextManagerMap").GetComponent <TextManager>().SetHorizontalSpacing(2);
                        GameObject.Find("TextManagerName").GetComponent <TextManager>().SetTextQueue(new TextMessage[] { new TextMessage("[noskipatall]" + PlayerCharacter.instance.Name, false, true) });
                        GameObject.Find("TextManagerLevel").GetComponent <TextManager>().SetTextQueue(new TextMessage[] { new TextMessage("[noskipatall]" + (GlobalControls.crate ? "VL" : "LV") +
                                                                                                                                          PlayerCharacter.instance.LV, false, true) });
                        GameObject.Find("TextManagerTime").GetComponent <TextManager>().SetTextQueue(new TextMessage[] { new TextMessage("[noskipatall]" + UnitaleUtil.TimeFormatter(SaveLoad.savedGame.playerTime), false, true) });
                        GameObject.Find("TextManagerMap").GetComponent <TextManager>().SetTextQueue(new TextMessage[] { new TextMessage("[noskipatall]" + SaveLoad.savedGame.lastScene, false, true) });
                        tmName.SetTextQueue(new TextMessage[] { new TextMessage(PlayerCharacter.instance.Name, false, true) });
                        diff = calcTotalLength(tmName);
                        tmName.SetEffect(new ShakeEffect(tmName));
                    }
                } catch {
                    GlobalControls.allowWipeSave = true;
                    if (GlobalControls.crate)
                    {
                        UnitaleUtil.DisplayLuaError(StaticInits.ENCOUNTER, "U USED AN ODL VERSOIN OF CFY? IT ISN'T COMAPTIBEL.\n\n"
                                                    + "DELEET UR SAVE OT NOT HVAE DA ERRRO AGAIN. HREE: <b>\n"
                                                    + Application.persistentDataPath + "/save.gd</b>\n\n"
                                                    + "OR <b>PERS R NWO</b> TO DELEET SAV N CLOSE YCF.\n\n\n"
                                                    + "IF MOAR PORBLMES, TELL EM! :D\n\n");
                    }
                    else
                    {
                        UnitaleUtil.DisplayLuaError(StaticInits.ENCOUNTER, "Have you saved on a previous or newer version of CYF? Your save isn't compatible with this version.\n\n"
                                                    + "To fix this, you must delete your save file. It can be found here: \n<b>"
                                                    + Application.persistentDataPath + "/save.gd</b>\n\n"
                                                    + "Or, you can <b>Press R now</b> to delete your save and close CYF.\n\n\n"
                                                    + "Tell me if you have any more problems, and thanks for following my fork! ^^\n\n");
                    }
                }
            }
            else
            {
                if (GlobalControls.input.Right == UndertaleInput.ButtonState.PRESSED || GlobalControls.input.Left == UndertaleInput.ButtonState.PRESSED)
                {
                    setColor(choiceLetter == 2 ? 2 : (choiceLetter + 1) % 2);
                }
                if (GlobalControls.input.Up == UndertaleInput.ButtonState.PRESSED || GlobalControls.input.Down == UndertaleInput.ButtonState.PRESSED)
                {
                    setColor(choiceLetter == 2 ? 0 : 2);
                }
                else if (GlobalControls.input.Confirm == UndertaleInput.ButtonState.PRESSED)
                {
                    switch (choiceLetter)
                    {
                    case 0:
                        phase = -1;
                        StartCoroutine(LoadGame());
                        break;

                    case 1:
                        phase = 2;
                        GameObject.Find(firstPhaseEventNames[choiceLetter]).GetComponent <SpriteRenderer>().color = new Color(1, 1, 1, 1);
                        GameObject.Find("CanvasReset").transform.position = new Vector3(320, 240, -500);
                        setColor(0, 2);
                        break;

                    case 2:
                        SceneManager.LoadScene("EnterName");
                        break;
                    }
                }
            }
        }
        else if (phase == 2)
        {
            if (tmName.transform.localScale.x < 3)
            {
                tmName.transform.localScale    = new Vector3(tmName.transform.localScale.x + 0.01f, tmName.transform.localScale.y + 0.01f, 1);
                tmName.transform.localPosition = new Vector3(actualX - (((tmName.transform.localScale.x - 1) * diff) / 2),
                                                             actualY - (((tmName.transform.localScale.x - 1) * diff) / 6), tmName.transform.localPosition.z);
            }
            if (GlobalControls.input.Right == UndertaleInput.ButtonState.PRESSED || GlobalControls.input.Left == UndertaleInput.ButtonState.PRESSED)
            {
                setColor((choiceLetter + 1) % 2, 2);
            }
            else if (GlobalControls.input.Confirm == UndertaleInput.ButtonState.PRESSED)
            {
                if (choiceLetter == 1)
                {
                    Camera.main.GetComponent <AudioSource>().Stop();
                    Camera.main.GetComponent <AudioSource>().PlayOneShot(AudioClipRegistry.GetSound("intro_holdup"));
                    phase = -1;
                    StartCoroutine(NewGame());
                }
                else
                {
                    phase = 1;
                    GameObject.Find(secondPhaseEventNames[choiceLetter]).GetComponent <SpriteRenderer>().color = new Color(1, 1, 1, 1);
                    GameObject.Find("CanvasReset").transform.position = new Vector3(320, 240, 50);
                    tmName.transform.localPosition = new Vector3(actualX, actualY, tmName.transform.localPosition.z);
                    tmName.transform.localScale    = new Vector3(1, 1, 1);
                    setColor(0);
                }
            }
        }
    }
Example #27
0
 public void setMaxHPShift(int shift, float invulnerabilitySeconds = 1.7f, bool set = false, bool canHeal = false)
 {
     invulTimer = invulnerabilitySeconds;
     if ((PlayerCharacter.instance.MaxHP + shift <= 0 && !set) || (shift <= 0 && set))
     {
         shift   = 0;
         set     = true;
         canHeal = true;
     }
     if (set)
     {
         if (shift == 0)
         {
             setHP(0);
         }
         else
         {
             if (shift > 999)
             {
                 shift = 999;
             }
             if (shift == PlayerCharacter.instance.MaxHP)
             {
                 return;
             }
             else if (shift < PlayerCharacter.instance.MaxHP)
             {
                 playerAudio.clip = AudioClipRegistry.GetSound("hurtsound");
                 playerAudio.Play();
                 setHP(PlayerCharacter.instance.HP - (PlayerCharacter.instance.MaxHP - shift));
             }
             else
             {
                 playerAudio.clip = AudioClipRegistry.GetSound("healsound");
                 playerAudio.Play();
                 if (canHeal)
                 {
                     setHP(PlayerCharacter.instance.HP - (PlayerCharacter.instance.MaxHP - shift));
                 }
             }
             PlayerCharacter.instance.MaxHPShift = shift - PlayerCharacter.instance.BasisMaxHP;
             UIStats.instance.setMaxHP();
         }
     }
     else
     {
         if (shift + PlayerCharacter.instance.MaxHP > 999)
         {
             shift = 999 - PlayerCharacter.instance.MaxHP;
         }
         if (shift == 0)
         {
             return;
         }
         else if (shift < 0)
         {
             playerAudio.clip = AudioClipRegistry.GetSound("hurtsound");
             playerAudio.Play();
             setHP(PlayerCharacter.instance.HP + shift);
         }
         else
         {
             playerAudio.clip = AudioClipRegistry.GetSound("healsound");
             playerAudio.Play();
             if (canHeal)
             {
                 setHP(PlayerCharacter.instance.HP + shift);
             }
         }
         PlayerCharacter.instance.MaxHPShift += shift;
         UIStats.instance.setMaxHP();
     }
 }
Example #28
0
    // Update is called once per frame
    private void Update()
    {
        if (hasRevived && reviveFade2)
        {
            reviveFade2.transform.localPosition = new Vector3(0, 0, 0);
            if (reviveFade2.color.a > 0.0f)
            {
                reviveFade2.color = new Color(1, 1, 1, reviveFade2.color.a - Time.deltaTime / 2);
            }
            else
            {
                Destroy(reviveFade2.gameObject);
            }
        }
        if (!started)
        {
            return;
        }
        if (!revived)
        {
            if (!once && UnitaleUtil.IsOverworld)
            {
                once = true;
                utHeart.transform.SetParent(GameObject.Find("Canvas GameOver").transform);
                utHeart.transform.position           = heartPos;
                utHeart.GetComponent <Image>().color = heartColor;
                canvasOW = GameObject.Find("Canvas OW");
                canvasOW.SetActive(false);
                canvasTwo = GameObject.Find("Canvas Two");
                canvasTwo.SetActive(false);
            }
            else if (!once)
            {
                once = true;
                gameObject.GetComponent <RectTransform>().sizeDelta = new Vector2(16, 16);
                gameObject.GetComponent <Image>().enabled           = true; // abort the blink animation if it was playing
            }

            if (internalTimer > breakHeartAfter)
            {
                AudioSource.PlayClipAtPoint(AudioClipRegistry.GetSound("heartbeatbreaker"), Camera.main.transform.position, 0.75f);
                brokenHeartPrefab = Instantiate(brokenHeartPrefab);
                brokenHeartPrefab.transform.SetParent(UnitaleUtil.IsOverworld ? GameObject.Find("Canvas GameOver").transform : gameObject.transform);
                brokenHeartPrefab.GetComponent <RectTransform>().position = heartPos;
                brokenHeartPrefab.GetComponent <Image>().color            = heartColor;
                brokenHeartPrefab.GetComponent <Image>().enabled          = true;
                if (UnitaleUtil.IsOverworld)
                {
                    utHeart.GetComponent <Image>().enabled = false;
                }
                else
                {
                    Color color = gameObject.GetComponent <Image>().color;
                    gameObject.GetComponent <Image>().color = new Color(color.r, color.g, color.b, 0);
                    if (EnemyEncounter.script.GetVar("revive").Boolean)
                    {
                        Revive();
                    }
                }
                breakHeartAfter = 999.0f;
            }

            if (internalTimer > explodeHeartAfter)
            {
                AudioSource.PlayClipAtPoint(AudioClipRegistry.GetSound("heartsplosion"), Camera.main.transform.position, 0.75f);
                brokenHeartPrefab.GetComponent <Image>().enabled = false;
                heartShardInstances = new RectTransform[6];
                heartShardRelocs    = new Vector2[6];
                heartShardCtrl      = new LuaSpriteController[6];
                for (int i = 0; i < heartShardInstances.Length; i++)
                {
                    heartShardInstances[i] = Instantiate(heartShardPrefab).GetComponent <RectTransform>();
                    heartShardCtrl[i]      = new LuaSpriteController(heartShardInstances[i].GetComponent <Image>());
                    heartShardInstances[i].transform.SetParent(UnitaleUtil.IsOverworld ? GameObject.Find("Canvas GameOver").transform : gameObject.transform);
                    heartShardInstances[i].GetComponent <RectTransform>().position = heartPos;
                    heartShardInstances[i].GetComponent <Image>().color            = heartColor;
                    heartShardRelocs[i] = Random.insideUnitCircle * 100.0f;
                    heartShardCtrl[i].Set(heartShardAnim[0]);
                    heartShardCtrl[i].SetAnimation(heartShardAnim, 1 / 5f);
                }
                explodeHeartAfter = 999.0f;
            }

            if (internalTimer > gameOverAfter)
            {
                AudioClip originMusic = gameOverMusic.clip;
                if (deathMusic != null)
                {
                    try { gameOverMusic.clip = AudioClipRegistry.GetMusic(deathMusic); }
                    catch { UnitaleUtil.DisplayLuaError("game over screen", "The specified death music doesn't exist. (\"" + deathMusic + "\")"); }
                    if (gameOverMusic.clip == null)
                    {
                        gameOverMusic.clip = originMusic;
                    }
                }
                gameOverMusic.Play();
                gameOverAfter = 999.0f;
            }

            if (internalTimer > fluffybunsAfter)
            {
                if (deathText != null)
                {
                    List <TextMessage> text  = deathText.Select(str => new TextMessage(str, false, false)).ToList();
                    TextMessage[]      text2 = new TextMessage[text.Count + 1];
                    for (int i = 0; i < text.Count; i++)
                    {
                        text2[i] = text[i];
                    }
                    text2[text.Count] = new TextMessage("", false, false);
                    if (Random.Range(0, 400) == 44)
                    {
                        gameOverTxt.SetTextQueue(new[] {
                            new TextMessage("[color:ffffff][voice:v_fluffybuns][waitall:2]4", false, false),
                            new TextMessage("[color:ffffff][voice:v_fluffybuns][waitall:2]" + PlayerCharacter.instance.Name + "!\n[w:15]Stay determined...", false, false),
                            new TextMessage("", false, false)
                        });
                    }
                    else
                    {
                        gameOverTxt.SetTextQueue(text2);
                    }
                }
                else
                {
                    // This "4" made us laugh so hard that I kept it :P
                    int fourChance = Random.Range(0, 80);

                    string[] possibleDeathTexts = { "You cannot give up\njust yet...", "It cannot end\nnow...", "Our fate rests upon\nyou...",
                                                    "Don't lose hope...",              "You're going to\nbe alright!" };
                    if (fourChance == 44)
                    {
                        possibleDeathTexts[4] = "4";
                    }

                    gameOverTxt.SetTextQueue(new[] {
                        new TextMessage("[color:ffffff][voice:v_fluffybuns][waitall:2]" + possibleDeathTexts[Math.RandomRange(0, possibleDeathTexts.Length)], false, false),
                        new TextMessage("[color:ffffff][voice:v_fluffybuns][waitall:2]" + PlayerCharacter.instance.Name + "!\n[w:15]Stay determined...", false, false),
                        new TextMessage("", false, false)
                    });
                }

                fluffybunsAfter = 999.0f;
            }

            if (!done)
            {
                gameOverImage.color = new Color(1, 1, 1, gameOverFadeTimer);
                if (gameOverAfter >= 999.0f && gameOverFadeTimer < 1.0f)
                {
                    gameOverFadeTimer += Time.deltaTime / 2;
                    if (gameOverFadeTimer >= 1.0f)
                    {
                        gameOverFadeTimer = 1.0f;
                        done = true;
                    }
                }
                internalTimer += Time.deltaTime; // This is actually dangerous because done can be true before everything's done if timers are modified
            }
            else if (!exiting && !gameOverTxt.AllLinesComplete())
            {
                // Note: [noskip] only affects the UI controller's ability to skip, so we have to redo that here.
                if (InputUtil.Pressed(GlobalControls.input.Confirm) && gameOverTxt.LineComplete())
                {
                    gameOverTxt.NextLineText();
                }
            }
        }
        else
        {
            if (reviveTextSet && !reviveText.AllLinesComplete())
            {
                // Note: [noskip] only affects the UI controller's ability to skip, so we have to redo that here.
                if (InputUtil.Pressed(GlobalControls.input.Confirm) && reviveText.LineComplete())
                {
                    reviveText.NextLineText();
                }
            }
            else if (reviveTextSet && !exiting)
            {
                exiting = true;
            }
            else if (internalTimerRevive >= 5.0f && !reviveTextSet && breakHeartReviveAfter)
            {
                if (deathText != null)
                {
                    List <TextMessage> text = new List <TextMessage>();
                    foreach (string str in deathText)
                    {
                        text.Add(new TextMessage(str, false, false));
                    }
                    TextMessage[] text2 = new TextMessage[text.Count + 1];
                    for (int i = 0; i < text.Count; i++)
                    {
                        text2[i] = text[i];
                    }
                    text2[text.Count] = new TextMessage("", false, false);
                    reviveText.SetTextQueue(text2);
                }
                reviveTextSet = true;
            }
            else if (internalTimerRevive > 2.5f && internalTimerRevive < 4.0f)
            {
                brokenHeartPrefab.transform.localPosition = new Vector2(Random.Range(-3, 2), Random.Range(-3, 2));
            }
            else if (!breakHeartReviveAfter && internalTimerRevive > 2.5f)
            {
                breakHeartReviveAfter = true;
                AudioSource.PlayClipAtPoint(AudioClipRegistry.GetSound("heartbeatbreaker"), Camera.main.transform.position, 0.75f);
                if (UnitaleUtil.IsOverworld)
                {
                    utHeart.GetComponent <Image>().enabled = true;
                }
                else
                {
                    Color color = gameObject.GetComponent <Image>().color;
                    gameObject.GetComponent <Image>().color = new Color(color.r, color.g, color.b, 1);
                }
                Destroy(brokenHeartPrefab);
            }

            if (!reviveTextSet)
            {
                internalTimerRevive += Time.deltaTime;
            }

            if (exiting && reviveFade.color.a < 1.0f && reviveFade.isActiveAndEnabled)
            {
                reviveFade.color = new Color(1, 1, 1, reviveFade.color.a + Time.deltaTime / 2);
            }
            else if (exiting)
            {
                // repurposing the timer as a reset delay
                gameOverFadeTimer -= Time.deltaTime;
                if (gameOverMusic.volume - Time.deltaTime > 0.0f)
                {
                    gameOverMusic.volume -= Time.deltaTime;
                }
                else
                {
                    gameOverMusic.volume = 0.0f;
                }
                if (gameOverFadeTimer < -1.0f)
                {
                    reviveFade2 = Instantiate(reviveFade.gameObject).GetComponent <Image>();
                    reviveFade2.transform.SetParent(playerParent);
                    reviveFade2.transform.SetAsLastSibling();
                    reviveFade2.transform.localPosition = new Vector3(0, 0, 0);
                    reviveFade.color = new Color(1, 1, 1, 0);
                    EndGameOverRevive();
                    if (musicBefore != null)
                    {
                        musicBefore.clip = music;
                        musicBefore.Play();
                    }
                    hasRevived = true;
                }
            }
        }

        for (int i = 0; i < heartShardInstances.Length; i++)
        {
            heartShardInstances[i].position += (Vector3)heartShardRelocs[i] * Time.deltaTime;
            heartShardRelocs[i].y           -= 100f * Time.deltaTime;
        }

        if (gameOverTxt.textQueue == null)
        {
            return;
        }
        if (!exiting && gameOverTxt.AllLinesComplete() && gameOverTxt.LineCount() != 0)
        {
            exiting           = true;
            gameOverFadeTimer = 1.0f;
        }
        else if (exiting && gameOverFadeTimer > 0.0f)
        {
            gameOverImage.color = new Color(1, 1, 1, gameOverFadeTimer);
            if (!(gameOverFadeTimer > 0.0f))
            {
                return;
            }
            gameOverFadeTimer -= Time.deltaTime / 2;
            if (gameOverFadeTimer <= 0.0f)
            {
                gameOverFadeTimer = 0.0f;
            }
        }
        else if (exiting)
        {
            // repurposing the timer as a reset delay
            gameOverFadeTimer -= Time.deltaTime;
            if (gameOverMusic.volume - Time.deltaTime > 0.0f)
            {
                gameOverMusic.volume -= Time.deltaTime;
            }
            else
            {
                gameOverMusic.volume = 0.0f;
            }
            if (gameOverFadeTimer < -1.0f)
            {
                //StaticInits.Reset();
                EndGameOver();
            }
        }
    }
Example #29
0
    // Update is called once per frame
    private void Update()
    {
        // do not update the attack UI if the ATTACKING state is frozen
        if (UIController.instance.frozenState != UIController.UIState.PAUSE)
        {
            return;
        }

        if (shakeInProgress)
        {
            int shakeidx = (int)Mathf.Floor(shakeTimer * shakeX.Length / totalShakeTime);
            if (Damage > 0 && shakeIndex != shakeidx)
            {
                if (shakeIndex != shakeidx && shakeIndex >= shakeX.Length)
                {
                    shakeIndex = shakeX.Length - 1;
                }
                shakeIndex = shakeidx;
                Vector2 localEnePos = enemy.GetComponent <RectTransform>().anchoredPosition; // get local position to do the shake
                enemy.GetComponent <RectTransform>().anchoredPosition = new Vector2(localEnePos.x + shakeX[shakeIndex], localEnePos.y);

                /*#if UNITY_STANDALONE_WIN || UNITY_EDITOR_WIN
                 *  if (StaticInits.ENCOUNTER == "01 - Two monsters" && StaticInits.MODFOLDER == "Examples")
                 *      Misc.MoveWindow(shakeX[shakeIndex] * 2, 0);
                 #endif*/
            }
            if (shakeTimer < 1.5f)
            {
                damageTextRt.localPosition = new Vector2(damageTextRt.localPosition.x, enemy.offsets[2].y + 40 * (2 + Mathf.Sin(shakeTimer * Mathf.PI * 0.75f)));
            }
            shakeTimer += Time.deltaTime;
            if (shakeTimer >= totalShakeTime)
            {
                shakeInProgress = false;
            }
        }
        else if ((slice.animcomplete && !slice.img.GetComponent <KeyframeCollection>().enabled&& stopped && !showedup) || needAgain)
        {
            needAgain = true;
            if (!wait1frame)
            {
                wait1frame = true;
                slice.StopAnimation();
                slice.Set("empty");
                enemy.TryCall("BeforeDamageValues", new[] { DynValue.NewNumber(Damage) });
                if (Damage > 0)
                {
                    AudioSource aSrc = GetComponent <AudioSource>();
                    aSrc.clip = AudioClipRegistry.GetSound("hitsound");
                    aSrc.Play();
                }
                // set damage numbers and positioning
                string damageTextStr;
                if (Damage == 0)
                {
                    if (enemy.DefenseMissText == null)
                    {
                        damageTextStr = "[color:c0c0c0]MISS";
                    }
                    else
                    {
                        damageTextStr = "[color:c0c0c0]" + enemy.DefenseMissText;
                    }
                }
                else if (Damage > 0)
                {
                    damageTextStr = "[color:ff0000]" + Damage;
                }
                else
                {
                    damageTextStr = "[color:00ff00]" + Damage;
                }
                damageTextRt.localPosition = new Vector3(0, 0, 0);
                damageText.SetText(new TextMessage(damageTextStr, false, true));
                damageTextRt.localPosition = new Vector3(-UnitaleUtil.CalcTextWidth(damageText) / 2 + enemy.offsets[2].x, 40 + enemy.offsets[2].y);

                // initiate lifebar and set lerp to its new health value
                if (Damage != 0)
                {
                    int newHP = enemy.HP - Damage;
                    try {
                        lifeBar.GetComponent <RectTransform>().localPosition = new Vector2(enemy.offsets[2].x, 20 + enemy.offsets[2].y);
                        lifeBar.GetComponent <RectTransform>().sizeDelta     = new Vector2(enemy.GetComponent <RectTransform>().rect.width, 13);
                        lifeBar.whenDamageValue = enemy.GetComponent <RectTransform>().rect.width;
                        lifeBar.setInstant(enemy.HP < 0 ? 0 : enemy.HP / (float)enemy.MaxHP);
                        lifeBar.setLerp(enemy.HP / (float)enemy.MaxHP, newHP / (float)enemy.MaxHP);
                        lifeBar.setVisible(true);
                        enemy.doDamage(Damage);
                    } catch { return; }
                }
                enemy.HandleAttack(Damage);
            }
            else
            {
                // finally, damage enemy and call its attack handler in case you wanna stop music on death or something
                shakeInProgress = true;
                waitingToFade   = true;
                needAgain       = false;
                totalShakeTime  = shakeX.Length * (1.5f / 8.0f);
                showedup        = true;
            }
        }
        else if (!slice.animcomplete)
        {
            slice.img.gameObject.GetComponent <RectTransform>().sizeDelta = new Vector2(slice.img.GetComponent <Image>().sprite.rect.width, slice.img.GetComponent <Image>().sprite.rect.height);
        }
    }
Example #30
0
 public static void PlaySound(string name, float volume = 0.65f)
 {
     try { UnitaleUtil.PlaySound("MusicPlaySound", AudioClipRegistry.GetSound(name), volume); }
     catch {  }
 }