Game Pro
Game Pro
#include <windows.h>
#include <gl/gl.h>
#include <stdio.h>
//Global Variables
float y = 0.0f;
int p1score = 0;
int p2score = 0;
DWORD threadId[2];
HDC hDC;
HWND hWnd;
HANDLE thread1;
HANDLE thread2;
// Function Declarations
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
void UpdateScore(){
char newtext[32];
char tostring[4];
ZeroMemory(newtext, 32);
ZeroMemory(tostring, 4);
strcat(newtext, tostring);
strcat(newtext, tostring);
strcat(newtext, "]");
while(1){
compY -= 0.01f;
}else if(ballY > compY){
compY += 0.01f;
//UpdateOpenGL(hDC);
Sleep(15);
return 0;
while(1){
ballY += incY;
ballX += incX;
incX = -incX;
if(ballX >= 1.05f && ballY >= compY-0.12f && ballY <= compY+0.12f){
incX = -incX;
UpdateScore();
DWORD exitcode;
DWORD exitcode2;
GetExitCodeThread(thread1, &exitcode);
GetExitCodeThread(thread2, &exitcode2);
y = 0.0f;
compY = 0.0f;
incX = -0.01f;
incY = 0.01f;
ballX = 0.0f;
ballY = 0.0f;
ExitThread(exitcode);
ExitThread(exitcode2);
incY = -incY;
p2score++;
UpdateScore();
DWORD exitcode;
DWORD exitcode2;
GetExitCodeThread(thread1, &exitcode);
GetExitCodeThread(thread2, &exitcode2);
y = 0.0f;
compY = 0.0f;
incX = -0.01f;
incY = 0.01f;
ballX = 0.0f;
ballY = 0.0f;
ExitThread(exitcode);
ExitThread(exitcode2);
//UpdateOpenGL(hDC);
Sleep(12);
return 0;
// WinMain
WNDCLASS wc;
HGLRC hRC;
MSG msg;
wc.style = CS_OWNDC;
wc.lpfnWndProc = WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.lpszMenuName = NULL;
wc.lpszClassName = "PongGL";
RegisterClass( &wc );
hWnd = CreateWindow(
while ( !quit )
if ( msg.message == WM_QUIT )
quit = TRUE;
else
TranslateMessage( &msg );
DispatchMessage( &msg );
}
}
else
UpdateOpenGL(hDC);
// shutdown OpenGL
DestroyWindow( hWnd );
return msg.wParam;
// Window Procedure
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
switch (message)
{
case WM_CREATE:
return 0;
case WM_CLOSE:
PostQuitMessage( 0 );
return 0;
case WM_DESTROY:
return 0;
case WM_KEYDOWN:
switch ( wParam )
case 38:
//CreateThread(NULL,0,MoveUp,0,0,&threadId[0]);
movingup = true;
wUp = false;
while(wUp == false){
if(!GetAsyncKeyState(38)){
wUp = true;
movingup = false;
}
UpdateOpenGL(hDC);
y += 0.03f;
Sleep(10);
}else{
y = 0.88f;
wUp = true;
//y += 0.01f;
break;
case 40:
movingdown = true;
sUp = false;
while(sUp == false){
if(!GetAsyncKeyState(40)){
sUp = true;
movingdown = false;
UpdateOpenGL(hDC);
y -= 0.03f;
Sleep(10);
}else{
y = -0.89f;
sUp = true;
//y -= 0.01f;
break;
case VK_ESCAPE:
PostQuitMessage(0);
return 0;
break;
return 0;
default:
// Enable OpenGL
PIXELFORMATDESCRIPTOR pfd;
int format;
// get the device context (DC)
pfd.nVersion = 1;
pfd.iPixelType = PFD_TYPE_RGBA;
pfd.cColorBits = 24;
pfd.cDepthBits = 16;
pfd.iLayerType = PFD_MAIN_PLANE;
// Disable OpenGL
wglDeleteContext( hRC );
glClear( GL_COLOR_BUFFER_BIT );
glPushMatrix();
glBegin( GL_POLYGON );
glEnd();
glBegin( GL_POLYGON );
glEnd();
glBegin( GL_POLYGON );
glEnd();
glPopMatrix();
SwapBuffers( hDC );
Sleep(10);