Ejemplo n.º 1
0
    IEnumerator <float> DieCo(Vector3 damageForce)
    {
        DoFlash(-0.25f, 100.0f);
        IsDead                      = true;
        gameObject.layer            = SceneGlobals.Instance.DeadEnemyLayer;
        SpriteRenderer.sortingOrder = SceneGlobals.Instance.OnTheFloorSortingValue;
        body_.freezeRotation        = false;
        body_.velocity              = Vector3.zero;
        body_.AddForce(damageForce * 10, ForceMode2D.Impulse);
        float angularVelocityVariation = 1.4f - Random.value * 0.8f;

        body_.angularVelocity  = (damageForce.x > 0 ? -300 : 300) * damageForce.magnitude * angularVelocityVariation;
        BlipRenderer.enabled   = false;
        LightRenderer.enabled  = false;
        ShadowRenderer.enabled = false;

        ParticleScript.EmitAtPosition(ParticleScript.Instance.DeathFlashParticles, transform_.position, 2);
        AudioManager.Instance.PlaySfxClip(DeathSound, maxInstances: 8, DeathSoundPitchVariation, DeathSoundPitch);
        SceneGlobals.Instance.CameraShake.SetMinimumShake(0.6f);

        float endTime = Time.unscaledTime + 2.0f;

        while (Time.unscaledTime < endTime)
        {
            float velocity = body_.velocity.sqrMagnitude;
            if (velocity > 0.02f & Random.value < 0.1f)
            {
                ParticleScript.EmitAtPosition(ParticleScript.Instance.MuzzleSmokeParticles, transform_.position, 2);
            }

            yield return(0);
        }
    }
Ejemplo n.º 2
0
    public void OnPoke()
    {
        if (scythesEnabled_)
        {
            return;
        }

        GameEvents.RaiseQuestEvent(QuestEvent.ReaperAnnoyed);

        CurrentRunData.Instance.ShopKeeperPokeCount++;
        int scytheCount = CurrentRunData.Instance.ShopKeeperPokeCount + 1;

        if (scytheCount > Scythes.Length)
        {
            scytheCount = Scythes.Length;
        }

        for (int i = 0; i < scytheCount; ++i)
        {
            if (i != 0 && Random.value < 0.1f)
            {
                continue;
            }

            var     scythe = Scythes[i];
            Vector3 offset = Random.insideUnitCircle * 1.0f;
            scythe.transform.position += offset;
            scythe.SetActive(true);
            ParticleScript.EmitAtPosition(ParticleScript.Instance.PlayerLandParticles, scythe.transform.position, 5);
        }

        AudioManager.Instance.PlaySfxClip(ShopKeeperAggroSound, 1);

        scythesEnabled_ = true;
    }
Ejemplo n.º 3
0
    public void TakeDamage(IEnemy enemy, int amount, Vector3 damageForce, IEffect effect = null)
    {
        if (IsDead)
        {
            return;
        }
        if (effect != null)
        {
            Effects.Add(effect);
        }
        AudioManager.Instance.PlaySfxClip(TakeDamageSound, 1);
        DoFlash(2, 0.3f);
        ParticleScript.EmitAtPosition(ParticleScript.Instance.DeathFlashParticles, transform_.position, 2);
        FloatingTextSpawner.Instance.Spawn(transform_.position + Vector3.up, $"-{amount.ToString()}", Color.red, speed: 1.0f, timeToLive: 1.0f);

        AddPlayerHealthEvent(-amount, enemy.Name);

        Life = Mathf.Max(0, Life - amount);
        GameEvents.RaisePlayerDamaged(enemy);

        UpdateHealth();
        if (Life == 0)
        {
            KilledBy      = enemy.Name;
            KilledByEnemy = enemy;
            Die();
            GameEvents.RaisePlayerKilled(enemy);
        }
    }
