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; }
LVL_Npc *LevelScene::spawnNPC(LevelNPC npcData, NpcSpawnType sp_type, NpcSpawnDirection sp_dir, bool reSpawnable) { if(!ConfigManager::lvl_npc_indexes.contains(npcData.id)) return NULL; obj_npc* curNpcData = &ConfigManager::lvl_npc_indexes[npcData.id]; LVL_Npc * npc = luaEngine.createLuaNpc(npcData.id); if(!npc) return NULL; npcData.array_id= ++data.npc_array_id; npc->setup = curNpcData; npc->reSpawnable=reSpawnable; npc->data = npcData; npc->init(); npc->Activate(); switch(sp_type) { case GENERATOR_WARP: switch(sp_dir) { case SPAWN_DOWN: npc->setWarpSpawn(LVL_Npc::WARP_TOP); break; case SPAWN_UP: npc->setWarpSpawn(LVL_Npc::WARP_BOTTOM); break; case SPAWN_LEFT: npc->setWarpSpawn(LVL_Npc::WARP_RIGHT); break; case SPAWN_RIGHT: npc->setWarpSpawn(LVL_Npc::WARP_LEFT); break; } break; case GENERATOR_PROJECTILE: break; default: break; } active_npcs.push_back(npc); npcs.push_back(npc); return npc; }
LVL_Npc *LevelScene::spawnNPC(const LevelNPC &npcData, NpcSpawnType sp_type, NpcSpawnDirection sp_dir, bool reSpawnable) { if(npcData.id <= 0) return nullptr; if(!ConfigManager::lvl_npc_indexes.contains(npcData.id)) return nullptr; obj_npc *curNpcData = &ConfigManager::lvl_npc_indexes[npcData.id]; LVL_Npc *npc = m_luaEngine.createLuaNpc(npcData.id); if(!npc) return nullptr; npc->setScenePointer(this); npc->setup = curNpcData; npc->reSpawnable = reSpawnable; npc->data = npcData; npc->data.meta.array_id = ++m_data.npc_array_id; npc->init(); npc->m_spawnedGeneratorType = sp_type; npc->m_spawnedGeneratorDirection = sp_dir; switch(sp_type) { case GENERATOR_WARP: switch(sp_dir) { case SPAWN_DOWN: npc->setWarpSpawn(LVL_Npc::WARP_TOP); break; case SPAWN_UP: npc->setWarpSpawn(LVL_Npc::WARP_BOTTOM); break; case SPAWN_LEFT: npc->setWarpSpawn(LVL_Npc::WARP_RIGHT); break; case SPAWN_RIGHT: npc->setWarpSpawn(LVL_Npc::WARP_LEFT); break; } break; case GENERATOR_PROJECTILE: switch(sp_dir) { case SPAWN_DOWN: npc->setSpeedX(0.0); npc->setSpeedY(ConfigManager::g_setup_npc.projectile_speed); break; case SPAWN_UP: npc->setSpeedX(0.0); npc->setSpeedY(-ConfigManager::g_setup_npc.projectile_speed); break; case SPAWN_LEFT: npc->setSpeedX(-ConfigManager::g_setup_npc.projectile_speed); npc->setSpeedY(0.0); break; case SPAWN_RIGHT: npc->setSpeedX(ConfigManager::g_setup_npc.projectile_speed); npc->setSpeedY(0.0); break; } PGE_Audio::playSound(ConfigManager::g_setup_npc.projectile_sound_id); break; default: break; } npc->Activate(); m_npcActive.push_back(npc); m_itemsNpc.push_back(npc); return npc; }
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(); }