Original Post
I am making a Space Invaders clone for my final project in Visual C++/MFC. The lil tank moves and fires, I even have the "invaders" on the screen and moving back and forth. As of right now i display the invaders using a for loop. Here is the code I use:
// draws the first row of invaders, the "red invaders"
void CSpace_Invaders_CloneView::DrawFirstSet()
{
CBitmap bmp;
// chooses which bitmap to load
if( m_blInvaderState == false )
{
bmp.LoadBitmap( IDB_TOP_INVADER_CLOSE );
}
else
{
bmp.LoadBitmap( IDB_TOP_INVADER_OPEN );
}
CClientDC dc(this);
CDC bmDC;
bmDC.CreateCompatibleDC(&dc);
CBitmap *pOldbmp = bmDC.SelectObject(&bmp);
BITMAP bi;
bmp.GetBitmap(&bi);
for( int i = 0; i < 550; i += 50 )
{
dc.BitBlt(( 5 + i ) + m_nMoveInvaderX,60 + m_nMoveInvaderY,bi.bmWidth,bi.bmHeight,&bmDC,0,0,SRCCOPY);
}
bmDC.SelectObject(pOldbmp);
}
// draws the second and third rows of invaders, the "blue invaders"
void CSpace_Invaders_CloneView::DrawSecondSet()
{
CBitmap bmp;
// chooses which bitmap to load
if( m_blInvaderState == false )
{
bmp.LoadBitmap( IDB_MIDDLE_INVADER_CLOSE );
}
else
{
bmp.LoadBitmap( IDB_MIDDLE_INVADER_OPEN );
}
CClientDC dc(this);
CDC bmDC;
bmDC.CreateCompatibleDC(&dc);
CBitmap *pOldbmp = bmDC.SelectObject(&bmp);
BITMAP bi;
bmp.GetBitmap(&bi);
for( int i = 0; i < 550; i += 50 )
{
dc.BitBlt(( 0 + i ) + m_nMoveInvaderX,100 + m_nMoveInvaderY,bi.bmWidth,bi.bmHeight,&bmDC,0,0,SRCCOPY);
dc.BitBlt(( 0 + i ) + m_nMoveInvaderX,140 + m_nMoveInvaderY,bi.bmWidth,bi.bmHeight,&bmDC,0,0,SRCCOPY);
}
bmDC.SelectObject(pOldbmp);
}
// draws the fourth and fifth rows of invaders, the "white invaders"
void CSpace_Invaders_CloneView::DrawThirdSet()
{
CBitmap bmp;
// chooses which bitmap to load
if( m_blInvaderState == false )
{
bmp.LoadBitmap( IDB_BOTTOM_INVADER_CLOSE );
}
else
{
bmp.LoadBitmap( IDB_BOTTOM_INVADER_OPEN );
}
CClientDC dc(this);
CDC bmDC;
bmDC.CreateCompatibleDC(&dc);
CBitmap *pOldbmp = bmDC.SelectObject(&bmp);
BITMAP bi;
bmp.GetBitmap(&bi);
for( int i = 0; i < 550; i += 50 )
{
dc.BitBlt(( 0 + i ) + m_nMoveInvaderX,180 + m_nMoveInvaderY,bi.bmWidth,bi.bmHeight,&bmDC,0,0,SRCCOPY);
dc.BitBlt(( 0 + i ) + m_nMoveInvaderX,220 + m_nMoveInvaderY,bi.bmWidth,bi.bmHeight,&bmDC,0,0,SRCCOPY);
}
bmDC.SelectObject(pOldbmp);
}
It all works but I don''t think I can do collision detection going about it this way. Everything I have read suggests using a two dimensional array. The only problem is i have no clue as to what to put in the array. Since I am using MFC I would probably create my own CArray class, something along the lines of CArray< CBitmap, CBitmap& > if that is even right I don''t know, I''ve also read about ImageLists. They seem as though they might come in handy but again I have no idea of what to put in them.
Of course any help would be appreciated.