示例#1
0
        private void Destroy()
        {
            gameObject.SetActive(false);
            SpaceInvaderAbstractFactory spaceInvaderFactory = SpaceInvaderFactoryProducer.GetFactory("PlayerBulletFactory"); // accessomg InvaderFactory

            spaceInvaderFactory.RecyclePlayerBullet(this);
        }
示例#2
0
        private void DestroyEffect()
        {
            gameObject.SetActive(true);
            SpaceInvaderAbstractFactory spaceInvaderFactory = SpaceInvaderFactoryProducer.GetFactory("EffectsFactory");

            spaceInvaderFactory.RecycleEffect(this);
        }
        // very basic implementation of firing mechnism, it can be more advanced if needed which I feel not needed for this game
        private void FireBullet()
        {
            int        newFireColumn = 0;
            List <int> nonEmptyFirableColumnIndexs = new List <int>();

            for (int i = 0; i < m_firableColumn.Length; i++)
            {
                if (m_lastFiredColumn != i && m_firableColumn[i] != null)
                {
                    nonEmptyFirableColumnIndexs.Add(i);
                }
            }

            newFireColumn = nonEmptyFirableColumnIndexs[UnityEngine.Random.Range(0, nonEmptyFirableColumnIndexs.Count)];

            Invader fireInvader  = m_firableColumn[newFireColumn];
            Vector3 firePosition = fireInvader.transform.position;

            SpaceInvaderAbstractFactory spaceInvaderFactory = SpaceInvaderFactoryProducer.GetFactory("InvaderBulletFactory"); // accessomg InvaderFactory
            InvaderBullet invaderBullet = spaceInvaderFactory.GetInvaderBullet(InvaderBulletTypes.SquiglyShot);

            invaderBullet.gameObject.transform.position = new Vector3(firePosition.x, firePosition.y - .3f, firePosition.z);
            invaderBullet.gameObject.transform.rotation = Quaternion.identity;
            invaderBullet.gameObject.SetActive(true);
        }
示例#4
0
        private void Exlode()
        {
            SpaceInvaderAbstractFactory spaceInvaderFactory = SpaceInvaderFactoryProducer.GetFactory("EffectsFactory");
            Effects invadeExplodeEffect = spaceInvaderFactory.GetEffects(EffectsType.PlayerbulletExplode);

            invadeExplodeEffect.transform.position = transform.position;
            invadeExplodeEffect.transform.rotation = Quaternion.identity;
            invadeExplodeEffect.gameObject.SetActive(true);
            invadeExplodeEffect.DestroyAfterSomeTime(.15f);
        }
