void InAreaDetector::processDetector()
{
    _contacts = 0;
    _detected = false;
    _trapZone = _srcTrapZone;

    _trapZone.setPos(
        _parentNPC->posCenterX() + _srcTrapZone.left(),
        _parentNPC->posCenterY() + _srcTrapZone.top()
    );

    if(_parentNPC->direction() < 0)
    {
        double x_pos = _trapZone.left() + (_parentNPC->posCenterX() - _trapZone.center().x()) * 2.0;
        _trapZone.setPos(x_pos, _trapZone.y());
    }

    detectedPLR.clear();
    detectedBLK.clear();
    detectedBGO.clear();
    detectedNPC.clear();
    detectedBlocks.clear();
    detectedBGOs.clear();
    detectedNPCs.clear();
    detectedPlayers.clear();

    std::vector<PGE_Phys_Object *> bodies;
    _scene->queryItems(_trapZone, &bodies);

    for(PGE_RenderList::iterator it = bodies.begin(); it != bodies.end(); it++)
    {
        PGE_Phys_Object *visibleBody = *it;
        if(visibleBody == _parentNPC) continue;
        if(visibleBody == nullptr)
            continue;
        if(!visibleBody->isVisible()) //Don't whip elements from hidden layers!
            continue;
        switch(visibleBody->type)
        {
        case PGE_Phys_Object::LVLPlayer:
            if((_filters & F_PLAYER) == 0) continue;
            {
                LVL_Player *p = dynamic_cast<LVL_Player *>(visibleBody);
                if(!p) continue;
                detectedPlayers.push_back(p);
                detectedPLR[p->data.id] = 1;
                break;
            }
        case PGE_Phys_Object::LVLBGO:
            if((_filters & F_BGO) == 0) continue;
            {
                LVL_Bgo *b = dynamic_cast<LVL_Bgo *>(visibleBody);
                if(!b) continue;
                detectedBGOs.push_back(b);
                detectedBGO[b->data.id] = 1;
                break;
            }
        case PGE_Phys_Object::LVLNPC:
            if((_filters & F_NPC) == 0) continue;
            {
                LVL_Npc *n = dynamic_cast<LVL_Npc *>(visibleBody);
                if(!n) continue;
                detectedNPCs.push_back(n);
                detectedNPC[n->_npc_id] = 1;
                break;
            }
        case PGE_Phys_Object::LVLBlock:
            if((_filters & F_BLOCK) == 0) continue;
            {
                LVL_Block *s = dynamic_cast<LVL_Block *>(visibleBody);
                if(!s) continue;
                if(!s->m_destroyed)
                    detectedBlocks.push_back(s);
                detectedBLK[s->data.id] = 1;
                break;
            }
        default:
            continue;
        }
        _detected = true;
        _contacts++;
    }
}
Пример #2
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();
}