예제 #1
0
 public void RemoveObjectFromProcessing(iAttackableObject planet)
 {
     if (m_ProcessingObjects.Contains(planet))
     {
         m_ProcessingObjects.Remove(planet);
     }
 }
예제 #2
0
        void CreateProjectile(iAttackableObject sender, float objectSize)
        {
            //Calculate projectile init move direction and spawn offset
            Vector2 dirToSun                     = SunObject.Position - sender.Position;
            Vector2 verticalToDirToSun           = new Vector2(-dirToSun.y, dirToSun.x);
            Vector2 verticalToDirToSunNormalized = verticalToDirToSun.normalized;
            Vector3 spawnOffset2D                = verticalToDirToSunNormalized * objectSize;

            //Create and position projectile
            Projectile projectile = Instantiate(GameManager.Instance.AssetsLibrary.Library_Prefabs.ProjectilePrefab);

            projectile.transform.position = sender.Position + spawnOffset2D;

            //Subscribe projectile for events
            projectile.OnProjectileRemoved += (iGravityAffectable objToRemove) =>
            {
                //Remove object from physics processing
                PhysicsController.RemoveGravityAffectable(objToRemove);

                //Remove object
                Destroy(objToRemove.GetObject);
            };
            projectile.OnCollideWithBattleObject += (BattleObject objToRemove, int damage, int projectileSenderID) =>
            {
                objToRemove.TakeDamage(damage);

                if (objToRemove.IsDestroyed)
                {
                    //If enemy was destroyed
                    if (!objToRemove.IsPlayer)
                    {
                        //Remove planet from AI processing
                        m_AIManager.RemoveObjectFromProcessing(objToRemove);

                        //If player destroyed enemy
                        if (projectileSenderID == m_Player.ID)
                        {
                            //Update score and calculate win state
                            m_EnemiesDestroyed++;
                            m_OnScoreUpdate?.Invoke(GetScore());
                        }

                        //Decrease amount of enemies
                        m_CurrentEnemies--;

                        //Calculate win state
                        if (PlayerWon())
                        {
                            m_IsPaused = true;
                            UIManager.ShowBattleResult(true, GetScore());
                            m_OnGameFinished?.Invoke(true);
                        }
                        else
                        {
                            CameraShakeEffect.TriggerShake();
                        }
                    }
                    else //Player was destroyed
                    {
                        m_IsPaused = true;
                        UIManager.ShowBattleResult(false, GetScore());
                        m_OnGameFinished?.Invoke(true);
                    }

                    //Please, accept my appologize. I dont like this peace of code but it exists due to the lack of time :)

                    //Remove planet from physics processing
                    iAttractor attractor = objToRemove as iAttractor;
                    if (attractor != null)
                    {
                        PhysicsController.RemoveAttractor(attractor);
                    }

                    //Destroy planet
                    Destroy(objToRemove.gameObject);
                }
            };
            projectile.OnExplosion += (Vector3 spawnPos) =>
            {
                Transform explosionEffect = Instantiate(GameManager.Instance.AssetsLibrary.Library_Prefabs.ExplosionPrefab, spawnPos, Quaternion.identity);
                Destroy(explosionEffect.gameObject, 3);
            };

            //Subscribe for pause event
            m_OnPauseStateChanged += projectile.PauseUpdate;
            m_OnGameFinished      += projectile.PauseUpdate;

            //Add projectile to physics processing
            PhysicsController.AddGravityAffectable(projectile);

            //Launch projectile
            projectile.Launch(verticalToDirToSunNormalized,
                              sender.ProjectileStats.Acceleration,
                              sender.ProjectileStats.Weight,
                              sender.ProjectileStats.LifeTime,
                              sender.ProjectileStats.Damage,
                              sender.ProjectileStats.CorrespondingSprite,
                              sender.IsPlayer,
                              sender.ID);
        }
예제 #3
0
 public void AddObjectToProcessing(iAttackableObject planet) => m_ProcessingObjects.Add(planet);