示例#5
0
        public void Kill()
        {
            Debug.Log("Player dies");
            gameObject.SetActive(false);
            SpaceInvaderAbstractFactory spaceInvaderFactory = SpaceInvaderFactoryProducer.GetFactory("PlayerFactory");

            spaceInvaderFactory.RecyclePlayer(this);
            Exlode();
            m_playerLifeSO.Value = m_playerLifeSO.Value - 1;
        }
        // called when player bullet hit on invader. check invader script
        public void DestroyInvader(Invader thisInvader)
        {
            // for boss checking
            if (m_lastInviderColumnIndexCntr < 0)
            {
                m_lastInviderColumnIndex = thisInvader.m_coumnIndex; m_lastInviderColumnIndexCntr = 1;
            }
            else
            {
                int cntr = m_lastInviderColumnIndex == thisInvader.m_coumnIndex ? m_lastInviderColumnIndexCntr + 1 : 1; // adding to the colmns index
                m_lastInviderColumnIndexCntr = cntr;
                m_lastInviderColumnIndex     = thisInvader.m_coumnIndex;
            }

            bool timetoBoSS = m_lastInviderColumnIndexCntr >= m_maxInvaderColumnCntr ? true : false;

            if (timetoBoSS && m_lastScoreBossShown + m_minScoreNeeded < m_gameScoreSO.Value)
            {
                if (m_bossInvader == null)
                {
                    m_lastScoreBossShown = m_gameScoreSO.Value;
                    CreatNewBoss();
                    Debug.Log("creating new boss : USER Generated");
                    m_lastBossShownTime = Time.time;
                }
            }

            m_totalAliveInviders--; // decrement the invader count
            m_totalAliveInvadersSO.Value = m_totalAliveInviders;
            m_gameScoreSO.Value          = m_gameScoreSO.Value + thisInvader.m_killValue.Value;
            Vector3 invaderLastPos = thisInvader.transform.position;

            m_invaderRows[thisInvader.m_rowIndex][thisInvader.m_coumnIndex] = null;
            SpaceInvaderAbstractFactory spaceInvaderFactory = SpaceInvaderFactoryProducer.GetFactory("InvaderFactory"); // accessomg InvaderFactory

            spaceInvaderFactory.RecycleInvader(thisInvader);

            spaceInvaderFactory = SpaceInvaderFactoryProducer.GetFactory("EffectsFactory");
            Effects invadeExplodeEffect = spaceInvaderFactory.GetEffects(EffectsType.AlianExplodeEffect);

            invadeExplodeEffect.transform.position = invaderLastPos;
            invadeExplodeEffect.gameObject.SetActive(true);
            invadeExplodeEffect.DestroyAfterSomeTime(.15f);
            m_audioSource.PlayOneShot(m_invaderExlodeClip);

            UpdateTimeIntervalOFMove();    // check against the number of inviders left and increas the move speed

            if (m_totalAliveInviders == 0) //  next wave
            {
                m_invaderGridState = InvaderGridState.Pause;
                return;
                // for now there wont be any new waves, game will be over at this point
                // wil add new wave feature in the next update
            }
        }
示例#7
0
 void FixedUpdate()
 {
     // resend to teh factory if the position goes beyonf boundary
     if ((m_directionMove > 0 && transform.position.x > 3.6f) || (m_directionMove < 0 && transform.position.x < -3.6f))// reached borders
     {
         gameObject.SetActive(false);
         SpaceInvaderAbstractFactory spaceInvaderFactory = SpaceInvaderFactoryProducer.GetFactory("BossFactory"); // accessomg boss factoy
         spaceInvaderFactory.RecycleBoss(this);
         m_invaderManger.RemoveBoss();
     }
 }
        private bool CreateNewPlayer() // creates new player using the factory pattern
        {
            Debug.Log("Creating the player");
            SpaceInvaderAbstractFactory spaceInvaderFactory = SpaceInvaderFactoryProducer.GetFactory("PlayerFactory"); // getting PlayerFactory
            Player player = spaceInvaderFactory.GetPlayer();                                                           // factory returns new player

            player.gameObject.transform.position = m_playerInitialePos.position;                                       // assing spawn position to player
            player.gameObject.SetActive(true);
            player.InitializePlayer();                                                                                 // initializing player
            return(true);
        }
