/*************************************************************************
 * Function Name : GetSectionPmt
 * Description   : get one PMT section from a byte array
 * Parameters    :
 * Returns       :
 **************************************************************************/
static SECTION_PMT *GetSectionPmt(unsigned char *pucBuffer)
{
	SECTION_PMT *pstSectionPmt = (SECTION_PMT *)malloc(sizeof(SECTION_PMT));
	pstSectionPmt->table_id = pucBuffer[0];
	pstSectionPmt->section_syntax_indicator = (pucBuffer[1] >> 7) & 0x01;
	pstSectionPmt->reserved_future_use = (pucBuffer[1] >> 6) & 0x1;
	pstSectionPmt->reserved1 = (pucBuffer[1] >> 4) & 0x3;
	pstSectionPmt->section_length = ((pucBuffer[1] & 0x0F) << 8) | pucBuffer[2];
	pstSectionPmt->program_number = (pucBuffer[3] << 8) | pucBuffer[4];
	pstSectionPmt->reserved2 = (pucBuffer[5] >> 6) & 0x03;
	pstSectionPmt->version_number = (pucBuffer[5] >> 1) & 0x1F;
	pstSectionPmt->current_next_indicator = pucBuffer[5] & 0x01;
	pstSectionPmt->section_number = pucBuffer[6];
	pstSectionPmt->last_section_number = pucBuffer[7];
	pstSectionPmt->reserved3 = (pucBuffer[8] >> 5) & 0x07;
	pstSectionPmt->PCR_PID = ((pucBuffer[8] & 0x1f) << 8) | pucBuffer[9];
	pstSectionPmt->reserved4 = (pucBuffer[10] >> 4) & 0x0f;
	pstSectionPmt->program_info_length = ((pucBuffer[10] & 0x0f) << 8) | pucBuffer[11];
	pstSectionPmt->pstProgramElements = GetElementList(pucBuffer + 12 + pstSectionPmt->program_info_length,
	        pstSectionPmt->section_length - 9 - 4 - pstSectionPmt->program_info_length);
	pstSectionPmt->pstNext = NULL;
	return pstSectionPmt;
}
示例#2
0
void MainScene::UpdateData(const float& delta)
{
	// 关卡数据更新
	StageManager::getInstance()->Update(delta);

	vector<Element*> list = GetElementList();
	for (int i = 0; i < list.size(); ++i)
	{
		list.at(i)->SetPositionZ(-list.at(i)->GetOrder() * 2);

		if (list.at(i)->GetOrder() == LAYER_PLAYER_BULLET ||
			list.at(i)->GetOrder() == LAYER_ENEMY_BULLET)
		{
			RECT viewRect = Director::getInstance()->GetViewRect();
			D3DXVECTOR3 viewPos = Camera::getInstance()->GetViewPosition();
			if (Tools::CheckHit_UnInclude(list.at(i),
				viewPos.x - viewRect.right / 2.0f,
				viewPos.y - viewRect.bottom / 2.0f,
				viewPos.x + viewRect.right / 2.0f,
				viewPos.y + viewRect.bottom / 2.0f))
			{
				list.at(i)->SetVisible(false);
			}
		}
		else if (list.at(i)->GetOrder() == LAYER_ENEMY_1 ||
			list.at(i)->GetOrder() == LAYER_ENEMY_2 ||
			list.at(i)->GetOrder() == LAYER_ENEMY_3)
		{
			RECT viewRect = Director::getInstance()->GetViewRect();
			D3DXVECTOR3 viewPos = Camera::getInstance()->GetViewPosition();
			if (list.at(i)->GetPositionY() + (0.5f - list.at(i)->GetAnchorY()) * list.at(i)->GetHeight() <
				viewPos.y + viewRect.bottom / 2.0f &&
				list.at(i)->GetPositionY() - (0.5f - list.at(i)->GetAnchorY()) * list.at(i)->GetHeight() >
				viewPos.y - viewRect.bottom / 2.0f)
			{
				for (int j = 0; j < list.size(); ++j)
				{
					if (list.at(j)->GetOrder() == LAYER_PLAYER_BULLET)
					{
						if (Tools::CheckHit_Circle(list.at(j), list.at(i)) && ((Enemy*)list.at(i))->GetHp() > 0)
						{
							Bullet* bullet = (Bullet*)list.at(j);
							if (bullet->IsCross() == false)
							{
								bullet->Die();
							}
							Enemy* enemy = (Enemy*)list.at(i);
							enemy->SetHp(enemy->GetHp() - bullet->GetAttack());
							enemy->SetBruiseEnable(true);
							
							if (enemy->GetHp() <= 0)
							{
								enemy->Die();
								//分数更新
								UserManager* userMgr = UserManager::getInstance();
								userMgr->SetScore(userMgr->GetScore() + enemy->GetScore());
								enemy->SetScore(0);
								_scoreText->SetText("SCORE:" + to_string(userMgr->GetScore()));

								if (enemy->GetName().substr(0, 4).compare("boss") == 0)
								{
									if (userMgr->GetStage() < userMgr->GetStageMax())
									{
										userMgr->SetStage(userMgr->GetStage() + 1);
										if (_black == 0)
										{
											_black = Sprite::Create("Res/Login/black.png");
											_black->SetScale(500);
											Add(_black);
											ClearUpdateFunc();
											AddUpdateFunc(UpdateFunc::Create(CALLBACK_PARAMETER_1(MainScene::Fade, this)));
											AudioManager::getInstance()->stopBGM();
											AudioManager::getInstance()->playSoundEffect("Sound/se/clear.mp3");
											return;
										}
									}
									else
									{

									}
								}
							}
							else
							{
								Effect* boom = Effect::Create("fire1");
								boom->SetTextureBlend(true);
								boom->SetPosition(bullet->GetPositionX(), bullet->GetPositionY(), bullet->GetPositionZ());
								boom->SetOrder(LAYER_ENEMY_BOOM);
								Add(boom);
								AudioManager::getInstance()->playSoundEffect("Sound/se/beiji.ogg");
							}
						}
					}
				}
			}
			else if (Tools::CheckHit_UnInclude(list.at(i),
				viewPos.x - viewRect.right / 2.0f - 300,
				viewPos.y - viewRect.bottom / 2.0f - 300,
				viewPos.x + viewRect.right / 2.0f + 300,
				viewPos.y + viewRect.bottom / 2.0f + 300))
			{
				list.at(i)->SetVisible(false);
			}
		}
		else if (list.at(i)->GetOrder() == LAYER_PLAYER)
		{
			for (int j = 0; j < list.size(); ++j)
			{
				if (list.at(j)->GetOrder() == LAYER_ENEMY_BULLET)
				{
					if (Tools::CheckHit_Point(list.at(j), list.at(i)))
					{
						Bullet* bullet = (Bullet*)list.at(j);
						if (bullet->IsCross() == false)
						{
							bullet->Die();
						}
						Own* own = (Own*)list.at(i);
						if (own->GetBulletLevel() > 1)
						{
							if (rand() % 2 == 1)
							{
								own->SetBulletLevel(own->GetBulletLevel() - 1);
							}
						}
						else
						{
							own->SetHp(own->GetHp() - bullet->GetAttack());
						}
						own->SetBruiseEnable(true);
						if (own->GetHp() <= 0)
						{
							//Director::getInstance()->SetPause(true);
						}
					}
				}
				else if (list.at(j)->GetOrder() == LAYER_ITEM)
				{
					if (Tools::CheckHit_Circle(list.at(j), list.at(i)))
					{
						Own* own = (Own*)list.at(i);
						Item* item = (Item*)list.at(j);
						own->UseItem(item);
						item->SetVisible(false);
						AudioManager::getInstance()->playSoundEffect("Sound/se/get_item.mp3");
					}
				}
			}
		}
	}
}