Exemplo n.º 1
0
    // TODO PE: NOT EXPLOSION! SOMETHING COOL!
    IEnumerator ExplodeCo()
    {
        isExploding_ = true;

        while (true)
        {
            var pos = trans_.position;

            GameManager.Instance.MakeFlash(pos, new Color(0.4f, 0.4f, 0.2f), Radius * 1.5f);

            float force = 0.1f;

            int aliveCount = BlackboardScript.GetEnemies(pos, Radius);
            for (int i = 0; i < aliveCount; ++i)
            {
                int       idx   = BlackboardScript.Matches[i].Idx;
                ActorBase enemy = BlackboardScript.Enemies[idx];
                enemy.SetSlowmotion();
//                enemy.AddForce((enemy.transform.position - pos) * force);
            }

            // Kill player if very close, else just push
            float playerDist = BlackboardScript.DistanceToPlayer(pos);
            if (playerDist < Radius * 0.2f)
            {
                GameManager.Instance.PlayerScript.KillPlayer();
            }
            else if (playerDist < 1.0f)
            {
                GameManager.Instance.PlayerScript.AddForce((GameManager.Instance.PlayerTrans.position - pos) * 0.25f);
            }

            yield return(new WaitForSeconds(0.4f));
        }
    }
Exemplo n.º 2
0
    IEnumerator Think()
    {
        while (isSpawning_)
        {
            yield return(null);
        }

        const float DelayBeforeFirstCharge = 1.0f;
        float       nextCharge             = Time.time + DelayBeforeFirstCharge;

        while (true)
        {
            float       distanceToPlayer = BlackboardScript.DistanceToPlayer(position_);
            const float MinDistToCharge  = 3.0f;
            if (IsFullyReady && Time.time > nextCharge && distanceToPlayer > MinDistToCharge)
            {
                target_      = GameManager.Instance.PlayerTrans.position + (Vector3)(RndUtil.RandomInsideUnitCircle() * 2);
                target_      = GameManager.Instance.ClampToBounds(target_, renderer_.sprite);
                chargeSpeed_ = Speed * 5;
                if (chargeSpeed_ > 8.0f)
                {
                    chargeSpeed_ = 8.0f;
                }

                material_.color = ChargeColor;

                while ((transform_.position - target_).magnitude > 0.2f)
                {
                    if (Random.value < 0.1f)
                    {
                        GameManager.Instance.MakePoof(transform_.position + Vector3.down * 0.2f, 1, 0.3f);
                    }

                    yield return(null);
                }

                material_.color = Color.white;
                chargeSpeed_    = 0.0f;
                float cd = (1.0f + Random.value * 3) * GameMode.ChargeCdModifier;
                nextCharge = Time.time + cd;
            }

            yield return(null);
        }
    }
Exemplo n.º 3
0
    protected override void PreUpdate()
    {
        bool dead = Hp <= 0.0f;

        if (dead)
        {
            return;
        }

        if (Time.time > flashEndTime_)
        {
            material_.SetFloat(flashParamId_, 0.0f);

            bool closeToPlayer = BlackboardScript.DistanceToPlayer(position_) < 2.0f;
            if (closeToPlayer || isPainted_)
            {
                target_ = GameManager.Instance.PlayerTrans.position;
            }
            else
            {
                if (Vector3.Distance(position_, target_) < 0.25f)
                {
                    target_ = GetNewTarget();
                }
            }

            float deltaX = target_.x - transform_.position.x;
            float deltaY = target_.y - transform_.position.y;

            moveVec_.x = deltaX;
            moveVec_.y = deltaY;
            moveVec_.z = 0;
            moveVec_.Normalize();

            UpdatePosition(moveVec_, Speed);
        }

        Vector3 scale = scale_;

        scale.x = moveVec_.x < 0 ? -scale.x : scale.x;
        transform_.localScale = scale;
    }