示例#9
0
        public void ExecuteFire() // invokded from Input handler
        {
            if(m_playerModel.LastFireTime + m_playerModel.FireInterval <= Time.time) // handling firing interval
            {
                SpaceInvaderAbstractFactory spaceInvaderFactory = SpaceInvaderFactoryProducer.GetFactory("PlayerBulletFactory"); // accessomg InvaderFactory
                PlayerBullet playerBullet = spaceInvaderFactory.GetPlayerBullet();

                playerBullet.transform.position = m_playerModel.Position + new Vector3(0, .3f, 0); // adding little offset on y axist for stating not fromcentre
                playerBullet.transform.rotation = Quaternion.identity;
                playerBullet.gameObject.SetActive(true);

                m_playerModel.LastFireTime = Time.time;

                playerBullet.PlayFireSound();
            } 
        }
        // creates the Invaders in a grid manner
        // with the help of Grid class, this creates a new invader grids and stores in an jagged array
        private void CreateInvaderGrid()
        {
            if (m_invaderTypeRow.Length < 1)
            {
                return;
            }

            m_gridRows    = m_invaderTypeRow.Length;                       // number of rows of invaders
            m_gridColumns = m_invaderRowLength;                            // row counts is basically max Coulumn

            m_leftMaxMoveCheckIndex  = new RawCoumn(0, 0);                 // first row firt column
            m_rightMaxMoveCheckIndex = new RawCoumn(0, m_gridColumns - 1); // first row last column

            m_invaderRows = new Invader[m_gridRows][];
            for (int i = 0; i < m_gridRows; i++)
            {
                m_invaderRows[i] = new Invader[m_gridColumns];
            }

            m_2DGrid = new Grid2D(m_gridRows, m_gridColumns, m_gridCellWidth, m_gridCellHeight, m_gridRootObject.position);
            SpaceInvaderAbstractFactory spaceInvaderFactory = SpaceInvaderFactoryProducer.GetFactory("InvaderFactory"); // accessomg InvaderFactory

            for (int i = 0; i < m_gridRows; i++)
            {
                InvaderTypes rowType = m_invaderTypeRow[i]; // current row type
                for (int j = 0; j < m_gridColumns; j++)
                {
                    Cell cell = m_2DGrid.Cells[i][j];

                    Invader invader = spaceInvaderFactory.GetInvader(rowType); // asking for type of invaders from the factory
                    invader.gameObject.transform.position = cell.m_center;

                    invader.m_invaderManger = this;
                    invader.m_rowIndex      = i;
                    invader.m_coumnIndex    = j;
                    m_totalAliveInviders++;
                    m_totalAliveInvadersSO.Value = m_totalAliveInviders;
                    m_invaderRows[i][j]          = invader; // assigning to the invader array
                }
            }

            m_firableColumn    = m_invaderRows[m_invaderRows.Length - 1];
            m_invaderGridState = InvaderGridState.Created;
            // Invaders will be in hidden state at this point and next ShowAllInviders will display invaders with animation
        }
        public void DestroyBoss(Boss boss)
        {
            SpaceInvaderAbstractFactory spaceInvaderFactory = SpaceInvaderFactoryProducer.GetFactory("EffectsFactory");
            Effects bossExplodeEffect = spaceInvaderFactory.GetEffects(EffectsType.BossExplode);

            bossExplodeEffect.transform.position = boss.transform.position;
            bossExplodeEffect.gameObject.SetActive(true);
            bossExplodeEffect.DestroyAfterSomeTime(.15f);

            spaceInvaderFactory = SpaceInvaderFactoryProducer.GetFactory("BossFactory"); // accessomg boss factoy
            spaceInvaderFactory.RecycleBoss(boss);
            boss.gameObject.SetActive(false);
            m_audioSource.PlayOneShot(m_invaderExlodeClip);
            m_bossInvader = null;

            // score
            // for now, if the inviders move right it is 100, 50 left move not really a mystery :(
            int bossKillScore = m_invaderHorMovDirection > 0 ? 100 : 50;

            m_gameScoreSO.Value = m_gameScoreSO.Value + bossKillScore;
        }
        private void CreatNewBoss()
        {
            SpaceInvaderAbstractFactory spaceInvaderFactory = SpaceInvaderFactoryProducer.GetFactory("BossFactory"); // accessomg InvaderFactory
            Boss boss = spaceInvaderFactory.GetBoss();

            boss.m_invaderManger = this;
            Vector3 spawnPosition = m_bossSpawnPoint.position;

            if (m_invaderHorMovDirection > 0)
            {
                boss.m_directionMove = m_invaderHorMovDirection; // boss always move in the same direction of invaders
                boss.transform.gameObject.transform.position = new Vector3(-3.5f, spawnPosition.y, spawnPosition.z);
            }
            else
            {
                boss.m_directionMove = m_invaderHorMovDirection;
                boss.transform.gameObject.transform.position = new Vector3(3.5f, spawnPosition.y, spawnPosition.z);
            }
            boss.transform.gameObject.SetActive(true);
            m_bossInvader = boss;
            boss.PlaySound();
        }