Ejemplo n.º 1
0
    protected void processPlayerBullets(Enemy enemy)
    {
        //Initialize
        List<FNode> Deads 			= new List<FNode>();
        List<FNode> HittedEnemies 	= new List<FNode>();

        //For each child in the container
        for (int i = 0; i < m_PlayerBullets.GetChildCount(); i++) {
            //Get enemy
            PlayerBullet Bullet = m_PlayerBullets.GetChildAt(i) as PlayerBullet;
            if (Bullet != null) {
                //Move
                Bullet.x += 8.0f;
                Bullet.Update(Time.deltaTime);

                if (Bullet.ShouldBeDead()) {
                    //Log
                    logConsole("[ERROR] Memory Leak: PlayerBullet not deleted " + (m_Error + 1) + "/" + ERROR_MAX);

                    Deads.Add(Bullet);
                    incrementError();
                }

                if (enemy != null && !Bullet.ShouldBeTouched() && Bullet.doesCollide(enemy)) {
                    HittedEnemies.Add(enemy);
                    Bullet.EnableTouchChecking();
                    FSoundManager.PlaySound("explosion");

                    //Log
                    logConsole("[LOG] Engine: Bullet - Enemy collision detected!");
                }
            }
        }

        //Remove deads
        for (int i = 0; i < Deads.Count; i++) m_PlayerBullets.RemoveChild(Deads[i]);

        //Activate hitted enemies
        foreach(Enemy hitted in HittedEnemies) {
            hitted.EnableTouchChecking();
        }

        //Spawn
        m_PlayerBulletTimer -= Time.deltaTime;
        if (m_PlayerBulletTimer <= 0f && enemy != null && enemy.y == m_Exa.y) {
            //Create
            Vector2 playerPos 	= m_Exa.GetPosition();
            float X 			= playerPos.x + 10.0f;
            float Y				= playerPos.y;
            PlayerBullet bullet = new PlayerBullet(X,Y);
            bullet.SetBorder(m_PlayerBulletBorder);

            //Add
            m_PlayerBullets.AddChild(bullet);

            //Reset
            m_PlayerBulletTimer = 1.5f;

            //Log
            //logConsole("[LOG] Player: Shooting bullet");
        }
    }