Esempio n. 1
0
    public void OnCollisionEnter2D(Collision2D col)
    {
        // Kill the enemy if we've hit them...
        if (col.gameObject.CompareTag(Types.s_sTag_Enemy))
        {
            TrackHitPoints gc = col.gameObject.GetComponent <TrackHitPoints>();
            if (null != gc)
            {
                gc.DoKilledByEnvironment();
            }

            if (m_bKillEverything)
            {
                gc = GetComponent <TrackHitPoints>();
                GAssert.Assert(null != gc, "DestroyObstacleOnImpact called on go without a TrackHitPoints componetn!");
                gc.DoKilledByEnvironment();
            }
        }

        // Kill the enemy bullet if we've hit them...
        if (col.gameObject.CompareTag(Types.s_sTag_EnemyBullets))
        {
            Destroy(col.gameObject);

            if (m_bKillEverything)
            {
                TrackHitPoints gc = GetComponent <TrackHitPoints>();
                GAssert.Assert(null != gc, "DestroyObstacleOnImpact called on go without a TrackHitPoints componetn!");
                gc.DoKilledByEnvironment();
            }
        }
    }
Esempio n. 2
0
    virtual public void Spawn()
    {
        // Early outs...
        if (!m_bIsActive)
        {
            return;
        }
        if (!GameMode.PlayerIsAlive())
        {
            return;
        }
        if (TimerManager.IsPaused())
        {
            return;
        }

        // If we've spawned everything, DIE
        // This is mainly to prevent the player from cheesing the
        // object (through save/reload, when I do it) for infinite
        // points...
        if (m_iSpawnCount >= m_iMaxSpawn)
        {
            TrackHitPoints gc = GetComponent <TrackHitPoints>();
            if (null != gc)
            {
                gc.DoKilledByEnvironment();
            }
            else
            {
                Destroy(gameObject);
            }
            return;
        }

        // Spawn random prefab
        int iIndex = Random.Range(0, m_aSpawnPrefabs.Length);

        GAssert.Assert(null != m_aSpawnPrefabs[iIndex], "Spawner not setup with prefab at index " + iIndex.ToString());
        GameObject go = Instantiate(m_aSpawnPrefabs[iIndex], transform.position + m_vSpawnOffset, Quaternion.identity);

        // Tell it to go
        Types.IRoom_EnemyObject[] aGC = go.GetComponents <Types.IRoom_EnemyObject>();
        foreach (Types.IRoom_EnemyObject gc in aGC)
        {
            gc.OnRoomEnter();
        }

        // Add it to our list so we can kill everything on exit...
        m_aMyRoomObjects[m_iSpawnCount] = go;
        ++m_iSpawnCount;

        // New Spawn Timer
        m_iTimerHandle = TimerManager.AddTimer(Types.s_fDUR_ScreenTransitionDelay + Random.Range(m_fMinSpawnTime, m_fMaxSpawnTime), Spawn);
    }
Esempio n. 3
0
    private void Update()
    {
        // Player can die, so state might not exist...
        PlayerState gc = GameInstance.Object.GetPlayerState();

        if (null == gc)
        {
            return;
        }

        if (!gc.PlayerIsAlive())
        {
            if (null != m_gcHitPoints)
            {
                m_gcHitPoints.DoKilledByEnvironment();
            }
            else
            {
                Destroy(gameObject);
            }
        }
    }
Esempio n. 4
0
    // When the player has died we want to:
    // - Find all the live baddies
    // - Clear them
    // - Respawn them in positions away from where the player is respawned
    // - Continue...
    override public void OnPlayerHasDied(uint iPlayerLives)
    {
        // Get rid of the Update()
        m_bIsActive = false;

        // Clear next wave spawn timer
        if (m_iTimerHandle > 0)
        {
            TimerManager.ClearTimerHandler(m_iTimerHandle, SpawnWave);
        }

        // Clear the array of respawn positions
        m_aRespawnPositions.Clear();

        Vector2 vPos   = Vector3.zero;
        Vector2 vSpawn = GameMode.GetRespawnPosition();
        Vector2 vDist;
        bool    bChecking = true;

        foreach (GameObject go in m_aRoomObjects)
        {
            if (go != null)
            {
                // Find a random-ish point away from player respawn position...
                bChecking = true;
                do
                {
                    vPos  = new Vector2(Random.Range(-m_vHalfRoomBounds.x, m_vHalfRoomBounds.x), Random.Range(-m_vHalfRoomBounds.y, m_vHalfRoomBounds.y));
                    vPos += m_vRoomOrigin;
                    vDist = vSpawn - vPos;
                    if (vDist.magnitude > m_fDistanceFromPlayer)
                    {
                        bChecking = false;
                    }
                }while (bChecking);

                // Add this position to the list
                m_aRespawnPositions.Add(vPos);

                // Kill existing baddie
                TrackHitPoints gc = go.GetComponent <TrackHitPoints>();
                if (null != gc)
                {
                    gc.DoKilledByEnvironment();
                }
            }
        }


        // Tell any additional objects
        {
            foreach (GameObject go in m_aAdditionalObjects)
            {
                if (null == go)
                {
                    continue;
                }
                Types.IRoom_EnemyObject[] aGC = go.GetComponents <Types.IRoom_EnemyObject>();
                foreach (Types.IRoom_EnemyObject gc in aGC)
                {
                    gc.OnPlayerHasDied();
                }
            }
        }


        // Spawn a short warning icon...
        if (iPlayerLives > 0)
        {
            foreach (Vector3 vRPos in m_aRespawnPositions)
            {
                Instantiate(m_SpawnSet._goSpawnWarningEffectShort, vRPos, Quaternion.identity);
            }
        }
    }