Пример #1
0
void LevelScene::addPlayer(PlayerPoint playerData, bool byWarp, int warpType, int warpDirect)
{
    LVL_Player * player;
    if(luaEngine.isValid()){
        player = luaEngine.createLuaPlayer();
        if(player == nullptr)
            player = new LVL_Player();
    }else{
        player = new LVL_Player();
    }

    if(players.size()==0)
        player->camera = &cameras.first();
    else if(players.size()==1)
        player->camera = &cameras.last();

    int sID = findNearestSection(playerData.x, playerData.y);
    LVL_Section *sct = getSection(sID);
    if(!sct)
    {
        delete player;
        return;
    }
    player->setParentSection(sct);
    player->z_index = Z_Player;
    player->setPlayerPointInfo(playerData);
    player->init();
    players.push_back(player);

    if(playerData.id==1)
        player1Controller->registerInControl(player);
    else if(playerData.id==2)
        player2Controller->registerInControl(player);

    if(byWarp)
    {
        player->setPaused(true);
        player->WarpTo(playerData.x, playerData.y, warpType, warpDirect);
        if(warpType==2)
            PGE_Audio::playSoundByRole(obj_sound_role::WarpDoor);
        else if(warpType==0)
            PGE_Audio::playSoundByRole(obj_sound_role::PlayerMagic);
    }
}
Пример #2
0
void LevelScene::addPlayer(PlayerPoint playerData, bool byWarp, int warpType, int warpDirect, bool cannon, double cannon_speed)
{
    LVL_Player *player = nullptr;

    if(m_luaEngine.isValid())
    {
        player = m_luaEngine.createLuaPlayer();

        if(player == nullptr)
            player = new LVL_Player(this);
    }
    else
        player = new LVL_Player(this);

    if(!player)
        throw(std::runtime_error("Out of memory [new LVL_Player] addPlayer"));

    player->m_scene = this;

    if(m_itemsPlayers.size() == 0)
        player->camera = &m_cameras.front();
    else if(m_itemsPlayers.size() == 1)
        player->camera = &m_cameras.back();

    int sID = findNearestSection(playerData.x, playerData.y);
    LVL_Section *sct = getSection(sID);

    if(!sct)
    {
        delete player;
        return;
    }

    player->setParentSection(sct);
    player->z_index = zOrder.player;
    player->m_global_state = ((static_cast<unsigned>(m_playerStates.size()) > (playerData.id - 1)) ?
                            &m_playerStates[static_cast<int>(playerData.id - 1)] : nullptr);
    player->setPlayerPointInfo(playerData);
    if(!player->init())
    {
        delete player;
        m_errorMsg = "Failed to initialize playable character!\nSee log file for more information!";
        m_fader.setFade(10, 1.0, 1.0);
        setExiting(0, LvlExit::EXIT_Error);
        return;
    }
    m_itemsPlayers.push_back(player);

    if(playerData.id == 1)
        m_player1Controller->registerInControl(player);
    else if(playerData.id == 2)
        m_player2Controller->registerInControl(player);

    if(byWarp)
    {
        player->setPaused(true);
        player->WarpTo(playerData.x, playerData.y, warpType, warpDirect, cannon, cannon_speed);

        if(warpType == 2)
            PGE_Audio::playSoundByRole(obj_sound_role::WarpDoor);
        else if(warpType == 0)
            PGE_Audio::playSoundByRole(obj_sound_role::PlayerMagic);
    }
    else
        player->camera->changeSection(sct, true);
}