Ejemplo n.º 4
0
    IEnumerator <float> FireCo()
    {
        isFiring_ = true;

        while (true)
        {
            for (int i = 0; i < GunSettings.BurstCount; ++i)
            {
                var direction = latestFiringDirection_;
                var position  = transform_.position + direction * 0.5f;

                var angleOffsets = GetFiringAngleOffsets(GunSettings.FiringSpread, 1.0f);
                int bulletCount  = angleOffsets.Length;
                if (!ammoProvider_.TryUseAmmo(AmmoType, bulletCount))
                {
                    yield break;
                }

                for (int j = 0; j < bulletCount; ++j)
                {
                    float precisionPenalty = Mathf.Min(0.75f, Mathf.Max(0, -0.5f + penalty_ * 0.8f));
                    float precision        = GunSettings.Precision - precisionPenalty;

                    float       angleOffset = angleOffsets[j];
                    const float MaxDegreesOffsetAtLowestPrecision = 30.0f;
                    angleOffset += (Random.value - 0.5f) * (1.0f - precision) * MaxDegreesOffsetAtLowestPrecision;
                    var offsetDirection = Quaternion.AngleAxis(angleOffset, Vector3.forward) * direction;
                    Fire(position, offsetDirection);
                }

                latestFiringTime_ = Time.unscaledTime;

                audioManager_.PlaySfxClip(FireSound, 1, FireSoundPitchVariation, FireSoundPitch);
                cameraShake_.SetMinimumShake(0.75f);

                forceReceiver_.SetMinimumForce(-direction * Recoil);

                var particleCenter = position + direction * 0.3f;
                ParticleScript.EmitAtPosition(SceneGlobals.Instance.ParticleScript.MuzzleFlashParticles, particleCenter, 1);
                ParticleScript.EmitAtPosition(SceneGlobals.Instance.ParticleScript.MuzzleSmokeParticles, particleCenter, 5);

                float timePenalty = Mathf.Min(0.2f, Mathf.Max(0, -0.5f + penalty_ * 0.4f));
                float waitEndTime = Time.realtimeSinceStartup + GunSettings.TimeBetweenShots + timePenalty;
                while (Time.realtimeSinceStartup < waitEndTime)
                {
                    yield return(0);
                }

                penalty_ = Mathf.Min(2.0f, penalty_ + 0.1f);
            }

            bool continueFiring = GunSettings.FiringMode == FiringMode.Auto && triggerIsDown_;
            if (!continueFiring)
            {
                break;
            }
        }

        isFiring_ = false;
    }
Ejemplo n.º 5
0
    public void OnTriggerDown(Vector3 firingDirection)
    {
        if (Time.unscaledTime < cd_ || awaitingRelease_)
        {
            return;
        }

        if (!ammoProvider_.TryUseAmmo(AmmoType, 1))
        {
            return;
        }

        cd_ = Time.unscaledTime + Cooldown;
        awaitingRelease_ = true;

        LatestFiringDirection    = firingDirection;
        LatestFiringTimeUnscaled = Time.unscaledTime;

        var position = transform_.position + firingDirection * 0.5f;

        Fire(position, firingDirection);
        forceReceiver_.SetMinimumForce(-firingDirection * 3);

        var particleCenter = transform_.position + firingDirection * 0.5f;

        ParticleScript.EmitAtPosition(SceneGlobals.Instance.ParticleScript.MuzzleFlashParticles, particleCenter, 1);
        ParticleScript.EmitAtPosition(SceneGlobals.Instance.ParticleScript.MuzzleSmokeParticles, particleCenter, 10);
        audioManager_.PlaySfxClip(FireSound, 2, FireSoundPitchVariation, FireSoundPitch);
        cameraShake_.SetMinimumShake(1.0f);
    }
