Exemplo n.º 1
0
//我方方块移动
bool CMatchGame::MyBricksMove(float dt)
{
	if (!m_bConfirmMatch)
	{
		return false;
	}

	m_fWaitTime += dt;
	if (m_fWaitTime < 30)
	{
		return false;
	}

	//重置
	m_fWaitTime = 0;

	if (--m_iMyRowIdx >= m_iDestRowIdx + 2)
	{
		return true;
	}

	//已经和目标方块重合,更新游戏状态
	UpdateGameState();
	
	return true;
}
Exemplo n.º 2
0
//上按下
void CFlappyBirdGame::OnUpBtnPressed()
{
	if (m_enGameState != GAMESTATE_RUNNING)
	{
		return;
	}

	//重置按钮刷新时间
	m_fBirdTotalTime = BIRD_DOWN_INTERVAL - 3 * m_iSpeed;

	//按钮音效
	PLAY_EFFECT(EFFECT_CHANGE2);

	m_pGameScene->UpdateBrick(m_iBirdRowIdx, COLUMN_NUM / 2 - 1, false, false);

	if (--m_iBirdRowIdx < 0)
	{
		m_iBirdRowIdx = 0;
		m_enGameState = GAMESTATE_OVER;
	}

	m_pGameScene->UpdateBrick(m_iBirdRowIdx, COLUMN_NUM / 2 - 1, false, true);

	UpdateGameState();
}
	virtual void Update( float deltaTime )
	{
		UpdateSplashScreen();

		UpdateGameState();
		
		if (EGS_PLAYING == m_CurrentState)
		{
			UpdateSpawning( deltaTime );

			UpdateGlobalBlackboard( deltaTime );
		}

		DestroyPendingObjects();
		SpawnPendingObjects();
	}
