well when i compile my game i get a weird freezing error when i start the exe file
Printable View
well when i compile my game i get a weird freezing error when i start the exe file
Try a warmer room.
In all seriousness just posting a problem with tons of source is a bit lazy. What are the errors?
Any compiler warnings? When does it crash?
Learn how to use a debugger.
it crashes my computer xD, yet i try some debugging crashes agian
Also sounds like a case of programming it completely before any kind of testing has been done. Basicly in the future you want to add small(ish) pieces of code and then run tests on the program, just so you can spot problem-areas when things crashes. This will help you debug these types of problems.
well i have been debugging it, and i still get a case of a freezing screen as the output i do suspect it's from my GameInit() function thou
im still a bit new to windows soo i wish for some help and advice on how to fix this bug.....Code:void GameInit()
{
HDC hdcc =GetDC(ghWnd);
SetRect(&rtemp,0,0,SCREEN_WIDTH * BAR_SIZE,SCREEN_HEIGHT * BAR_SIZE);
AdjustWindowRect(&rtemp,WS_CAPTION|WS_VISIBLE|WS_SYSMENU,false);
SetWindowPos(ghWnd,NULL,0,0,SCREEN_WIDTH * BAR_SIZE,SCREEN_HEIGHT * BAR_SIZE,SWP_NOMOVE);
MapImage.CreateImage(hdcc,"gamescreen.bmp");
BarImage.CreateImage(NULL,"Bar.bmp");
BallImage.CreateImage(NULL,"ball.bmp");
Paddle.CreateImage(NULL,"Paddle.bmp");
NewGame();
}
void NewGame()
{
GAMESTARTED = false;
for(int xmi = 0; xmi < SCREEN_WIDTH; ++ xmi)
for(int ymi = 0; ymi < 60; ++ymi)
{
if(ymi < 10)
MAP[xmi][ymi] = REDBAR;
else
MAP[xmi][ymi] = BLACKBAR;
DrawBars(xmi,ymi,MAP[xmi][ymi]);
}
ball.Startpos( SCREEN_WIDTH / 2, 120 );
PaddleInit();
UpDateGame();
}
void UpDateGame()
{
if( GAMESTARTED == true)
{
collision();
PREBALL_X = BALL_X;
PREBALL_Y = BALL_Y;
BALL_X = ball.GetX_val();
BALL_Y = ball.GetY_val();
ball.Move();
DrawPaddle(Paddle_X, Paddle_Y);
UpdateWindow(ghWnd);
ShowWindow(ghWnd,SW_SHOW);
}
InvalidateRect(ghWnd,NULL,false);
}
You call GetDC, but do you call ReleaseDC anywhere?
ooh well thanks for that point
when i used breakspoint it stop at DrawBars() function, so that might be an error somewhere in there too...
the whole main code is thisCode:void NewGame()
{
GAMESTARTED = false;
for(int xmi = 0; xmi < SCREEN_WIDTH; ++ xmi)
for(int ymi = 0; ymi < 60; ++ymi)
{
if(ymi < 10)
MAP[xmi][ymi] = REDBAR;
else
MAP[xmi][ymi] = BLACKBAR;
DrawBars(xmi,ymi,MAP[xmi][ymi]);
}
void DrawPaddle(int _X, int _Y)
{ //checks to see if there was any previous ball movement
if(Paddle_Move == true)
BitBlt(MapImage,PrePaddle_X,PrePaddle_Y,8,1,Paddle,0,1,SRCCOPY);
//updates iamge
BitBlt(MapImage,_X,_Y,8,1,Paddle,0,0,SRCCOPY);
};
Code:#include "ball.h"
#include "ImageClass.h"
#include<windows.h>
//size of bars
#define BAR_SIZE 8
#define SCREEN_WIDTH 20
#define SCREEN_HEIGHT 30
//color bars
#define REDBAR 1
//to erase bars
#define BLACKBAR 0
//map array fir bars to be place in
int MAP[SCREEN_WIDTH ][SCREEN_HEIGHT];
// value ot use when to check the game is finish
bool GAMESTARTED;
// check if paddle is moving
bool Paddle_Move = false;
//gets time in milli seconds
// Started time
DWORD timerstart;
// difference of start and current time
DWORD timercurrent;
//images for each visible component
//ball
ImageClass BallImage;
//map
ImageClass MapImage;
//bars
ImageClass BarImage;
//paddle
ImageClass Paddle;
//global handle
HWND ghWnd;
// a class to calculate ball's movements
BallClass ball;
//current ball's coordiantes
int BALL_X;
int BALL_Y;
//preious coordinates
int PREBALL_X;
int PREBALL_Y;
//current paddle coordinates
int Paddle_X =0;
int Paddle_Y =0;
// previous paddle coordinates
int PrePaddle_X;
int PrePaddle_Y;
//sets the new game
void NewGame();
// draws bar image
void DrawBars(int x, int y, int title);
// checks for bar and ball collision (still working on it )
void collision();
// draw paddle image
void DrawPaddle( int _X, int _Y);
// init paddle
void PaddleInit();
// game loop
void UpDateGame();
// game init
void GameInit();
LRESULT CALLBACK WindowProc(HWND hwnd,UINT uMsg,WPARAM wParam,LPARAM lParam)
{// gets speed desired by the user
int N = 0;
switch( uMsg)
{
case WM_KEYDOWN:
{
switch(wParam)
{
case VK_RETURN:
GAMESTARTED = true;
break;
// moves paddle right
case VK_RIGHT:
Paddle_X -= 8;
Paddle_Move = true;
break;
//moves paddle left
case VK_LEFT:
Paddle_X += 8;
Paddle_Move = true;
break;
//increases ball speed
case VK_UP:
N += 1;
ball.Speed(N);
break;
//decreases ball speed
case VK_DOWN:
N -= 1;
break;
}
}
//copys entire buffer onto the main client's
case WM_PAINT:
{
PAINTSTRUCT ps;
HDC hdc = BeginPaint(ghWnd,&ps);
BitBlt(hdc,0,0,SCREEN_WIDTH * BAR_SIZE,SCREEN_HEIGHT * BAR_SIZE,MapImage,0,0,SRCCOPY);
EndPaint(ghWnd,&ps);
return (0);
}
break;
case WM_DESTROY:
{
PostQuitMessage(0);
return(0);
}
break;
default :
return (DefWindowProc(hwnd,uMsg,wParam,lParam));
}
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
timerstart = GetTickCount();
WNDCLASSEX wc;
wc.cbSize = sizeof(WNDCLASSEX);
wc.style = CS_VREDRAW|CS_HREDRAW;
wc.lpfnWndProc = (WNDPROC)WindowProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon =LoadIcon(NULL,IDI_APPLICATION);
wc.hCursor = LoadCursor(NULL,IDC_ARROW);
wc.hbrBackground =(HBRUSH)GetStockObject(BLACK_BRUSH);
wc.lpszMenuName = NULL;
wc.lpszClassName = "Blizt game";
wc.hIconSm = NULL;
RegisterClassEx(&wc);
ghWnd = CreateWindowEx(WS_EX_WINDOWEDGE,"Blizt game","Demo game",WS_SYSMENU|WS_CAPTION |WS_BORDER,0,0,160,240,NULL,NULL,hInstance,NULL);
GameInit();
MSG msg;
for( ; ; )
{// updates every second
timercurrent = GetTickCount() - timerstart;
if(timercurrent > 1000.0)
{ UpDateGame();
timerstart = timercurrent;
} //checks for quit
if(PeekMessage(&msg,ghWnd,0,0,PM_REMOVE))
{ if(msg.message == WM_QUIT) break;
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
return msg.wParam;
}
void DrawBars(int x, int y, int title)
{
BitBlt(MapImage,x* BAR_SIZE,y* BAR_SIZE,BAR_SIZE,BAR_SIZE,BarImage,title * BAR_SIZE, title * BAR_SIZE,SRCAND );
BitBlt(MapImage,x* BAR_SIZE,y* BAR_SIZE,BAR_SIZE,BAR_SIZE,BarImage,title * BAR_SIZE, title * BAR_SIZE + BAR_SIZE,SRCPAINT );
}
void PaddleInit()
{
Paddle_X = 8;
Paddle_Y = 208;
DrawPaddle( Paddle_X, Paddle_Y);
}
void DrawPaddle(int _X, int _Y)
{ //checks to see if there was any previous ball movement
if(Paddle_Move == true)
BitBlt(MapImage,PrePaddle_X,PrePaddle_Y,8,1,Paddle,0,1,SRCCOPY);
//updates iamge
BitBlt(MapImage,_X,_Y,8,1,Paddle,0,0,SRCCOPY);
};
//erases previous image then makes new iamge movement for ball(also paddle)
void DrawBall()
{
if(GAMESTARTED == true)
BitBlt(BallImage,PREBALL_X,PREBALL_Y,8,8,BallImage,2 * 8, 0, SRCCOPY);
BitBlt(BallImage,BALL_X,BALL_Y,8,8,BallImage,0,0,SRCAND);
BitBlt(BallImage,BALL_X,BALL_Y,8,8,BallImage,2 * 8, 2*8, SRCPAINT);
}
void collision()
{
if(Paddle_X > SCREEN_WIDTH)
Paddle_X -= 1;
if(Paddle_X < 0)
Paddle_X += 1;
if(ball.GetX_val() > SCREEN_WIDTH)
ball. Newdirection( 8,0);
if(ball.GetY_val() < 0 )
ball.Newdirection(0,-8);
if(ball.GetY_val() == 206)
/* end of round */
if (ball.GetY_val()== Paddle_X - 1)
ball.Newdirection(8,0);
}
void UpDateGame()
{
if( GAMESTARTED == true)
{
collision();
PREBALL_X = BALL_X;
PREBALL_Y = BALL_Y;
BALL_X = ball.GetX_val();
BALL_Y = ball.GetY_val();
ball.Move();
DrawPaddle(Paddle_X, Paddle_Y);
}
InvalidateRect(ghWnd,NULL,false);
}
void NewGame()
{
GAMESTARTED = false;
for(int xmi = 0; xmi < SCREEN_WIDTH; ++ xmi)
for(int ymi = 0; ymi < 60; ++ymi)
{
if(ymi < 10)
MAP[xmi][ymi] = REDBAR;
else
MAP[xmi][ymi] = BLACKBAR;
DrawBars(xmi,ymi,MAP[xmi][ymi]);
}
ball.Startpos( SCREEN_WIDTH / 2, 120 );
PaddleInit();
UpDateGame();
}
void GameInit()
{
RECT rtemp;
HDC hdcc =GetDC(ghWnd);
SetRect(&rtemp,0,0,SCREEN_WIDTH * BAR_SIZE,SCREEN_HEIGHT * BAR_SIZE);
AdjustWindowRect(&rtemp,WS_CAPTION|WS_VISIBLE|WS_SYSMENU,false);
SetWindowPos(ghWnd,NULL,0,0,SCREEN_WIDTH * BAR_SIZE,SCREEN_HEIGHT * BAR_SIZE,SWP_NOMOVE);
MapImage.CreateImage(hdcc,"gamescreen.bmp");
BarImage.CreateImage(NULL,"Bar.bmp");
BallImage.CreateImage(NULL,"ball.bmp");
Paddle.CreateImage(NULL,"Paddle.bmp");
ReleaseDC(ghWnd,hdcc);
NewGame();
}
Ehm, if you use breakpoints, then I'd expect the debugger to stop there! That's the whole point of breakpoints.
I would also like to echo the sentiments before of "posting huge bits of code with 'unknown' faults" is not a very productive way to solve problems. Try to isolate your problem to a few lines, then ask for help (but most likely, you'll find the problem yourself at that point).
--
Mats
^ thank you (scarcasm)
>..> i just wanna know what happen too confuse
If you want help with this you would probably be best off creating a small test prog that reproduces the problem. It may take some, but by doing this I have often sorted out problems with my own progs. Seriously, you will be very lucky if you find anyone willing to go through a load of code for you trying to fix unknown problems.
ooh thanks u mean like recreating what the program suppose to do at specific parts .....
Yes, break it into pieces that can stand alone. Then you will know where your problem is assuming each of the pieces is just the same as it was in the whole program.