Ejemplo n.º 6
0
 void Die()
 {
     ParticleScript.EmitAtPosition(SceneGlobals.Instance.ParticleScript.BulletFizzleParticles, position_, 10);
     ParticleScript.EmitAtPosition(SceneGlobals.Instance.ParticleScript.MuzzleFlashParticles, position_, 1);
     ParticleScript.EmitAtPosition(SceneGlobals.Instance.ParticleScript.MuzzleSmokeParticles, position_, 10);
     SceneGlobals.Instance.EnemyBullet1Pool.ReturnToPool(this.gameObject);
 }
Ejemplo n.º 7
0
 public void Die()
 {
     DoFlash(0, 0);
     ParticleScript.EmitAtPosition(ParticleScript.Instance.DeathFlashParticles, transform_.position, 4);
     IsDead = true;
     SetIsHumanControlled(false);
     CameraShake.Instance.SetMinimumShake(0.8f);
 }
Ejemplo n.º 8
0
    private IEffect FireArrowEffect(Vector3 pos)
    {
        MapScript.Instance.TriggerExplosion(pos, worldRadius: 1.9f, damageWallsOnly: false, me_);

        ParticleScript.EmitAtPosition(ParticleScript.Instance.WallDestructionParticles, pos, 10);
        ParticleScript.EmitAtPosition(ParticleScript.Instance.MuzzleFlashParticles, pos, 1);
        ParticleScript.EmitAtPosition(ParticleScript.Instance.PlayerLandParticles, pos, 10);
        return(new NoEffect());
    }
Ejemplo n.º 9
0
 void Die()
 {
     ParticleScript.EmitAtPosition(SceneGlobals.Instance.ParticleScript.BulletFizzleParticles, position_, 4);
     SceneGlobals.Instance.EnemyBullet1Pool.ReturnToPool(this.gameObject);
     if (CollisionAction != null)
     {
         CollisionAction(transform_.position);
     }
 }
Ejemplo n.º 10
0
    IEnumerator AI()
    {
        float baseSpeed = movable_.GetSpeed();

        while (true)
        {
            var pos       = movable_.GetPosition();
            var direction = CollisionUtil.GetRandomFreeDirection(pos) * (Random.value * 0.8f + 0.1f);
            movable_.MoveTo(pos + direction);

            float endTime = Time.time + 4 + Random.value;
            while (true)
            {
                if (me_.IsDead)
                {
                    float explosionDelay = Time.time + 2.0f + Random.value * 0.25f;
                    while (Time.time < explosionDelay)
                    {
                        bool flashOn = ((int)(Time.time * 10) & 1) == 0;
                        me_.DoFlash(flashOn ? 0.0f : 10.0f, 1000);

                        yield return(null);
                    }

                    me_.DoFlash(-0.25f, 0);

                    var deathPos = movable_.GetCenter();
                    MapScript.Instance.TriggerExplosion(deathPos, worldRadius: 1.9f, damageWallsOnly: false, me_);

                    ParticleScript.EmitAtPosition(ParticleScript.Instance.WallDestructionParticles, deathPos, 10);
                    ParticleScript.EmitAtPosition(ParticleScript.Instance.MuzzleFlashParticles, deathPos, 1);
                    ParticleScript.EmitAtPosition(ParticleScript.Instance.PlayerLandParticles, deathPos, 10);
                    yield break;
                }

                float time = Time.time;
                CheckFire(time);

                if (movable_.MoveTargetReached() || time > endTime)
                {
                    break;
                }

                yield return(null);
            }

            yield return(null);
        }
    }
Ejemplo n.º 11
0
    public void ActivateQuest(QuestId id)
    {
        QuestGiverScript.Instance.Close();
        activatedQuest_ = id;

        var pos = QuestPortal.transform.position;

        mapAccess_.TriggerExplosion(QuestPortal.transform.position, 2.9f);
        var portalCenter = pos + Vector3.up * 1.5f;

        ParticleScript.EmitAtPosition(ParticleScript.Instance.PlayerLandParticles, portalCenter, 25);
        ParticleScript.EmitAtPosition(ParticleScript.Instance.MuzzleFlashParticles, portalCenter, 1);
        ParticleScript.EmitAtPosition(ParticleScript.Instance.WallDestructionParticles, portalCenter, 10);
        QuestPortal.SetActive(true);
    }
