What's wrong with my game?

Started by
14 comments, last by ChocaPaluza123 22 years, 9 months ago
You can''t call DeleteObject etc outside of your functions!! I would recommend you get a basic book on C++ and learn that before learning games-specific techniques, especially graphics. Start out with basic console in/out stuff and then move forwards.

> Andrew.
Advertisement
quote:Original post by shaft
If you are using Visual C++, I recommend you use the TRACE("") statements to make sure the code you think is executing is actually getting executing.


I think this only works in MFC? In Win32 or DX I think you have to use OutputDebugString().

> Andrew.

adpeace is correct: TRACE("") only works within MFC.

ChocaPaluza123: why is your paddle RECT static? And where is it declared? If you declare it outside of any function (at the top, if you like, just after the header #include''s) then all functions within your source file will be able to access it because it has global scope . If you declare it as static at global scope, however, then you wont be able to modify it after intiilization. It seems you really want a DrawPaddle() function which maintains the static RECT. So your main loop/function will handle the keyboard input ( if(KEY_DOWN(...)) ) and then call DrawPaddle(), which will call InvalidateRect() to send a WM_PAINT message to Windows.

Keep posting. You''re trying first, which is why you''re getting quality replies (and don''t need to be so apologetic).
quote:Original post by Oluseyi
If you declare it outside of any function (at the top, if you like, just after the header #include''s) then all functions within your source file will be able to access it because it has global scope . If you declare it as static at global scope, however, then you wont be able to modify it after intiilization.


No, static at the file scope means it can''t be accessed outside that file. const at any scope means you can''t change it after initialization.

As for the original question, you''re still right. He wants to declare left_paddle outside of any functions, so any functions in that file can access it. Whether or not the static is there doesn''t really matter (since this is a first project, I doubt he''s got more than one .cpp file anyway.)

Anyway, good luck!
You guys got me thinking. Thanks for all those messages, and I think I should read a book other than C++ For Dummies and Windows Game Programming for Dummies.

C++
C++
Since you guys are getting really involved with this (a lot more than I thought), I''ll show you how my code is going now. I''ll try to pick up a copy of C++: The Complete Reference or something like that.

int MakeRect (int nLeft, int nTop, int nRight, int nBottom)
{
static RECT paddle;
paddle.left = nLeft;
paddle.top = nTop;
paddle.right = nRight;
paddle.bottom = nBottom;
}

if (KEY_DOWN(''A''))
{
}

if (KEY_DOWN(''Z''))
{
}

// what is the message
switch(msg)
{
case WM_CREATE:
{
// do initialization stuff here
return(0);
} break;

case WM_PAINT:
{
// start painting
hdc = BeginPaint(hwnd,&ps);

// GRAPHICS
// Step 1: Create the two paddles. Make their height about 40 pixels high and about 5 pixels wide,
// making their starting position 220 (top), 260 (bottom), 10 (facing the edge of the screen),
// and 15 (facing the center of the screen). Position them 10 pixels away from the edge
// of the screen and center them

HBRUSH brush = CreateSolidBrush(RGB(0,0,0));

MakeRect(10,200,300,15);

// draw it
FillRect(hdc,&paddle,brush);

DeleteObject(&brush);

// end painting
EndPaint(hwnd,&ps);
return(0);
} break;

C++
C++

This topic is closed to new replies.

Advertisement