当前位置: 首页>>代码示例>>C++>>正文


C++ Projectile::Update方法代码示例

本文整理汇总了C++中Projectile::Update方法的典型用法代码示例。如果您正苦于以下问题:C++ Projectile::Update方法的具体用法?C++ Projectile::Update怎么用?C++ Projectile::Update使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Projectile的用法示例。


在下文中一共展示了Projectile::Update方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: Update

void BattleStage::Update()
{

	while( GameObjectsToAdd.size() > 0 )
	{
		Projectile* p = GameObjectsToAdd.front();
		GameObjectsToAdd.pop_front();
		GameObjects.push_back( p );
	}

	while( GameObjectsToRemove.size() > 0 )
	{
		Projectile* p = GameObjectsToRemove.front();
		GameObjectsToRemove.pop_front();
		GameObjects.remove( p );
		delete p;
	}

	for( std::list<Projectile*>::const_iterator i = GameObjects.begin(); i != GameObjects.end(); i++ )
	{
		Projectile* p = (*i);
		p->Update();
	}

	LeftPlayer->Update();
	RightPlayer->Update();

	if( ((BattlePlayer*)LeftPlayer)->TargetHealth == 0 || ((BattlePlayer*)RightPlayer)->TargetHealth == 0 )
	{
		FRAMEWORK->ProgramStages->Push( new TransitionStrips( new BattleOver( this ), FRAMES_PER_SECOND, 80 ) );
	}

	for( std::list<Pickup*>::const_iterator i = GamePickups.begin(); i != GamePickups.end(); i++ )
	{
		Pickup* p = (*i);
		p->Update();
	}
}
开发者ID:foxblock,项目名称:Pong,代码行数:38,代码来源:battle.cpp

示例2: main


//.........这里部分代码省略.........

        switch (event.type) { // HANDLE ALLEGRO EVENTS
            case ALLEGRO_EVENT_TIMER:
                render = true;
                if (stage == Game) spawn_counter++;
                break;
            case ALLEGRO_EVENT_DISPLAY_CLOSE:
                executing = false;
                break;
            case ALLEGRO_EVENT_KEY_DOWN:
                executing = event.keyboard.keycode != ALLEGRO_KEY_ESCAPE;
                switch(event.keyboard.keycode) {
                    case ALLEGRO_KEY_A:
                    case ALLEGRO_KEY_LEFT:
                        if (stage == Game) player->Velocity.x = -5;
                        break;
                    case ALLEGRO_KEY_D:
                    case ALLEGRO_KEY_RIGHT:
                        if (stage == Game) player->Velocity.x = 5;
                        break;
                }
                break;
            case ALLEGRO_EVENT_KEY_UP:
                if (stage == Game) {
                    player->Velocity.x = 0;
                    player->Velocity.y = 0;
                }
                break;
            default: break;
        }

        switch (stage) { // UPDATE
            case Menu:
                play->Update(&event);
                leaderboard->Update(&event);
                options->Update(&event);
                quit->Update(&event);
                break;
            case Game:
                if (player->m_body->GetPosition().x < 1) player->m_body->SetTransform(b2Vec2(screen_w - 2, player->m_body->GetPosition().y), 0);
                if (player->m_body->GetPosition().x > screen_w - 1) player->m_body->SetTransform(b2Vec2(2, player->m_body->GetPosition().y), 0);
                if (spawn_counter > 75) {
                    spawn_counter = 0;
                    ALLEGRO_BITMAP *meteor_png;
                    switch (rand() % 4) { // Size
                    case 0:
                        switch (rand() % 4) { // Selection
                        case 0:
                            meteor_png = rand() % 2 ? assets->png_meteor_brown_big1 : assets->png_meteor_grey_big1;
                            break;
                        case 1:
                            meteor_png = rand() % 2 ? assets->png_meteor_brown_big2 : assets->png_meteor_grey_big2;
                            break;
                        case 2:
                            meteor_png = rand() % 2 ? assets->png_meteor_brown_big3 : assets->png_meteor_grey_big3;
                            break;
                        case 3:
                            meteor_png = rand() % 2 ? assets->png_meteor_brown_big4 : assets->png_meteor_grey_big4;
                            break;
                        default: break;
                        }
                        break;
                    case 1:
                        switch (rand() % 2) { // Selection
                        case 0:
                            meteor_png = rand() % 2 ? assets->png_meteor_brown_med1 : assets->png_meteor_grey_med1;
开发者ID:tsteinholz,项目名称:SpaceShooterIII,代码行数:67,代码来源:main.cpp

示例3: Update

/**
* Update cycle
*
* Checks for keypresses:
*   - Esc - Quits the game
*   - Left - Rotates ship left
*   - Right - Rotates ship right
*   - Up - Accelerates the ship
*   - Down - Deccelerates the ship
*
* Also calls Update() on all the ships in the universe
*/
bool Application::Update()
{
	float timedelta = hge_->Timer_GetDelta();
	if (bulletShootTimer < S_BULLET_SHOOT_INTERVAL)
	{
		bulletShootTimer += timedelta;
	}
	if (missileShootTimer < S_MISSILE_SHOOT_INTERVAL)
	{
		missileShootTimer += timedelta;
	}

	ships_.at(0)->SetAngularVelocity(0.0f);

	// Lab 13 Task 4 : Add a key to shoot missiles
	/*if (hge_->Input_GetKeyState(HGEK_ENTER))
	{
		if (!keydown_enter)
		{
			CreateMissile(ships_.at(0)->GetX(), ships_.at(0)->GetY(), ships_.at(0)->GetW(), ships_.at(0)->GetID());
			keydown_enter = true;
		}
	}
	else
	{
		if (keydown_enter)
		{
			keydown_enter = false;
		}
	}*/

	static const float MAX_ENTER_TIMER = 0.5f;
	static float enterTimer;

	if (enterTimer < MAX_ENTER_TIMER)
	{
		enterTimer += timedelta;
	}

	// Chat
	if (chatMode)
	{
		char input = hge_->Input_GetKey();

		if (input == HGEK_ESCAPE)
		{
			chatMode = false;
			typingMsg = "";
		}
		else if (input == HGEK_ENTER && enterTimer >= MAX_ENTER_TIMER)
		{
			// Send
			if (typingMsg != "")
			{
				RakNet::BitStream chatBS;
				chatBS.Write((unsigned char)ID_CHAT_SEND);
				chatBS.Write(typingMsg.c_str());
				rakpeer_->Send(&chatBS, HIGH_PRIORITY, RELIABLE_ORDERED, 0, UNASSIGNED_SYSTEM_ADDRESS, true);
				chatList.push_back(typingMsg);
			}

			// Reset
			chatMode = false;
			typingMsg = "";
			enterTimer = 0.f;
			chatShowTimer = 5.f;
		}
		else if (input >= 32 && input <= 126)
		{
			typingMsg += input;
		}
	}
	else
	{
		if (chatShowTimer > 0.f)
		{
			chatShowTimer -= timedelta;
		}

		if (hge_->Input_GetKeyState(HGEK_ENTER) && enterTimer >= MAX_ENTER_TIMER)
		{
			chatMode = true;
			enterTimer = 0.f;
		}

		// Ship controls
		if (hge_->Input_GetKeyState(HGEK_LEFT))
		{
//.........这里部分代码省略.........
开发者ID:NothingMuch123,项目名称:Multiplayer-Assignment-2,代码行数:101,代码来源:Application.cpp


注:本文中的Projectile::Update方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。