Ejemplo n.º 12
0
    IEnumerator <float> AICo()
    {
        Activate(true);
        collider_.enabled = false;

        transform_.position = Vector3.right * 1000;
        while (!run_)
        {
            yield return(0);
        }

        yield return(Timing.WaitForSeconds(spawnDelay_ + Random.value * 0.5f));

        var basePos     = AiBlackboard.Instance.PlayerPosition;
        var startOffset = new Vector3(0, 0, -12);

        SceneGlobals.Instance.AudioManager.PlaySfxClip(SceneGlobals.Instance.AudioManager.AudioClips.PlayerLand, 3, 0.1f, 1.8f);

        float t = 1;

        while (t >= 0)
        {
            CameraShake.Instance.SetMinimumShake(0.3f);

            var pos = basePos + startOffset * t;
            transform_.SetPositionAndRotation(pos, Quaternion.Euler(0, 0, t * 500));

            t -= Time.unscaledDeltaTime * 2f;
            yield return(0);
        }

        transform_.SetPositionAndRotation(basePos, Quaternion.identity);
        MapScript.Instance.TriggerExplosion(transform_.position, 2.5f);
        ParticleScript.EmitAtPosition(SceneGlobals.Instance.ParticleScript.WallDestructionParticles, basePos, 10);
//        SceneGlobals.Instance.AudioManager.PlaySfxClip(SceneGlobals.Instance.AudioManager.AudioClips.LargeExplosion1, 3, 0.1f, 1.2f);
//      SceneGlobals.Instance.CameraShake.SetMinimumShake(1.0f);

        collider_.enabled = true;

        while (true)
        {
            bool recentlySeenPlayer = mySenses_.GetPlayerLatestKnownPositionAge() < 2.0f;
            myMovement_.MoveTo(AiBlackboard.Instance.PlayerPosition);
            yield return(Timing.WaitForSeconds(0.05f));
        }
    }
Ejemplo n.º 13
0
    IEnumerator <float> WanderCo(float startDelay)
    {
        if (!path_.HasPath)
        {
            yield break;
        }

        yield return(Timing.WaitForSeconds(startDelay));

        float t    = 0;
        float endT = path_.EndT;

        while (true)
        {
            var oldPos = transform_.position;
            var newPos = path_.GetPosAtTime(t);
            transform_.position = newPos;

            var  movement  = newPos - oldPos;
            bool flipX     = movement.x < 0;
            bool isRunning = movement.sqrMagnitude > 0.01f * 0.01f;
            renderer_.sprite = SimpleSpriteAnimator.GetAnimationSprite(isRunning ? Anim.Run : Anim.Idle, Anim.DefaultAnimationFramesPerSecond);
            renderer_.flipX  = flipX;

            if (t == 0)
            {
                ParticleScript.EmitAtPosition(ParticleScript.Instance.PlayerLandParticles, newPos, 5);
                ParticleScript.EmitAtPosition(ParticleScript.Instance.WallDestructionParticles, newPos, 5);
                ParticleScript.EmitAtPosition(ParticleScript.Instance.MuzzleFlashParticles, newPos, 1);
            }

            t += Time.unscaledDeltaTime;
            if (t >= endT)
            {
                ParticleScript.EmitAtPosition(ParticleScript.Instance.PlayerLandParticles, newPos, 5);
                ParticleScript.EmitAtPosition(ParticleScript.Instance.WallDestructionParticles, newPos, 5);
                ParticleScript.EmitAtPosition(ParticleScript.Instance.MuzzleFlashParticles, newPos, 1);

                gameObject.SetActive(false);
                yield break;
            }

            yield return(0);
        }
    }
