コード例 #1
0
    // Because we can call to kill an object immediately, we've split it out from the collision function
    //
    public virtual void DoOnImpactFromPlayer(uint iDamage, bool bIsPlayerOption = false, bool bPlayerPhysicalCollision = false)
    {
        if (bIsPlayerOption && m_bIgnorePlayerOptionKills)
        {
            return;
        }

        GameInstance gi = GameInstance.Object;

        GAssert.Assert(null != gi, "Unable to get Game Instance!");

        m_iHitPointsRemaining = (int)MathUtil.Clamp(m_iHitPointsRemaining - (int)iDamage, 0, Types.s_iPLAYER_MaxDamage);
        if (m_iHitPointsRemaining <= 0)
        {
            PlayDeathEffects();;

            // Add optionals
            AddScore gcScore = GetComponent <AddScore>(); if (null != gcScore)
            {
                gcScore.AddScoreToPlayer();
            }
            UnlockAchievement gcAchievement = GetComponent <UnlockAchievement>(); if (null != gcAchievement)
            {
                gcAchievement.AddAchievement();
            }
            AddCameraShake gcShake = GetComponent <AddCameraShake>(); if (null != gcShake)
            {
                gcShake.AddShakeToCamera();
            }

            // BUT, we only spawn prefabs if we've been shot, not if it's a physical collision
            if (!bPlayerPhysicalCollision)
            {
                SpawnPrefab[] aPrefabSpawns = GetComponents <SpawnPrefab>();
                if (aPrefabSpawns.Length > 0)
                {
                    for (int i = 0; i < aPrefabSpawns.Length; ++i)
                    {
                        aPrefabSpawns[i].DoSpawnPrefab();
                    }
                }
            }

            // Die Die Die!
            Destroy(gameObject);
            return;
        }

        // Didn't die? Play the impact ting audio...
        if (m_bPlaySFXOnHit)
        {
            gi.GetAudioManager().PlayAudioAtLocation(transform.position, m_iSFX_Impact);
        }
    }
コード例 #2
0
    // Because we can call to kill an object immediately, we've split it out from the collision function
    //
    public override void DoOnImpactFromPlayer(uint iDamage, bool bIsPlayerOption = false, bool bPlayerPhysicalCollision = false)
    {
        if (m_bUpdateLoop || bIsPlayerOption)
        {
            return;
        }

        GameInstance gi = GameInstance.Object;

        GAssert.Assert(null != gi, "Unable to get Game Instance!");

        m_iHitPointsRemaining = (int)MathUtil.Clamp(m_iHitPointsRemaining - (int)iDamage, 0, Types.s_iPLAYER_MaxDamage);
        if (m_iHitPointsRemaining <= 0)
        {
            // Turn off the sprite and collider (Bespoke to the heart)
            GetComponent <SpriteRenderer>().enabled    = false;
            GetComponent <PolygonCollider2D>().enabled = false;

            // Move particles closer to camera, so they appear over everything
            Vector3 vPos = transform.position;
            vPos.z = Types.s_fPOS_FrontLayerZ;

            // Spawn the effects
            if (m_bPixelShatter)
            {
                SpriteToParticleSystem.ExplodeSprite(transform.position, Types.s_fVEL_PixelShatterVelocity, m_goPixelShatterPrefab, m_gcSprite, m_iPixelShatterTTL);
            }
            if (m_bPlaySFXOnDeath)
            {
                GameInstance.Object.GetAudioManager().PlayAudioAtLocation(transform.position, m_iSFX_Explosion);
            }
            if (m_bSpawnExplosionEffect && null != m_goExplosionPrefab)
            {
                Instantiate(m_goExplosionPrefab, transform.position, Quaternion.identity);
            }


            // Add optionals
            AddScore gcScore = GetComponent <AddScore>(); if (null != gcScore)
            {
                gcScore.AddScoreToPlayer();
            }
            AddCameraShake gcShake = GetComponent <AddCameraShake>(); if (null != gcShake)
            {
                gcShake.AddShakeToCamera();
            }

            SpawnPrefab[] aPrefabSpawns = GetComponents <SpawnPrefab>();
            if (aPrefabSpawns.Length > 0)
            {
                for (int i = 0; i < aPrefabSpawns.Length; ++i)
                {
                    aPrefabSpawns[i].DoSpawnPrefab();
                }
            }

            m_bUpdateLoop = true;
            GameMode.BeginCompletionSequence();
        }

        // Didn't die? Play the impact ting audio...
        if (m_bPlaySFXOnHit)
        {
            gi.GetAudioManager().PlayAudioAtLocation(transform.position, m_iSFX_Impact);
        }
    }