Exemplo n.º 4
0
    void Update()
    {
        Text.enabled           = Mood == OrcMood.Nervous;
        renderer_.sortingOrder = Mathf.RoundToInt(trans_.position.y * 100f) * -1;

        playerPos_        = GameManager.Instance.PlayerTrans.position;
        distanceToPlayer_ = BlackboardScript.DistanceToPlayer(trans_.position);
        playerIsClose_    = distanceToPlayer_ < 3.0f;
        targetVec_        = target_ - trans_.position;
        targetDir_        = targetVec_.normalized;
        distanceToTarget_ = targetVec_.magnitude;

        Vector3 arrowPos = arrow_.localPosition;

        arrowPos.y           = 1.0f + Mathf.Sin(Time.time * 8) * 0.25f;
        arrow_.localPosition = arrowPos;

        if (distanceToTarget_ > 0.1f)
        {
            trans_.position += targetDir_ * RunSpeed * Time.deltaTime;
        }
    }
Exemplo n.º 5
0
    IEnumerator ExplodeCo(float delay)
    {
        float explodeTime = Time.time + delay;
        float flashOffset = UnityEngine.Random.value;

        while (Time.time < explodeTime)
        {
            material_.SetFloat(flashParamId_, 0.6f + (Mathf.Sin(((Time.time + flashOffset) * 10) + 1.0f) * 0.5f) * 0.25f);
            yield return(null);
        }

        const float ExplodeRadius = 3.0f;

        AudioManager.Instance.PlayClipWithRandomPitch(AudioManager.Instance.MiscAudioSource, AudioManager.Instance.AudioData.LivingBombExplode);
        GameManager.Instance.MakeCircle(transform_.position, ExplodeRadius);
        GameManager.Instance.MakePoof(transform_.position, 2, ExplodeRadius * 0.2f);
        GameManager.Instance.ShakeCamera(0.4f);

        int  aliveCount = BlackboardScript.GetEnemies(transform_.position, ExplodeRadius);
        bool isFirstHit = true;

        for (int i = 0; i < aliveCount; ++i)
        {
            int       idx   = BlackboardScript.Matches[i].Idx;
            ActorBase enemy = BlackboardScript.Enemies[idx];
            if (enemy != this)
            {
                enemy.OnLivingBombHit(livingBombDamage_ * 0.9f, isFirstHit);
                isFirstHit = false;
            }
        }

        if (BlackboardScript.DistanceToPlayer(transform_.position) < ExplodeRadius * 0.5f)
        {
            GameManager.Instance.PlayerScript.KillPlayer();
        }

        ApplyDamage(livingBombDamage_, RndUtil.RandomInsideUnitCircle().normalized, 0.25f, true);
    }