Ejemplo n.º 14
0
    public void TakeDamage(int amount, Vector3 damageForce)
    {
        gameObject.SetActive(false);

        var pos = transform_.position;

        LootDropScript.Instance.SpawnCoins(20, pos);
        ParticleScript.EmitAtPosition(ParticleScript.Instance.PlayerLandParticles, pos, 5);
        ParticleScript.EmitAtPosition(ParticleScript.Instance.GoldParticles, pos, 10);
        ParticleScript.EmitAtPosition(ParticleScript.Instance.WallDestructionParticles, pos, 5);
        ParticleScript.EmitAtPosition(ParticleScript.Instance.MuzzleFlashParticles, pos, 1);
        MapScript.Instance.TriggerExplosion(pos, 1.9f, damageWallsOnly: false);

        bool spawnEnemy = Random.value < 0.5f;

        enemy.transform.SetPositionAndRotation(transform_.position, Quaternion.identity);
        enemy.SetActive(spawnEnemy);
    }
Ejemplo n.º 15
0
    public void SetIsHumanControlled(bool isHumanControlled, RigidbodyConstraints2D constraints = RigidbodyConstraints2D.FreezeRotation, bool showChangeEffect = false)
    {
        bool noChange = isHumanControlled == isHumanControlled_;

        if (noChange)
        {
            return;
        }

        isHumanControlled_             = isHumanControlled;
        humanPlayerController_.enabled = isHumanControlled_;
        body_.constraints = constraints;
        if (showChangeEffect && isHumanControlled)
        {
            ParticleScript.EmitAtPosition(SceneGlobals.Instance.ParticleScript.CharacterSelectedParticles, transform_.position + Vector3.up * 0.5f, 30);
        }

        RefreshInteracting();
    }
Ejemplo n.º 16
0
    public void OnTriggerDown(Vector3 firingDirection)
    {
        if (Time.unscaledTime < cd_ || awaitingRelease_)
        {
            return;
        }

        if (!ammoProvider_.TryUseAmmo(AmmoType, BulletCount))
        {
            return;
        }

        cd_ = Time.unscaledTime + Cooldown;
        awaitingRelease_ = true;

        LatestFiringDirection    = firingDirection;
        LatestFiringTimeUnscaled = Time.unscaledTime;

        float angle             = -AngleSpread * 0.5f;
        float angleStep         = AngleSpread / (BulletCount - 1);
        float angleMaxVariation = 10;

        for (int j = 0; j < BulletCount; ++j)
        {
            float positionRandomOffset = Random.value * 0.35f;
            var   position             = transform_.position + firingDirection * (0.375f + positionRandomOffset);

            float angleOffset = angle + Random.value * angleMaxVariation;
            angle += angleStep;
            var offsetDirection = Quaternion.AngleAxis(angleOffset, Vector3.forward) * firingDirection;
            Fire(position, offsetDirection);

            forceReceiver_.SetMinimumForce(-firingDirection * 3);
        }

        var particleCenter = transform_.position + firingDirection * 0.5f;

        ParticleScript.EmitAtPosition(SceneGlobals.Instance.ParticleScript.MuzzleFlashParticles, particleCenter, 1);
        ParticleScript.EmitAtPosition(SceneGlobals.Instance.ParticleScript.MuzzleSmokeParticles, particleCenter, 5);
        audioManager_.PlaySfxClip(FireSound, 1, 0.1f);
        cameraShake_.SetMinimumShake(0.75f);
    }
Ejemplo n.º 17
0
    void ExecuteBuy(ShopItemId id, int displayIdx)
    {
        var item = allItems_.Where(i => i.Id == id).Single();

        if (!AcceptBuy(item.Price))
        {
            return;
        }

        var player = PlayableCharacters.GetPlayerInScene();

        switch (id)
        {
        case ShopItemId.Item1Health:
            bool isOverheal = player.Life == player.MaxLife;
            if (isOverheal)
            {
                FloatingTextSpawner.Instance.Spawn(transform.position + Vector3.up * 0.5f, "Hah!", Color.white);
            }
            player.AddHealth(1, "Shop Item");
            break;

        case ShopItemId.IncreaseMaxHp1:
            player.AddMaxHealth(1);
            break;

        default:
            print("Not implemented: " + id);
            break;
        }

        CurrentRunData.Instance.ItemsBought++;

        var display = Displays[displayIdx];

        ParticleScript.EmitAtPosition(ParticleScript.Instance.PlayerLandParticles, display.transform.position, 5);
        ParticleScript.EmitAtPosition(ParticleScript.Instance.MuzzleFlashParticles, display.transform.position, 1);
        display.SetActive(false);
        GameSceneLogic.Instance.UpdateCoinWidget();
    }