コード例 #3
0
    void Update()
    {
        if (m_gcPlayerAttractor.GetDistanceFromPlayer() <= m_fPickupDistance)
        {
            // Grab the optional components.
            //
            AddScore      gcScore       = GetComponent <AddScore>();
            AddMultiplier gcMult        = GetComponent <AddMultiplier>();
            AddPowerup    gcPowerUp     = GetComponent <AddPowerup>();
            PlayerState   gcPlayerState = GameInstance.Object.GetPlayerState();
            AddGameEvent  gcGameEvent   = GetComponent <AddGameEvent>();

            bool bDidAdd = false;

            // Call the relevant actions...
            //
            switch (m_iTriggerAction)
            {
            case Types.EPlayerPickupAction._NOTHING:
                break;

            case Types.EPlayerPickupAction._GIVE_SCORE_AND_MULTIPLIER:
                if (null != gcScore)
                {
                    bDidAdd = gcScore.AddScoreToPlayer();
                }
                if (null != gcMult)
                {
                    bDidAdd = gcMult.AddMultiplierToPlayer();
                }
                break;

            case Types.EPlayerPickupAction._GIVE_MULTIPLIER:
                if (null != gcMult)
                {
                    bDidAdd = gcMult.AddMultiplierToPlayer();
                }
                break;

            case Types.EPlayerPickupAction._GIVE_SCORE:
                if (null != gcScore)
                {
                    bDidAdd = gcScore.AddScoreToPlayer();
                }
                break;

            case Types.EPlayerPickupAction._GIVE_SCORE_AND_POWERUP:
                if (null != gcScore)
                {
                    bDidAdd = gcScore.AddScoreToPlayer();
                }
                if (null != gcPowerUp)
                {
                    bDidAdd = gcPowerUp.AddPowerupToPlayer();
                }
                break;

            case Types.EPlayerPickupAction._GIVE_POWERUP:
                if (null != gcPowerUp)
                {
                    bDidAdd = gcPowerUp.AddPowerupToPlayer();
                }
                break;

            case Types.EPlayerPickupAction._GIVE_LIFE:
                if (null != gcPlayerState)
                {
                    bDidAdd = gcPlayerState.AddLives(1);
                }
                break;

            case Types.EPlayerPickupAction._GAME_EVENT:
                if (null != gcGameEvent)
                {
                    bDidAdd = gcGameEvent.AddGameEventForPlayer();
                }
                break;

            case Types.EPlayerPickupAction._GIVE_KEY:
                if (null != gcGameEvent)
                {
                    bDidAdd = true;
                }
                if (null != gcGameEvent)
                {
                    bDidAdd = gcGameEvent.AddGameEventForPlayer();                                                      // Key prefab should also have an event attached!
                }
                GameInstance.Object.GetPlayerState().SpawnExitKey();
                break;
            }
            ;

            // Only play the feedbacks if add was successful
            if (bDidAdd)
            {
                GameInstance.Object.GetAudioManager().PlayAudioAtLocation(transform.position, m_iAudio);
                if (null != m_goPickupEffect)
                {
                    Instantiate(m_goPickupEffect, transform.position, Quaternion.identity);
                }
            }

            Destroy(gameObject);
        }
    }