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(); } } }
// Let TrackHitPoints handle our death... // private void KillInstant(Collision2D collision) { TrackHitPoints gc = GetComponent <TrackHitPoints>(); GAssert.Assert(null != gc, "DestroyOnImpact, no TrackHitPoints component on this gameObject!"); gc.KillInstant(); this.enabled = false; }
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); }
override public void OnPlayerHasDied() { m_bBehaviourCanUpdate = false; TrackHitPoints gc = GetComponent <TrackHitPoints>(); if (null != gc) { gc.PlayDeathEffects(); } base.OnReset(); }
virtual public void OnPlayerHasDied() { m_bBehaviourCanUpdate = false; // Explode... TrackHitPoints gc = GetComponent <TrackHitPoints>(); if (null != gc) { gc.PlayDeathEffects(); } // Hide... m_gcRenderer.enabled = false; }
public void OnTriggerEnter2D(Collider2D col) { // Destroy Enemy bullets if (col.gameObject.CompareTag(Types.s_sTag_EnemyBullets)) { Destroy(col.gameObject); } // Pass max damage to anything else... TrackHitPoints gc = col.gameObject.GetComponent <TrackHitPoints>(); if (null != gc) { gc.DoOnImpactFromPlayer(Types.s_iPLAYER_MaxDamage, true); return; } }
override protected void Awake() { base.Awake(); // Validate! { m_gcGameInstance = GameInstance.Object; GAssert.Assert(null != m_gcGameInstance, "Unable to get GameInstance!"); m_goPlayer = m_gcGameInstance.GetPlayerObject(); GAssert.Assert(null != m_goPlayer, "Unable to get player!"); BulletMovementSpark gc = m_BulletPrefab.GetComponent <BulletMovementSpark>(); GAssert.Assert(null != gc, "Baby Enforcer Gun must have bullets of type BulletMovementSpark"); m_gcHealth = GetComponent <TrackHitPoints>(); GAssert.Assert(null != m_gcHealth, "Unable to get health!"); } }
// Move the object // private void FixedUpdate() { if (TimerManager.IsPaused()) { return; } if (!GameMode.PlayerIsAlive()) { return; } // Check for room bounds if (transform.position.x >= m_vRoomBounds.x || transform.position.x <= -m_vRoomBounds.x) { m_vTraj.x *= -1; ++m_iBounceCount; } if (transform.position.y + 0.06f >= m_vRoomBounds.y || transform.position.y + 0.06f <= -m_vRoomBounds.y) { m_vTraj.y *= -1; ++m_iBounceCount; } if (m_iBounceCount >= m_iKillAfterNumBounces) { TrackHitPoints gc = GetComponent <TrackHitPoints>(); GAssert.Assert(null != gc, "DestroyOnImpact, no TrackHitPoints component on this gameObject!"); gc.KillInstant(); this.enabled = false; } else { m_gcRgdBdy.MovePosition(transform.position + ((m_vTraj * m_fMovementSpeed) * TimerManager.fFixedDeltaTime)); } }
protected new void Update() { if (!m_bIsActive) { return; } if (null == m_goPlayerObject) { return; } if (TimerManager.IsPaused()) { return; } Vector3 vDist = m_goPlayerObject.transform.position - transform.position; m_bPlayerInRange = false; // If we're respecting colliders, then we need to have raycast line-of-sight to the player if (m_bRespectColliders) { RaycastHit2D Hit = Physics2D.Raycast(transform.position + (vDist.normalized * m_fRaycastOffset), vDist.normalized, (m_fTriggerDistance - m_fRaycastOffset)); Debug.DrawRay(transform.position + (vDist.normalized * 0.12f), vDist.normalized * (m_fTriggerDistance - m_fRaycastOffset)); if (null != Hit.collider && Hit.collider.CompareTag("Player")) { m_bPlayerInRange = true; } } // Otherwise just explode if we're close enough! else if (vDist.magnitude <= m_fTriggerDistance) { m_bPlayerInRange = true; } if (m_bPlayerInRange) { // Tell the mine to start the countdown to explode ExplodingMine gcMine = GetComponent <ExplodingMine>(); if (null != gcMine) { gcMine.StartExplosionCountdown(); } // Change to the active material, if present SpriteRenderer gcRenderer = GetComponent <SpriteRenderer>(); if (null != m_gcActiveMaterial && null != gcRenderer) { gcRenderer.material = m_gcActiveMaterial; } // If we've been triggered, don't let the player destroy the mine TrackHitPoints gcHitP = GetComponent <TrackHitPoints>(); if (null != gcHitP) { gcHitP.enabled = false; } // Work here is done... this.enabled = false; } }
// 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); } } }
private void Awake() { m_gcHitPoints = GetComponent <TrackHitPoints>(); }
// Pay audio / effects, and return to the pool // virtual public void OnCollisionEnter2D(Collision2D collision) { if (m_bIsAlive) { // Now do some checks to see what we hit. { // Env always killed the bullet, no matter where it comes from if (collision.gameObject.CompareTag(Types.s_sTAG_Environment) || collision.gameObject.CompareTag(Types.s_sTAG_Doorway)) { m_iDamageRemaining = 0; } // Enemy Bullets always subtract from Damage Remaining else if (collision.gameObject.CompareTag(Types.s_sTag_EnemyBullets)) { m_iDamageRemaining = (int)MathUtil.Clamp(m_iDamageRemaining - 1, 0, Types.s_iPLAYER_MaxDamage); } // Enemies and destructible items should subtract their hitpoints else if (collision.gameObject.CompareTag(Types.s_sTag_Enemy) || collision.gameObject.CompareTag(Types.s_sTag_Destructible)) { // But... if we're a player bullet we also need to tell the Enemy how much damage we're doing! // Enemy bullets should just die on impact... if (!gameObject.CompareTag(Types.s_sTag_PlayerBullets)) { m_iDamageRemaining = 0; } else { TrackHitPoints gc = collision.gameObject.GetComponent <TrackHitPoints>(); if (null != gc) { int iHitPoints = gc.GetHitPointsRemaining(); int iDamageAfter = (int)MathUtil.Clamp(m_iDamageRemaining - iHitPoints, 0, Types.s_iPLAYER_MaxDamage); gc.DoOnImpactFromPlayer((uint)m_iDamageRemaining); m_iDamageRemaining = iDamageAfter; } // If an enemy doesn't have TrackHitPoints it's invulnerable, so kill this bullet else { m_iDamageRemaining = 0; } } } // Anything remaining is untagged, so kill the bullet just in case... else { m_iDamageRemaining = 0; } } // Die if we need to... if (m_iDamageRemaining == 0) { Vector3 vPos = new Vector3(collision.contacts[0].point.x, collision.contacts[0].point.y, Types.s_fPOS_FrontLayerZ); vPos += new Vector3(collision.contacts[0].normal.x, collision.contacts[0].normal.y, 0.0f) * Types.s_fPOS_ImpactEffectSpawnOffset; if (null != m_goImpactParticleEffect) { Instantiate(m_goImpactParticleEffect, vPos, Quaternion.identity); } GameInstance.Object.GetAudioManager().PlayAudioAtLocation(transform.position, m_iDespawnEffect); DeInitBullet(); } } }