Ejemplo n.º 18
0
 void Die()
 {
     ParticleScript.EmitAtPosition(SceneGlobals.Instance.ParticleScript.BulletFizzleParticles, position_, 4);
     SceneGlobals.Instance.ElongatedBulletPool.ReturnToPool(this.gameObject);
 }
Ejemplo n.º 19
0
    // When destroying walls some colliders are left behind. Fix should be incoming:
    // https://github.com/Unity-Technologies/2d-extras/issues/34
    public void TriggerExplosion(Vector3 worldPosition, float worldRadius, bool damageWallsOnly = true, IEnemy explosionSource = null, bool damageSelf = true)
    {
        int tilesChecked = MapUtil.ClearCircle(this, mapStyle_, worldPosition, worldRadius);

        WallCompositeCollider.generationType = CompositeCollider2D.GenerationType.Manual;
        int tilesCleared = 0;

        for (int i = 0; i < tilesChecked; ++i)
        {
            bool wasDestroyed = MapUtil.LatestResultFlags[i];
            if (wasDestroyed)
            {
                tilesCleared++;
            }

            if (wasDestroyed || !damageWallsOnly)
            {
                var tile = MapUtil.LatestResultPositions[i];

                // Show effect a bit above wall tile center since they also have a top
                const float EffectOffset = 0.5f;
                var         tileWorldPos = WallTileMap.GetCellCenterWorld(tile) + Vector3.up * EffectOffset;
                ParticleScript.EmitAtPosition(SceneGlobals.Instance.ParticleScript.AnimatedFireParticles, tileWorldPos, 3);
            }
        }

        if (!damageWallsOnly)
        {
            var   player    = PlayableCharacters.GetPlayerInScene();
            var   playerPos = player.GetPosition();
            float playerDistanceFromExplosion = (worldPosition - playerPos).magnitude;
            bool  damagePlayer = playerDistanceFromExplosion < worldRadius * 0.8f;
            if (damagePlayer)
            {
                player.TakeDamage(explosionSource, CurrentRunData.Instance.PlayerExplosionDamage, Vector3.zero);
            }

            int mask  = SceneGlobals.Instance.EnemyDeadOrAliveMask;
            int count = Physics2D.OverlapCircleNonAlloc(worldPosition, worldRadius * 0.9f, TempColliderResult, mask);
            for (int i = 0; i < count; ++i)
            {
                var enemyGO = TempColliderResult[i];
                var enemy   = enemyGO.GetComponent <IEnemy>();

                bool isSelf = enemy == explosionSource;
                bool skipDueToSelfDamage = isSelf && !damageSelf;
                if (enemy != null && !skipDueToSelfDamage)
                {
                    var diff      = enemyGO.transform.position - worldPosition;
                    var direction = diff.normalized;
                    enemy.TakeDamage(ExplosionDamageToEnemies, direction * 1.5f);
                }
            }
        }

        SceneGlobals.Instance.AudioManager.PlaySfxClip(SceneGlobals.Instance.AudioManager.AudioClips.LargeExplosion1, 1, 0.1f);
        SceneGlobals.Instance.CameraShake.SetMinimumShake(1.0f);

        WallCompositeCollider.generationType = CompositeCollider2D.GenerationType.Synchronous;
        TilemapCollider.enabled = false;
        TilemapCollider.enabled = true;
    }