Exemplo n.º 6
0
    IEnumerator ThrowCo(Vector3 from, Vector3 to)
    {
        shadowRenderer_.enabled = false;
        var fuseEmission = fuseParticles_.emission;

        fuseEmission.enabled = true;

        float length    = (to - from).magnitude;
        float force     = Mathf.Min(5.0f, length);
        float velocityY = 1.0f * force;
        float downForce = -25.0f;
        float speed     = 5.0f * force;

        float   fuseT0  = Time.time;
        float   fuseT1  = fuseT0 + FuseTime;
        Vector3 dir     = (to - from).normalized;
        Vector3 pos     = from;
        float   offsetY = 0;

        audioSource_.clip   = AudioManager.Instance.AudioData.BombFuseBurn;
        audioSource_.volume = 0.5f * AudioManager.Instance.MasterVolume;
        audioSource_.Play();

        while (Time.time < fuseT1)
        {
            float delta = Time.deltaTime;

            Vector3 showPos = pos;
            showPos.y                 += offsetY;
            trans_.position            = showPos;
            bombRenderer_.sortingOrder = (Mathf.RoundToInt(trans_.position.y * 100f));
            bombMaterial_.SetFloat(flashParamId_, (Mathf.Sin((Time.time * 15) + 1.0f) * 0.5f) * 0.75f);

            offsetY   += velocityY * delta;
            velocityY += downForce * delta;
            if (offsetY <= 0)
            {
                shadowRenderer_.enabled = true;
                velocityY = -velocityY * 0.5f;
            }

            pos   += dir * speed * Time.deltaTime;
            speed *= 1.0f - (5.0f * delta);

            yield return(null);
        }

        fuseEmission.enabled = false;

        audioSource_.clip   = AudioManager.Instance.AudioData.BombExplode;
        audioSource_.volume = 1.0f * AudioManager.Instance.MasterVolume;
        audioSource_.Play();
        GameManager.Instance.MakeFlash(pos, Radius * 1.5f);
        GameManager.Instance.MakePoof(pos, 6, Radius * 1.5f);
        GameManager.Instance.ShakeCamera(4.0f);

        int deadCount = BlackboardScript.GetDeadEnemies(pos, Radius);

        for (int i = 0; i < deadCount; ++i)
        {
            int       idx   = BlackboardScript.Matches[i].Idx;
            ActorBase enemy = BlackboardScript.DeadEnemies[idx];
            enemy.AddForce((enemy.transform.position - pos) * 0.25f);
//            enemy.Explode(2.0f + Random.value * 2);
        }

        int aliveCount = BlackboardScript.GetEnemies(pos, Radius);

        for (int i = 0; i < aliveCount; ++i)
        {
            int       idx   = BlackboardScript.Matches[i].Idx;
            ActorBase enemy = BlackboardScript.Enemies[idx];
            enemy.ApplyDamage(Damage, enemy.transform.position - pos, 1.0f, true);
        }

        for (int i = 0; i < 10; ++i)
        {
            Vector2 rnd      = RndUtil.RandomInsideUnitCircle() * Radius * 0.5f;
            Vector3 flamePos = pos;
            flamePos.x += rnd.x;
            flamePos.y += rnd.y;
            GameManager.Instance.EmitFlame(flamePos, Random.value + 0.5f);
            yield return(null);
        }

        // Kill player if very close, else just push
        float playerDist = BlackboardScript.DistanceToPlayer(pos);

        if (playerDist < 3.0f)
        {
            GameManager.Instance.PlayerScript.AddForce((GameManager.Instance.PlayerTrans.position - pos) * 0.1f);
        }

        Hide();
    }
Exemplo n.º 7
0
    IEnumerator Think()
    {
        while (isSpawning_)
        {
            yield return(null);
        }

        const float DelayBeforeFirstShoot = 1.0f;
        float       nextShoot             = Time.time + DelayBeforeFirstShoot;

        while (true)
        {
            float       distanceToPlayer = BlackboardScript.DistanceToPlayer(position_);
            const float MinDistToShoot   = 4.0f;
            if (IsFullyReady && Time.time > nextShoot && distanceToPlayer > MinDistToShoot)
            {
                int projectileCount = 5 + SaveGame.RoundScore / 15;
                projectileCount = Mathf.RoundToInt(projectileCount * GameMode.FireCountModifier);
                if (projectileCount > 12)
                {
                    projectileCount = 12;
                }
                if (projectileCount < 1)
                {
                    projectileCount = 1;
                }

                for (int i = 0; i < projectileCount; ++i)
                {
                    Shoot();
                    GameManager.Instance.MakeFlash(position_, 1.0f);
                    yield return(new WaitForSeconds(0.25f * GameMode.FireRateModifier));
                }
                nextShoot = Time.time + cd;
                cd        = (Cd + Random.value) * GameMode.FireRateModifier;
            }

            if (distanceToPlayer < 8.0f)
            {
                target_   = GameManager.Instance.PlayerTrans.position;
                target_.x = -target_.x;
                target_.y = -target_.y;
                target_   = GameManager.Instance.ClampToBounds(target_, renderer_.sprite);
            }
            else
            {
                if (Vector3.Distance(position_, target_) < 0.25f)
                {
                    target_ = GetNewTarget();
                }
            }

            float deltaX = target_.x - transform_.position.x;
            float deltaY = target_.y - transform_.position.y;

            moveVec_.x = deltaX;
            moveVec_.y = deltaY;
            moveVec_.z = 0;
            moveVec_.Normalize();

            UpdatePosition(moveVec_, Speed);
            yield return(null);
        }
    }