Exemplo n.º 4
0
int main( int argc, char* argv[] )
{	

	Initialise( iScreenWidth, iScreenHeight, false, "Just Another Retro Pew Pew" );
	SetBackgroundColour( SColour( 000, 000, 000, 000 ) );

//	player.SetSpriteID(CreateSprite( "./images/player.png", player.GetWidth(), player.GetHeight(), true));

	GameStates eCurrentState = eMAIN_MENU;

	do 
	{
		ClearScreen();
		float fDeltaT = GetDeltaTime();
		switch (eCurrentState)
		{
	case eMAIN_MENU:
		UpdateMainMenu();
			if( IsKeyDown( KEY_ENTER) )
			{
				eCurrentState = eGAMEPLAY;
				
			
			}
			break;
	case eGAMEPLAY:
		UpdateGameState();
		if( IsKeyDown( KEY_ESCAPE) )
			{
				eCurrentState = eMAIN_MENU;

			}

		break;
	default:
		break;
		}
			
	} while ( FrameworkUpdate() == false );

	Shutdown();

	return 0;
}
Exemplo n.º 5
0
int main(unsigned int /*argc*/, const char* /*argv*/[])
{
    GameState state;
    ViewState viewState;

    auto previousTime = std::chrono::high_resolution_clock::now();
    std::chrono::microseconds remainingUpdateTime;

    while (viewState.window.isOpen())
    {
        const auto currentTime = std::chrono::high_resolution_clock::now();
        auto lastRenderDuration(std::chrono::duration_cast<std::chrono::microseconds>(currentTime - previousTime));
        previousTime = currentTime;
        remainingUpdateTime += lastRenderDuration;

        ProcessWindowEvents(viewState.window, state);

        const unsigned int kDesiredUdatesPerSecond = 60;
        const auto kUpdateStepDuration = std::chrono::microseconds(1000000) / kDesiredUdatesPerSecond;
        unsigned int updateIterationsPerformedThisFrame = 0;
        while (remainingUpdateTime >= kUpdateStepDuration)
        {
            UpdateGameState(state, kUpdateStepDuration);
            remainingUpdateTime -= kUpdateStepDuration;

            // Ensure that we don't spiral out of control
            ++updateIterationsPerformedThisFrame;
            if (updateIterationsPerformedThisFrame > kDesiredUdatesPerSecond)
            {
                std::cerr << "Updates are "
                    << std::chrono::duration_cast<std::chrono::milliseconds>(remainingUpdateTime).count()
                    << "ms behind" << std::endl;
                break;
            }
        }

        Render(state, viewState, lastRenderDuration, remainingUpdateTime);
    }

    return 0;
}
Exemplo n.º 6
0
//目标方块移动
bool CMatchGame::DestBricksMove( float dt )
{
	m_fDestBrickMoveTime += dt;
	if (m_fDestBrickMoveTime < BRICK_MOVE_INTERVAL - 70 * m_iSpeed)
	{
		return false;
	}

	//重置
	m_fDestBrickMoveTime = 0;

	//目标方块下降一格
	if (++m_iDestRowIdx <= m_iMyRowIdx - 2)
	{
		return true;
	}

	//更新游戏状态
	UpdateGameState();

	return true;
}
Exemplo n.º 7
0
//更新
void CFlappyBirdGame::Play(float dt)
{
	if (m_enGameState == GAMESTATE_RUNNING)
	{
		bool bRefreshFlag = BirdMove(dt);
		bRefreshFlag = PillarMove(dt) || bRefreshFlag;
		if (!bRefreshFlag)
		{
			return;
		}

		UpdateGameState();
	}
	else if (m_enGameState == GAMESTATE_OVER)
	{
		m_fRefreshTime += dt;
		if (m_fRefreshTime < GAMEOVER_WAITTIME)
		{
			return;
		}

		//设置剩余生命
		--m_iLife;
		m_pGameScene->UpdateSmallBricks();

		//检查是否有剩余生命,没有则返回游戏结束界面
		if (m_iLife <= 0)
		{
			m_pGameScene->RunScene(SCENE_GAMEOVER);
			return;
		}

		//重置数据
		InitData();
	}

	m_pGameScene->UpdateBricks();
}
Exemplo n.º 8
0
void ActTest(AbstractRoom * Start, Holdall &PlayerBag, std::string *ActList, int numActs)
{
	bool Enigmatic = false; // TODO: convert this to flags
	AbstractRoom * currentRoom;
	//AbstractRoom* allRooms[NumRooms];
	int GameClock = 0;
	int Flags = 0;

	PlayerBag.Capacity = 10;
	std::cout << "Player bag capacity = " << PlayerBag.Capacity << std::endl;

	//AbstractRoom* Start = BuildTheHouse(allRooms);
	//FillTheRooms(allRooms);

	//PlayerBag.Contents = EquipThePlayer();

	int MoveCounter = 0;
	std::string nothing;
	currentRoom = Start;

	while (GameClock < GameLength)
	{
		std::cout << std::endl;
		currentRoom->Print(Enigmatic);
		currentRoom = currentRoom->NextUserActionTest(&PlayerBag, ActList[MoveCounter++]);
		//currentRoom = currentRoom->NextUserAction(&PlayerBag);
		if (currentRoom == 0 ) break;
		if (MoveCounter >= numActs) break;
		if ( 0 )
		{
			// Turn this on for step-by-step walkthroughs
			std::cout << "Step " << MoveCounter << ", hit <return> to continue: ";
			getline(std::cin, nothing);
		}
		UpdateGameState(Flags, GameClock, &PlayerBag, currentRoom);
		CheckForTimers(allRooms, GameClock, &PlayerBag);
	}
	if (GameClock >= GameLength)
		std::cout << "It's 4:00. Your friends have arrived. You are out of time." << std::endl;

	int points = PlayerBag.getGameTaskStatus();

	std::cout << std::endl;
	if (points ==2)
		std::cout 
			<< "Success!" << std::endl
			<< "You met the rudimentary needs for a nice tea." << std::endl
			<< "Maybe next time you could do a little more to make it special." << std::endl
			<< "Your friends still like you. They'll come again." << std::endl;
	else if (points >2)
		std::cout 
			<< "Success!" << std::endl
		 	<< "Congratulations, you made a superbly nice tea!" << std::endl
			<< "Your friends tweet about it. Their pictures go viral." << std::endl
			<< "You're invited to BBC headquarters to meet the cast of" << std::endl
			<< "Pride&Prejudice. They hire you as a consulting writer."<< std::endl;
  else
		std::cout 
			<< "You did not succeed :(" << std::endl
			<< "You didn't meet the rudimentary needs for a nice tea." << std::endl
			<< "Your Tea Party is a failure. Your friends tweet about it." << std::endl
			<< "You are banned for life from Jane Austen Society meetings." << std::endl
			<< "You start reading Edward Gorey and listening to emo music." << std::endl;

}
Exemplo n.º 9
0
int main( int argc, char* argv[] )
{	

	Initialise(iScreenWidth, iScreenHeight, false, "Space Invaders");
    
	SetBackgroundColour(SColour(0x00, 0x00, 0x00, 0xFF));

	//player settings
	player.SetSize(64.0f, 32.0f);
	player.iSpriteID = CreateSprite("./images/cannon.png", player.fWidth, player.fHeight, true);
	player.SetMovementExtremes(0.0f, iScreenWidth);
	player.SetMovementKeys(65, 68);
	player.x = iScreenWidth * 0.5f;
	player.y = 88.0f;

	//create Marquee sprite
	iArcadeMarquee = CreateSprite("./images/Space-Invaders-Marquee.png", iScreenWidth, iScreenHeight, true);

	//enemy creation
	CreateEnemies();
	enemyDirection = eRIGHT;
	nextDirection = eRIGHT;

	//font setting
	AddFont(pInvadersFont);

	//game state declaration
	GAMESTATES eCurrentState = eMAIN_MENU;

    //Game Loop
    do
    {
		float fDeltaT = GetDeltaTime();

		switch (eCurrentState) {
		case eMAIN_MENU:

			UpdateMainMenu();

			//input
			if (IsKeyDown(257) && !IsKeyDown(256)) {
				eCurrentState = eGAMEPLAY;
				ResetEnemies();
			}

			break;

		case eGAMEPLAY:

			UpdateGameState(fDeltaT);

			//ChangeState
			if (IsKeyDown(256)) {
				eCurrentState = eMAIN_MENU;
			}

			break;

		default:
			break;
		}

		//clear screen
		ClearScreen();


    } while(!FrameworkUpdate());

	Shutdown();

    return 0;
}
Exemplo n.º 10
0
// -----------------------------------------------------------------------------------------------
// Update and Update States:
// -----------------------------------------------------------------------------------------------
void PlayerInstance :: Update()
{
	if(playerState == PLAYER_STATE_USE_ITEM)
	{
		UpdateGameState();
	}
	else if(playerState == PLAYER_STATE_BUILD)
	{

	}
	else if(playerState == PLAYER_STATE_INVENTORY)
	{
		UpdateInventoryState();
	}

	DrawGameHUD();
	
	vector3df camPos = position + vector3df(0,PLAYER_HEIGHT,0) + vector3df(lookAtHeading.X, 0, lookAtHeading.Z) * 0.5f;

	IRR->camera->setPosition(camPos);
	IRR->camera->setTarget(camPos + lookAtHeading);

	CharacterInstance::Update();

	

		/*
		// Place targeting cube:
		vector3di openBlock;
		if(MapMgr->GetLastOpenBlock(position, camHeading, 3.0f, openBlock))
		{
			targetCube->setPosition(vector3df(0.5f + openBlock.X, 0.5f + openBlock.Y, 0.5f + openBlock.Z));
		}
		*/

		/*
		// Place Items by first holding down Q to display objectPlaceNode
		if(IRR->receiver->key_is_down[KEY_KEY_Q] && !selectedSlot->IsEmpty())
		{
			if( !objectPlaceNode->isVisible() )
			{
				objectPlaceNode->setVisible(true);
				objectPlaceNode->setMesh( inventorySlots[hotBarSlotSelected][HOT_BAR_Y].GetMesh());
			}

			vector3df pos;

			if( GManager->GetPointOfItemOrMapCollision(position, camHeading, 3.0f, pos))
			{
				objectPlaceNode->setPosition(pos);
				objectPlaceNode->setRotation( vector3df(0, yRotation, 0) );
			}
			else
			{
				objectPlaceNode->setVisible(false);
			}
			
		}
		
		// While Q is down and mouse is clicked, Place currently selected item:
		vector3df pos;
		if(IRR->receiver->key_is_down[KEY_KEY_Q] 
		&& IRR->receiver->key_is_down[KEY_LBUTTON] 
		&& actionDelay <= 0 
		&& !selectedSlot->IsEmpty() 
		&& GManager->GetPointOfItemOrMapCollision(position, camHeading, 3.0f, pos))
		{
			GManager->CreateItemInstance(selectedSlot->GetItem(), pos, vector3df(0, yRotation, 0));
			selectedSlot->RemoveFromSlot(1);
			actionDelay = 20;
		}
		

		vector3df pos;
		// While F is down, display Zombie Mesh for placing:
		if(IRR->receiver->key_is_down[KEY_KEY_F])
		{
			if( !objectPlaceNode->isVisible() )
			{
				objectPlaceNode->setVisible(true);
				objectPlaceNode->setMesh(IRR->sceneMgr->getMesh("mdl/Zombie.irrmesh"));
			}

			vector3df pos;
			if( MapMgr->GetPointOfMapCollision(position, camHeading, 3.0f, pos) )
			{
				objectPlaceNode->setPosition(pos);
				objectPlaceNode->setRotation( vector3df(0, yRotation, 0) );
			}
			else
			{
				objectPlaceNode->setVisible(false);
			}
			
		}
		

		// While F is down and mouse is pressed, place a zombie
		if(IRR->receiver->key_is_down[KEY_KEY_F] 
		&& IRR->receiver->key_is_down[KEY_LBUTTON] 
		&& actionDelay <= 0 
		&& MapMgr->GetPointOfMapCollision(position, camHeading, 3.0f, pos))
		{
			InstanceMgr->CreateZombieInstance(pos);
			actionDelay = 20;
		}

		if(!IRR->receiver->key_is_down[KEY_KEY_Q] && !IRR->receiver->key_is_down[KEY_KEY_F])
		{
			objectPlaceNode->setVisible(false);
		}
	}
	*/
}