Example #1
0
//-----------------------------------------------------------------------------
// Purpose: Spawn blocks for balls to break.
//-----------------------------------------------------------------------------
void CGameLogic::CreateBlocks( void )
{
#if 1
	int nBlocks = m_bLessBlocks ? 11 : 22;

	// TEMP: Spawn a bunch of blocks.
	for ( int y = 4; y >= 0; y-- )
	{
		for ( int x = 0; x < nBlocks; x++ )
		{
			Vector vecOrigin( x * 30 + 21.0f + 30 * ( 11 - nBlocks / 2 ), g_ScreenRect.height * 0.5f + 30.0f * ( y - 2 ) );
			CBlock *pBlock = CreateEntity<CBlock>( vecOrigin );
			//printf( "0: %g %g\n", vecOrigin.x, vecOrigin.y );

			if ( pBlock )
			{
				pBlock->SetType( RandomInt( 0, BLOCK_COUNT ) );
			}
		}
	}
#else
	std::string strLine;
	std::ifstream fileStream;
	fileStream.open( "level.txt" );

	while ( !fileStream.eof() )
	{
		std::getline( fileStream, strLine );

		int iType = 0;
		Vector vecPos;
		sscanf( strLine.c_str(), "%d: %f %f", &iType, &vecPos.x, &vecPos.y );

		CBlock *pBlock = CreateEntity<CBlock>( vecPos );
		if ( pBlock )
		{
			pBlock->SetType( iType );
		}
	}

	fileStream.close();
#endif
}