-2

Hello, i have been developing a game-project in Visual C++ 6.0 but now i have an extremely bad problem. When i start my game, it gets a lot of CPU usage - like 60-70%. When i start debugger it gives me a several errors, but i have no idea how to fix it. Throughly i'm using bitmaps and i don't know if that's the cause. Look how it looks - http://img2.imageshack.us/img2/716/guitarmaster.jpg
As you can see "Start Game" is marked and the bitmap has orange background and the others have black background. When an option is marked it puts another bitmap to the place of original. The bitmaps i load in this way

void Game::StartGame(CBitmap *p, CDC *pDC)
{
   CDC dcMemory;
   BITMAP bm;
   dcMemory.CreateCompatibleDC(pDC);
   dcMemory.SelectObject(p);
   p->GetBitmap(&bm);
   int x,y;
   x = (screenX*bm.bmWidth)/1280;tretchBlt(rect.right/2-bm.bmWidth/2, 2*y, x,y, &dcMemory, 0,0, bm.bmWidth, bm.bmHeight, SRCCOPY);
}

In my OnInitDialog() function my code is:

CRect rect;
    GetClientRect(&rect);
    CClientDC clientDC(this);
    pDC = new CDC();
    Bitmap = new CBitmap();
    Bitmap->CreateCompatibleBitmap(&clientDC,rect.right,rect.bottom);
    pDC->CreateCompatibleDC(&clientDC);
    pDC->SelectObject(Bitmap);

And in WM_TIMER (OnTimer) i use the following:

pDC->illSolidRect(rect, RGB(0,0,0));

and then the bitmap from above i load there

CBitmap startGame;
startGame.LoadBitmap(the_resource_here);   // if not marked
CBitmap startGame1;
startGame1.LoadBitmap(the_resource_here);   // if marked - here the bitmap file is different
I have a boolean variable to check if the menu item is marked or not - I make that in PreTranslateMessage();
In OnTimer() i go on with:
if(ifStartGame == true)
   StartGame(&startGame, pDC);
else
   StartGame(&startGame1, pDC);

Now the bad stuff;
My menu items(Start Game... About ... Exit) i control them using Arrow Keys from keyboard(in PreTranslateMessage).
When i press Enter in one of them it calls me a class(for example for start game - one class, for about - other class)
It works perfect until i press Enter on them 5-6 times, and then it stops calling the class windows.

I'll post my PreTranslateMessage() code below:

if (pMsg->message == WM_KEYUP)   
    {
        if(pMsg->wParam == VK_DOWN)
        {
            if(ifStartChecked == true)     // if start is true - it makes the next true and start - false
            {
                ifHowToPlayChecked = true;
                ifStartChecked = false;
            }
            else if(ifHowToPlayChecked == true)        
            {
                ifHowToPlayChecked = false;
                ifAboutChecked = true;
            }
            else if(ifAboutChecked == true)                                // HERE I CHANGE THE STATES - I MEAN THE PLAYER CHOOSES AN OPTION
            {
                ifAboutChecked = false;
                ifExitChecked = true;
            }
            else if(ifExitChecked == true)
            {
                ifExitChecked = false;
                ifStartChecked = true;
            }
        }

        if(pMsg->wParam == VK_RETURN)                    // IF THE PLAYER PRESSES ENTER IT CHECKS ON WHICH MENU ITEM ENTER IS PRESSED
        {
            if(ifStartChecked == true)
            {
                Class1 dlg1; 
                dlg1.DoModal();
            }
            else if(ifHowToPlayChecked == true)
            {
                Class2 dlg2;
                dlg2.DoModal();
            }
            else if(ifAboutChecked== true)
            {
                Class3 dlg3;
                dlg3.DoModal();
            }
            else if(ifExitChecked == true)
            {
                exit(0);
            }

Ah.. and -&gt is equal to "->" When i copied the code it pasted -&gt instead of ->

Edited by Nick Evan: Added code-tags

Votes + Comments
10+ posts, still no code tags - fail
2
Contributors
1
Reply
3
Views
7 Years
Discussion Span
Last Post by bman214
-1

I wish I could help. The thing is, i'm programming a TEXT-BASED game and I don't know how to add graphics (especialy moving ones) to C++.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.