Exemplo n.º 1
0
    /// <summary>
    /// 开始游戏
    /// </summary>
    public void StartGame()
    {
        // 初始从第一关开始
        Level = ConfigMgr.instance.gameConfig.GetLevelConfig(1);
        // 初始化得分
        Score = 0;
        // 初始化核弹
        BombCnt = 0;


        // 关闭开始游戏界面
        PanelMgr.instance.HidePanel <StartGamePanel>();

        // 显示游戏战斗界面
        PanelMgr.instance.ShowPanel <MainGamePanel>();

        // 创建主角飞机
        player = AircraftFactory.CreateAircraft(AircraftType.Player);

        // 初始化核弹生成器
        m_superBombGenerator.Init();


        gameState = GameState.Playing;
    }
Exemplo n.º 2
0
    /// <summary>
    /// 随机生成一个敌机
    /// </summary>
    private void RandomGenerateEnemy()
    {
        EnemyAircraft enemy        = null;
        var           config       = m_enemyRandom.Next();
        var           aircraftType = (AircraftType)config.Index;

        if (m_reusePool.ContainsKey(aircraftType) && m_reusePool[aircraftType].Count > 0)
        {
            enemy = m_reusePool[aircraftType].Dequeue();
            enemy.ActiveSelf(true);
        }
        else
        {
            enemy = (EnemyAircraft)AircraftFactory.CreateAircraft((AircraftType)config.Index);
            enemy.backToPoolAction = () =>
            {
                // 对象回收
                if (!m_reusePool.ContainsKey(aircraftType))
                {
                    m_reusePool[aircraftType] = new Queue <EnemyAircraft>();
                }
                m_reusePool[aircraftType].Enqueue(enemy);

                if (m_aliveEnemy.Contains(enemy))
                {
                    m_aliveEnemy.Remove(enemy);
                }
            };
        }
        enemy.blood     = config.Blood;
        enemy.moveSpeed = Random.Range(config.MinSpeed, config.MaxSpeed);
        enemy.ResetTimeToFire(1);
        enemy.RandomStartPos();
        if (!m_aliveEnemy.Contains(enemy))
        {
            m_aliveEnemy.Add(enemy);
        }
    }