Exemplo n.º 1
0
int LVL_Npc::lua_activate_neighbours()
{
    QVector<PGE_Phys_Object *> bodies;
    PGE_RectF posRectC = m_momentum.rectF().withMargin(2.0);
    m_scene->queryItems(posRectC, &bodies);

    int found = 0;
    for(PGE_RenderList::iterator it = bodies.begin(); it != bodies.end(); it++)
    {
        PGE_Phys_Object *item = *it;
        if(item->type != PGE_Phys_Object::LVLNPC) continue;
        LVL_Npc *body = dynamic_cast<LVL_Npc *>(item);
        if(!body) continue;
        if(body == this) continue;
        if(!body->isVisible()) continue;
        if(body->killed) continue;
        if(body->_npc_id != _npc_id) continue;
        if(!body->isActivated)
        {
            body->Activate();
            m_scene->active_npcs.push_back(body);
            found++;
        }
    }
    return found;
}
void LevelScene::update()
{
    if(m_luaEngine.shouldShutdown())
    {
        m_fader.setFade(10, 1.0, 1.0);
        setExiting(0, LvlExit::EXIT_Error);
    }

    Scene::update();

    if(!m_isPauseMenu)
        tickAnimations(uTickf);

    if(!m_isLevelContinues)
    {
        //Level exit timeout
        m_exitLevelDelay -= uTickf;

        if(m_exitLevelDelay <= 0.0)
        {
            m_doExit = true;

            if(m_fader.isNull())
            {
                if(PGE_MusPlayer::isPlaying())
                    PGE_MusPlayer::fadeOut(500);

                m_fader.setFade(10, 1.0, 0.01);
            }
        }
    }

    if(m_doExit)
    {
        if(m_exitLevelCode == LvlExit::EXIT_Closed)
        {
            m_fader.setFull();
            m_isRunning = false;
        }
        else
        {
            if(m_fader.isFull())
                m_isRunning = false;
        }
    }
    else if(m_isPauseMenu)
        processPauseMenu();
    else
    {
        //Update physics is not pause menu
        updateLua();//Process LUA code
        m_systemEvents.processEvents(uTickf);
        m_events.processTimers(uTickf);

        //update cameras
        for(PGE_LevelCamera &cam : m_cameras)
            cam.updatePre(uTickf);

        processEffects(uTickf);

        if(!m_isTimeStopped) //if activated Time stop bonus or time disabled by special event
        {
            //Make world step
            processPhysics(uTickf);
        }

        while(!m_blockTransforms.empty())
        {
            transformTask_block x = m_blockTransforms.front();
            x.block->transformTo_x(x.id);
            m_blockTransforms.pop_front();
        }

        // Send controller states to controllable objects
        m_player1Controller->sendControls();
        m_player2Controller->sendControls();

        //update players
        for(LVL_Player *plr : m_itemsPlayers)
        {
            plr->update(uTickf);

            if(PGE_Window::showDebugInfo)
            {
                m_debug_player_jumping    = plr->m_jumpPressed;
                m_debug_player_onground   = plr->onGround();
                m_debug_player_foots      = (int)plr->l_contactB.size();
            }
        }

        for(size_t i = 0; i < m_blocksInFade.size(); i++)
        {
            if(m_blocksInFade[i]->tickFader(uTickf))
            {
                m_blocksInFade.erase(m_blocksInFade.begin() + (int)i);
                i--;
            }
        }

        //Process activated NPCs
        //for(size_t i = 0; i < m_npcActive.size(); i++)
        for(auto i = m_npcActive.begin(); i != m_npcActive.end();)
        {
            LVL_Npc *n = *i;
            n->update(uTickf);
            if(n->isKilled())
            {
                i = m_npcActive.erase(i);
                continue;
            }
            else if(n->activationTimeout <= 0)
            {
                if(!n->warpSpawing)
                    n->deActivate();
                if(n->wasDeactivated)
                {
                    if(!isVizibleOnScreen(n->m_momentum) || !n->isVisible() || !n->is_activity)
                    {
                        n->wasDeactivated = false;
                        i = m_npcActive.erase(i);
                        continue;
                    }
                }
            }
            ++i;
        }

        if(!m_isTimeStopped) //if activated Time stop bonus or time disabled by special event
        {
            //Process and resolve collisions
            processAllCollisions();
        }

        /***************Collect garbage****************/
        if(!m_npcDead.empty())
            collectGarbageNPCs();

        if(!m_playersDead.empty())
            collectGarbagePlayers();

        if(!m_blocksToDelete.empty())
            collectGarbageBlocks();

        /**********************************************/

        //update cameras
        for(PGE_LevelCamera &cam : m_cameras)
        {
            cam.updatePost(uTickf);
            //! --------------DRAW HUD--------------------------------------
            // TODO: Implement separated render queue for elements of HUD and provide render functions
            // are will draw HUD elements after world has drawn.
            LuaEngine *sceneLuaEngine = getLuaEngine();
            if(sceneLuaEngine)
            {
                if(sceneLuaEngine->isValid() && !sceneLuaEngine->shouldShutdown())
                {
                    LuaEvent drawHUDEvent = BindingCore_Events_Engine::createDrawLevelHUDEvent(sceneLuaEngine,
                                            &cam,
                                            &m_playerStates[(size_t)(cam.playerID - 1)]);
                    sceneLuaEngine->dispatchEvent(drawHUDEvent);
                }
            }
            //! ------------------------------------------------------------
        }

        //Add effects into the render table
        for(Scene_Effect &item : WorkingEffects)
        {
            renderArrayAddFunction([&item](double camPosX, double camPosY)
            {
                item.render(camPosX, camPosY);
            },  item.m_zIndex);
        }

        //Clear garbage (be careful!)
        //luaEngine.runGarbageCollector();
    }

    //Process interprocessing commands cache
    process_InterprocessCommands();
    //Process Z-sort of the render functions
    renderArrayPrepare();
    //Process message boxes
    m_messages.process();
}
Exemplo n.º 3
0
void PGE_LevelCamera::update(float ticks)
{
    objects_to_render.clear();

    if(!cur_section) return;
    fader.tickFader(ticks);

    if(isAutoscroll) processAutoscroll(ticks);

    LvlSceneP::s->queryItems(posRect, &objects_to_render);

    int contacts = 0;
    for(int i=0; i<objects_to_render.size();i++)
    {
        contacts++;
        PGE_Phys_Object * visibleBody = objects_to_render[i];
        bool renderable=false;
        if(!visibleBody->isVisible())
        {
            objects_to_render.removeAt(i); i--; continue;
        }
        switch(visibleBody->type)
        {
            case PGE_Phys_Object::LVLBlock:
            case PGE_Phys_Object::LVLBGO:
            case PGE_Phys_Object::LVLNPC:
            case PGE_Phys_Object::LVLPlayer:
            case PGE_Phys_Object::LVLEffect:
                renderable=true;
        }

        if(visibleBody->type==PGE_Phys_Object::LVLNPC)
        {
            LVL_Npc *npc = dynamic_cast<LVL_Npc*>(visibleBody);
            if(npc && npc->isVisible())
            {
                if(!npc->isActivated && !npc->wasDeactivated)
                {
                    npc->Activate();
                    LvlSceneP::s->active_npcs.push_back(npc);
                }
                else
                {
                    if(npc->wasDeactivated)
                        npc->activationTimeout=0;
                    else
                    {
                        if(npc->is_activity)
                            npc->activationTimeout = npc->setup->deactivetionDelay;
                        else
                            npc->activationTimeout = 150;
                    }
                }
            }
        }

        if(!PGE_Window::showPhysicsDebug && !renderable)
        {
            objects_to_render.removeAt(i); i--;
        }
    }

    //Sort array
    sortElements();
}