Im sorry guys, I forgot to mention that Im using MFC here, so there is no game message loop. This timer takes care of almost everything. I've fixed the bugs I had and am now working on drawing problems.
Heres my render function or atleast the part that isn't working perhaps you guys have some ideas. It works the way I thin it should before
//Get the rect area of the entire screen CRect rect; GetClientRect (&rect); //Create a DC for the primary surface CClientDC dc (this); // off-screen pixels CBitmap bmOff; bmOff.CreateCompatibleBitmap (&dc, rect.Width(), rect.Height()); //create a memory DC compatible with the primary surface CDC memDC; memDC.CreateCompatibleDC (&dc); //make sure to save the old 1x1 Bitmap CBitmap * pOldOffBM = memDC.SelectObject (&bmOff); // draw to offscreen DC //memDC.FillSolidRect (&rect, RGB (215, 215, 0)); //desert to buggie on /* No more desert to buggie on, its time to buggie on something more realisitic. Implementing map rendering here. */ // Load bitmap //create an instance of CBitmap CBitmap bmMap; // DC CDC memBitmapDC; memBitmapDC.CreateCompatibleDC(&dc); // load the bitmap resource into the bitmap instance bmMap.LoadBitmap(IDB_DEFAULTMAP); // select the bitmap into the DC (remember to save the old one!) CBitmap * pOldddddddy = memBitmapDC.SelectObject(&bmMap); // TRACE("[%f,%f]\n", m_cNewBuggie.GetXPos(), m_cNewBuggie.GetYPos()); // This will do the drawing int iYOffSet(static_cast<int>(m_cNewBuggie.GetYPos())%32); int iXOffSet(static_cast<int>(m_cNewBuggie.GetXPos())%32); for(int iWinYPos(-32), iLogicalY((m_cNewBuggie.GetYPos()-(550/2)+64)/32); iWinYPos<576; iWinYPos += 32, iLogicalY++) for(int iWinXPos(-32), iLogicalX((m_cNewBuggie.GetXPos()-(1000/2)+64)/32); iWinXPos<1028; iWinXPos += 32, iLogicalX++){ // Our window variables for drawing // We have twenty tiles switch(m_gmCurrent.iMapTiles[iLogicalY][iLogicalX]){ case 0: memDC.BitBlt(iWinXPos, iWinYPos, 32, 32, &memBitmapDC, 0, 0, SRCCOPY); break; case 1: memDC.BitBlt(iWinXPos, iWinYPos, 32, 32, &memBitmapDC, 32, 0, SRCCOPY); break; case 2: memDC.BitBlt(iWinXPos, iWinYPos, 32, 32, &memBitmapDC, 64, 0, SRCCOPY); break; case 3: memDC.BitBlt(iWinXPos, iWinYPos, 32, 32, &memBitmapDC, 96, 0, SRCCOPY); case 4: memDC.BitBlt(iWinXPos, iWinYPos, 32, 32, &memBitmapDC, 0, 32, SRCCOPY); break; case 5: memDC.BitBlt(iWinXPos, iWinYPos, 32, 32, &memBitmapDC, 32, 32, SRCCOPY); break; case 6: memDC.BitBlt(iWinXPos, iWinYPos, 32, 32, &memBitmapDC, 64, 32, SRCCOPY); break; case 7: memDC.BitBlt(iWinXPos, iWinYPos, 32, 32, &memBitmapDC, 96, 32, SRCCOPY); break; case 8: memDC.BitBlt(iWinXPos, iWinYPos, 32, 32, &memBitmapDC, 0, 64, SRCCOPY); break; case 9: memDC.BitBlt(iWinXPos, iWinYPos, 32, 32, &memBitmapDC, 32, 64, SRCCOPY); break; case 10: memDC.BitBlt(iWinXPos, iWinYPos, 32, 32, &memBitmapDC, 64, 64, SRCCOPY); break; case 11: memDC.BitBlt(iWinXPos, iWinYPos, 32, 32, &memBitmapDC, 96, 64, SRCCOPY); break; case 12: memDC.BitBlt(iWinXPos, iWinYPos, 32, 32, &memBitmapDC, 0, 96, SRCCOPY); break; case 13: memDC.BitBlt(iWinXPos, iWinYPos, 32, 32, &memBitmapDC, 32, 96, SRCCOPY); break; case 14: memDC.BitBlt(iWinXPos, iWinYPos, 32, 32, &memBitmapDC, 64, 96, SRCCOPY); break; case 15: memDC.BitBlt(iWinXPos, iWinYPos, 32, 32, &memBitmapDC, 96, 96, SRCCOPY); break; case 16: memDC.BitBlt(iWinXPos, iWinYPos, 32, 32, &memBitmapDC, 0, 129, SRCCOPY); break; case 17: memDC.BitBlt(iWinXPos, iWinYPos, 32, 32, &memBitmapDC, 32, 129, SRCCOPY); break; case 18: memDC.BitBlt(iWinXPos, iWinYPos, 32, 32, &memBitmapDC, 64, 129, SRCCOPY); break; case 19: memDC.BitBlt(iWinXPos, iWinYPos, 32, 32, &memBitmapDC, 96, 129, SRCCOPY); break; default: memDC.BitBlt(iWinXPos, iWinYPos, 32, 32, &memBitmapDC, 96, 129, SRCCOPY); break; } } memBitmapDC.SelectObject(pOldddddddy); m_cNewBuggie.Render (&memDC); for(int i(0); i < 4; i++) if(m_cbBuggies) m_cbBuggies->Render(&memDC); // flip to primary dc.BitBlt (0, 0, rect.Width(), rect.Height(), &memDC, 0, 0, SRCCOPY); // restore all surfaces/objects memDC.SelectObject (pOldOffBM);
Thats just all the code, though you only need to pay attention to the for loop with the offset. Im trying to draw a grid of map tiles. But I want it to look smooth as the buggy moves per pixel. Anyways again thanks for any of the help that you can offer.
Okay I fixed some of the code, it now looks like this, runs better but still doesn't run correctly. As well Im having some more troubles, these toubles are with collission detection. If you have any suggestions feel free.