so I have this code which is based on one of the projects in the Tricks windows book, which could draw random rectangles to the screen, so I decided to try and see if i could put together a little pong. so first a changed the code to draw 3 boxes: a player, a computer(I’m treating this as a one player game right now, I’m not really worrying about the other paddle yet), and a "ball." next i wanted to make the player paddle move, so i put together some input code, which sees if the up or down key has been pressed, and if so changes the coordinates of the paddle, but when I run the program the paddle responds very poorly, it jumps to the top of the screen and barley moves form there. Here’s the main game code:
void Game::GetInput()
{
//if User hits up key we move the paddle up
if (KEYDOWN(VK_UP))
{
PlayerRect.top =- 1;
PlayerRect.bottom = PlayerRect.top + 200;
}
if (KEYDOWN(VK_DOWN))
{
PlayerRect.top =+ 1;
PlayerRect.bottom = PlayerRect.top + 200;
}
return;
}
/////////////////////////////////////////////////////////////////////
Game::Init()
{
// this is called once after the initial window is created and
// before the main event loop is entered, do all your initialization
// here
PlayerRect.top = 200;
PlayerRect.bottom = PlayerRect.top + 200;
PlayerRect.left = 20;
PlayerRect.right = PlayerRect.left + 20;
CPURect.top = 200;
CPURect.bottom = CPURect.top + 200;
CPURect.left = 760;
CPURect.right = CPURect.left + 20;
BallRect.top = 310;
BallRect.bottom = BallRect.top + 20;
BallRect.left = 390;
BallRect.right = BallRect.left + 20;
pRenderer = new DDrawObj();
pRenderer->Init();
return 1;
} // end Game_Init
///////////////////////////////////////////////////////////
Game::Main()
{
// this is the main loop of the game, do all your processing
// here
GetInput();
pRenderer->Render(PlayerRect, CPURect, BallRect );
// for now test if user is hitting ESC and send WM_CLOSE
if (KEYDOWN(VK_ESCAPE))
SendMessage(main_window_handle,WM_CLOSE,0,0);
// return success or failure or your own return code here
return(1);
} // end Game_Main
/////////////////////////////////////////////////////////////
Game::Shutdown()
{
// this is called after the game is exited and the main event
// loop while is exited, do all you cleanup and shutdown here
pRenderer->Shutdown();
delete pRenderer;
// return success or failure or your own return code here
return(1);
} // end Game_Shutdown
here's the DDraw code if it matters
//DDraw Stuff///////////////////////////////////////////////
LPDIRECTDRAW7 lpdd = NULL; // dd object
LPDIRECTDRAWSURFACE7 lpddsPrimary = NULL; // dd primary surface
LPDIRECTDRAWSURFACE7 lpddsBack = NULL; // dd back surface
LPDIRECTDRAWPALETTE lpddpal = NULL; // a pointer to the created dd palette
LPDIRECTDRAWCLIPPER lpddClipper = NULL; // dd clipper
PALETTEENTRY palette[256]; // color palette
PALETTEENTRY save_palette[256]; // used to save palettes
DDSURFACEDESC2 ddsd; // a direct draw surface description struct
DDBLTFX ddbltfx; // used to fill
DDSCAPS2 ddscaps; // a direct draw surface capabilities struct
HRESULT ddrval; // result back from dd calls
DWORD start_clock_count = 0; // used for timing
//INTI FUNCTIONS////////////////////////////////////////////////
DDrawObj::ClipperSetup()
{
LPRGNDATA RgnData;
lpdd->CreateClipper(0, &lpddClipper, NULL);
RgnData = (LPRGNDATA)malloc(sizeof(RGNDATAHEADER)+
sizeof(RECT));
//RECT rect={win->ReturnX(),win->ReturnY(),win->ReturnWidth(),win->ReturnHeight()};
RECT rect={0,0,SCREEN_WIDTH,SCREEN_HEIGHT};
memcpy(RgnData->Buffer,&rect,sizeof(RECT));
RgnData->rdh.dwSize=sizeof(RGNDATAHEADER);
RgnData->rdh.iType=RDH_RECTANGLES;
RgnData->rdh.nCount=1;
RgnData->rdh.nRgnSize=sizeof(RECT);
RgnData->rdh.rcBound.left=64000;
RgnData->rdh.rcBound.top=64000;
RgnData->rdh.rcBound.right=-64000;
RgnData->rdh.rcBound.bottom=-64000;
if(rect.left<RgnData->rdh.rcBound.left)
RgnData->rdh.rcBound.left=rect.left;
if(rect.top<RgnData->rdh.rcBound.top)
RgnData->rdh.rcBound.top=rect.top;
if(rect.right>RgnData->rdh.rcBound.right)
RgnData->rdh.rcBound.right=rect.right;
if(rect.bottom>RgnData->rdh.rcBound.bottom)
RgnData->rdh.rcBound.bottom=rect.bottom;
//set the Clip List
lpddClipper->SetClipList(RgnData, 0);
//attach the clipper
lpddsBack->SetClipper(lpddClipper);
//free the memeory
delete RgnData;
RgnData = NULL;
return 1;
}
///////////////////////////////////////////////////////////
DDrawObj::SurfaceSetup()
{
//Microsoft Says to Clear memory
memset(&ddsd, 0, sizeof(ddsd));
//fill in the stuct
ddsd.dwSize = sizeof(ddsd);
//enable data fields with values that will send valid data in
//in this case ddsCaps is used and DDSD_BACKBUFFER to say we want a back buffer
ddsd.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT;
//set the nuber of back buffers
ddsd.dwBackBufferCount = 1;
//Request a Complex, flipable
ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE |
DDSCAPS_COMPLEX|
DDSCAPS_FLIP;
lpdd->CreateSurface(&ddsd, &lpddsPrimary, NULL);
//this is needed by the call
ddsd.ddsCaps.dwCaps = DDSCAPS_BACKBUFFER;
//request the attached back buffer
lpddsPrimary->GetAttachedSurface(&ddsd.ddsCaps, &lpddsBack);
return 1;
}
//RGB Setup
DDrawObj::RGBModeSetup()
{
//setup the surface
SurfaceSetup();
DDPIXELFORMAT ddpixel; //used to hold info
//clear mem and enter the size
memset(&ddpixel, 0, sizeof(ddpixel));
ddpixel.dwSize = sizeof(ddpixel);
lpddsPrimary->GetPixelFormat(&ddpixel);
if (ddpixel.dwFlags & DDPF_RGB)
switch(ddpixel.dwRGBBitCount)
{
case 15://5.5.5 mode
{
//use "RGB16BIT555(r, g, b) ((b & 31) + ((g & 31) << 5) + ((r & 31) << 10))" Macro
BitMode = 555;
} break;
case 16:
{
//use the "RGB16BIT565(r, g, b) ((b & 31) + ((g & 63) << 5) + ((r & 31) << 11))" Macro
BitMode = 565;
} break;
case 24:
{
//use the "RGB16BIT565(r, g, b) ((b & 31) + ((g & 63) << 5) + ((r & 31) << 11))" Macro
BitMode = 24;
} break;
case 32:
{
//use the "RGB16BIT565(r, g, b) ((b & 31) + ((g & 63) << 5) + ((r & 31) << 11))" Macro
BitMode = 32;
} break;
default: break;
}
return 1;
}
//Palette Mode Setup////////////////////////////////////////
DDrawObj::PaletteSetUp()
{
/////Set Up the Paletted Mode////////////////////
//Fill 'em With Colors
for(int color=1; color < 255; color++)
{
//fill with a random value
palette.peRed = rand()%<span class="cpp-number">256</span>;
palette.peGreen = rand()%<span class="cpp-number">256</span>;
palette.peBlue = rand()%<span class="cpp-number">256</span>;
palette.peFlags = PC_NOCOLLAPSE;
}
palette[<span class="cpp-number">0</span>].peRed = <span class="cpp-number">0</span>;
palette[<span class="cpp-number">0</span>].peGreen = <span class="cpp-number">0</span>;
palette[<span class="cpp-number">0</span>].peBlue = <span class="cpp-number">0</span>;
palette[<span class="cpp-number">0</span>].peFlags = PC_NOCOLLAPSE;
palette[<span class="cpp-number">255</span>].peRed = <span class="cpp-number">255</span>;
palette[<span class="cpp-number">255</span>].peGreen = <span class="cpp-number">255</span>;
palette[<span class="cpp-number">255</span>].peBlue = <span class="cpp-number">255</span>;
palette[<span class="cpp-number">255</span>].peFlags = PC_NOCOLLAPSE;
<span class="cpp-comment">//create the interface</span>
lpdd->CreatePalette(DDPCAPS_8BIT|
DDPCAPS_ALLOW256|
DDPCAPS_INITIALIZE,
palette,
&lpddpal,
NULL);
<span class="cpp-comment">///////////////////////////////////////////////</span>
<span class="cpp-comment">//setup the surface </span>
SurfaceSetup();
<span class="cpp-comment">//attach the palette to the surface</span>
lpddsPrimary->SetPalette(lpddpal);
<span class="cpp-keyword">return</span> <span class="cpp-number">1</span>;
}
<span class="cpp-comment">/////////////////////////////////////////////////////////////</span>
DDrawObj::Init()
{
<span class="cpp-comment">// this is called once after the initial window is created and</span>
<span class="cpp-comment">// before the main event loop is entered, do all your initialization</span>
<span class="cpp-comment">// here</span>
<span class="cpp-comment">//clear the pointer in the unlikely event it's been used before</span>
<span class="cpp-keyword">if</span>(lpdd)
{
lpdd->Release();
lpdd = NULL;
}
<span class="cpp-comment">//Create the interface</span>
<span class="cpp-keyword">if</span>(FAILED(DirectDrawCreateEx(NULL, (<span class="cpp-keyword">void</span> **)&lpdd, IID_IDirectDraw7, NULL)))
{MessageBox(NULL, <span class="cpp-literal">"Failed to create interface"</span>, <span class="cpp-literal">"Error"</span>, MB_OK);}
<span class="cpp-comment">//set cooperation level to normal for a windowed app</span>
<span class="cpp-keyword">if</span>(FAILED(lpdd->SetCooperativeLevel(main_window_handle, DDSCL_FULLSCREEN|
DDSCL_ALLOWMODEX|
DDSCL_EXCLUSIVE|
DDSCL_ALLOWREBOOT)))
MessageBox(NULL, <span class="cpp-literal">"Failed to set co-op level"</span>, <span class="cpp-literal">"Error"</span>, MB_OK);
<span class="cpp-comment">//set the display mode to the values defined in the header file</span>
<span class="cpp-keyword">if</span>(FAILED(lpdd->SetDisplayMode(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP, <span class="cpp-number">0</span>, <span class="cpp-number">0</span>)))
MessageBox(NULL, <span class="cpp-literal">"Failed to set display mode"</span>, <span class="cpp-literal">"Error"</span>, MB_OK);
<span class="cpp-comment">//set var BitMode to the default 8 bits</span>
BitMode = <span class="cpp-number">8</span>;
<span class="cpp-comment">/////////////////////////////////////////</span>
<span class="cpp-comment">//if it's 8 bit set up the palette </span>
<span class="cpp-keyword">if</span> (SCREEN_BPP==<span class="cpp-number">8</span>)
{
PaletteSetUp();
}
<span class="cpp-keyword">if</span> (SCREEN_BPP==<span class="cpp-number">16</span> || SCREEN_BPP==<span class="cpp-number">24</span> || SCREEN_BPP==<span class="cpp-number">32</span>)
{
<span class="cpp-keyword">if</span>(FAILED(RGBModeSetup()))
MessageBox(NULL, <span class="cpp-literal">"Failed to setup RGB Mode"</span>, <span class="cpp-literal">"Error"</span>, MB_OK);
}
<span class="cpp-comment">//flip buffers</span>
lpddsPrimary->Flip(NULL, DDFLIP_WAIT);
WindowRect.top = <span class="cpp-number">100</span>;
WindowRect.left = <span class="cpp-number">100</span>;
WindowRect.right = SCREEN_WIDTH;
WindowRect.bottom= SCREEN_HEIGHT;
<span class="cpp-comment">//setup the clipper</span>
ClipperSetup();
<span class="cpp-comment">// return success or failure or your own return code here</span>
<span class="cpp-keyword">return</span>(<span class="cpp-number">1</span>);
} <span class="cpp-comment">// end DDRawObj::Init</span>
<span class="cpp-comment">////////////////////////////////////////////////////////////////////</span>
DDrawObj::Shutdown()
{
<span class="cpp-comment">// this is called after the game is exited and the main event</span>
<span class="cpp-comment">// loop while is exited, do all you cleanup and shutdown here</span>
<span class="cpp-comment">//Release the Palette</span>
<span class="cpp-keyword">if</span> (lpddpal)
{
lpddpal->Release();
lpddpal = NULL;
} <span class="cpp-comment">// end if</span>
<span class="cpp-comment">// now the primary surface</span>
<span class="cpp-keyword">if</span> (lpddsPrimary)
{
lpddsPrimary->Release();
lpddsPrimary = NULL;
} <span class="cpp-comment">// end if</span>
<span class="cpp-comment">// now blow away the IDirectDraw7 interface</span>
<span class="cpp-keyword">if</span> (lpdd)
{
lpdd->Release();
lpdd = NULL;
} <span class="cpp-comment">// end if</span>
<span class="cpp-comment">// return success or failure or your own return code here</span>
<span class="cpp-keyword">return</span>(<span class="cpp-number">1</span>);
} <span class="cpp-comment">// end DDrawObj::Shutdown</span>
<span class="cpp-comment">////////////////////////////////////////////////////////////////////</span>
<span class="cpp-comment">//RENDERER FUNCTIONS////////////////////////////////////////////////</span>
DDrawObj::Load_Bitmap_File(BITMAP_FILE_PTR bitmap, <span class="cpp-keyword">char</span> *filename)
{
<span class="cpp-comment">// this function opens a bitmap file and loads the data into bitmap</span>
<span class="cpp-keyword">int</span> file_handle, <span class="cpp-comment">// the file handle</span>
index; <span class="cpp-comment">// looping index</span>
UCHAR *temp_buffer = NULL; <span class="cpp-comment">// used to convert 24 bit images to 16 bit</span>
OFSTRUCT file_data; <span class="cpp-comment">// the file data information</span>
<span class="cpp-comment">// open the file if it exists</span>
<span class="cpp-keyword">if</span> ((file_handle = OpenFile(filename,&file_data,OF_READ))==-<span class="cpp-number">1</span>)
<span class="cpp-keyword">return</span>(<span class="cpp-number">0</span>);
<span class="cpp-comment">// now load the bitmap file header</span>
_lread(file_handle, &bitmap->bitmapfileheader,<span class="cpp-keyword">sizeof</span>(BITMAPFILEHEADER));
<span class="cpp-comment">// test if this is a bitmap file</span>
<span class="cpp-keyword">if</span> (bitmap->bitmapfileheader.bfType!=BITMAP_ID)
{
<span class="cpp-comment">// close the file</span>
_lclose(file_handle);
<span class="cpp-comment">// return error</span>
<span class="cpp-keyword">return</span>(<span class="cpp-number">0</span>);
} <span class="cpp-comment">// end if</span>
<span class="cpp-comment">// now we know this is a bitmap, so read in all the sections</span>
<span class="cpp-comment">// first the bitmap infoheader</span>
<span class="cpp-comment">// now load the bitmap file header</span>
_lread(file_handle, &bitmap->bitmapinfoheader,<span class="cpp-keyword">sizeof</span>(BITMAPINFOHEADER));
<span class="cpp-comment">// now load the color palette if there is one</span>
<span class="cpp-keyword">if</span> (bitmap->bitmapinfoheader.biBitCount == <span class="cpp-number">8</span>)
{
_lread(file_handle, &bitmap->palette,MAX_COLORS_PALETTE*<span class="cpp-keyword">sizeof</span>(PALETTEENTRY));
<span class="cpp-comment">// now set all the flags in the palette correctly and fix the reversed </span>
<span class="cpp-comment">// BGR RGBQUAD data format</span>
<span class="cpp-keyword">for</span> (index=<span class="cpp-number">0</span>; index < MAX_COLORS_PALETTE; index++)
{
<span class="cpp-comment">// reverse the red and green fields</span>
<span class="cpp-keyword">int</span> temp_color = bitmap->palette[index].peRed;
bitmap->palette[index].peRed = bitmap->palette[index].peBlue;
bitmap->palette[index].peBlue = temp_color;
<span class="cpp-comment">// always set the flags word to this</span>
bitmap->palette[index].peFlags = PC_NOCOLLAPSE;
} <span class="cpp-comment">// end for index</span>
} <span class="cpp-comment">// end if</span>
<span class="cpp-comment">// finally the image data itself</span>
_lseek(file_handle,-(<span class="cpp-keyword">int</span>)(bitmap->bitmapinfoheader.biSizeImage),SEEK_END);
<span class="cpp-comment">// now read in the image, if the image is 8 or 16 bit then simply read it</span>
<span class="cpp-comment">// but if its 24 bit then read it into a temporary area and then convert</span>
<span class="cpp-comment">// it to a 16 bit image</span>
<span class="cpp-keyword">if</span> (bitmap->bitmapinfoheader.biBitCount==<span class="cpp-number">8</span> || bitmap->bitmapinfoheader.biBitCount==<span class="cpp-number">16</span> ||
bitmap->bitmapinfoheader.biBitCount==<span class="cpp-number">24</span>)
{
<span class="cpp-comment">// delete the last image if there was one</span>
<span class="cpp-keyword">if</span> (bitmap->buffer)
free(bitmap->buffer);
<span class="cpp-comment">// allocate the memory for the image</span>
<span class="cpp-keyword">if</span> (!(bitmap->buffer = (UCHAR *)malloc(bitmap->bitmapinfoheader.biSizeImage)))
{
<span class="cpp-comment">// close the file</span>
_lclose(file_handle);
<span class="cpp-comment">// return error</span>
<span class="cpp-keyword">return</span>(<span class="cpp-number">0</span>);
} <span class="cpp-comment">// end if</span>
<span class="cpp-comment">// now read it in</span>
_lread(file_handle,bitmap->buffer,bitmap->bitmapinfoheader.biSizeImage);
} <span class="cpp-comment">// end if</span>
<span class="cpp-keyword">else</span>
{
<span class="cpp-comment">// serious problem</span>
<span class="cpp-keyword">return</span>(<span class="cpp-number">0</span>);
} <span class="cpp-comment">// end else</span>
#<span class="cpp-keyword">if</span> <span class="cpp-number">0</span>
<span class="cpp-comment">// write the file info out </span>
printf(<span class="cpp-literal">"\nfilename:%s \nsize=%d \nwidth=%d \nheight=%d \nbitsperpixel=%d \ncolors=%d \nimpcolors=%d"</span>,
filename,
bitmap->bitmapinfoheader.biSizeImage,
bitmap->bitmapinfoheader.biWidth,
bitmap->bitmapinfoheader.biHeight,
bitmap->bitmapinfoheader.biBitCount,
bitmap->bitmapinfoheader.biClrUsed,
bitmap->bitmapinfoheader.biClrImportant);
<span class="cpp-directive">#endif</span>
<span class="cpp-comment">// close the file</span>
_lclose(file_handle);
<span class="cpp-comment">// flip the bitmap</span>
Flip_Bitmap(bitmap->buffer,
bitmap->bitmapinfoheader.biWidth*(bitmap->bitmapinfoheader.biBitCount/<span class="cpp-number">8</span>),
bitmap->bitmapinfoheader.biHeight);
<span class="cpp-comment">// return success</span>
<span class="cpp-keyword">return</span>(<span class="cpp-number">1</span>);
} <span class="cpp-comment">// end Load_Bitmap_File</span>
<span class="cpp-comment">///////////////////////////////////////////////////////////</span>
DDrawObj::Unload_Bitmap_File(BITMAP_FILE_PTR bitmap)
{
<span class="cpp-comment">// this function releases all memory associated with "bitmap"</span>
<span class="cpp-keyword">if</span> (bitmap->buffer)
{
<span class="cpp-comment">// release memory</span>
free(bitmap->buffer);
<span class="cpp-comment">// reset pointer</span>
bitmap->buffer = NULL;
} <span class="cpp-comment">// end if</span>
<span class="cpp-comment">// return success</span>
<span class="cpp-keyword">return</span>(<span class="cpp-number">1</span>);
} <span class="cpp-comment">// end Unload_Bitmap_File</span>
<span class="cpp-comment">///////////////////////////////////////////////////////////</span>
DDrawObj::Flip_Bitmap(UCHAR *image,
<span class="cpp-keyword">int</span> bytes_per_line,
<span class="cpp-keyword">int</span> height)
{
<span class="cpp-comment">// this function is used to flip bottom-up .BMP images</span>
UCHAR *buffer; <span class="cpp-comment">// used to perform the image processing</span>
<span class="cpp-keyword">int</span> index; <span class="cpp-comment">// looping index</span>
<span class="cpp-comment">// allocate the temporary buffer</span>
<span class="cpp-keyword">if</span> (!(buffer = (UCHAR *)malloc(bytes_per_line*height)))
<span class="cpp-keyword">return</span>(<span class="cpp-number">0</span>);
<span class="cpp-comment">// copy image to work area</span>
memcpy(buffer,image,bytes_per_line*height);
<span class="cpp-comment">// flip vertically</span>
<span class="cpp-keyword">for</span> (index=<span class="cpp-number">0</span>; index < height; index++)
memcpy(&image[((height-<span class="cpp-number">1</span>) - index)*bytes_per_line],
&buffer[index*bytes_per_line], bytes_per_line);
<span class="cpp-comment">// release the memory</span>
free(buffer);
<span class="cpp-comment">// return success</span>
<span class="cpp-keyword">return</span>(<span class="cpp-number">1</span>);
} <span class="cpp-comment">// end Flip_Bitmap</span>
<span class="cpp-comment">///////////////////////////////////////////////////////////////</span>
DDrawObj::PlotPixel24(<span class="cpp-keyword">int</span> x, <span class="cpp-keyword">int</span> y,
<span class="cpp-keyword">int</span> red, <span class="cpp-keyword">int</span> green, <span class="cpp-keyword">int</span> blue,
UCHAR *VideoBuffer, <span class="cpp-keyword">int</span> lPitch)
{
DWORD pixel_addr = (x+x+x) + y*lPitch;
VideoBuffer[pixel_addr] = blue;
VideoBuffer[pixel_addr+<span class="cpp-number">1</span>] = green;
VideoBuffer[pixel_addr+<span class="cpp-number">2</span>] = red;
<span class="cpp-keyword">return</span> <span class="cpp-number">1</span>;
}
<span class="cpp-comment">//Plot 16 bit pixel int 5.6.5//////////////////////////////</span>
DDrawObj::PlotPixel565(<span class="cpp-keyword">int</span> x, <span class="cpp-keyword">int</span> y,
<span class="cpp-keyword">int</span> red, <span class="cpp-keyword">int</span> green, <span class="cpp-keyword">int</span> blue,
USHORT *VideoBuffer, <span class="cpp-keyword">int</span> lPitch)
{
USHORT pixel = RGB16BIT565(red, green, blue);
VideoBuffer[x+y*(lPitch >> <span class="cpp-number">1</span>)] = pixel;
<span class="cpp-keyword">return</span> <span class="cpp-number">1</span>;
}
<span class="cpp-comment">//Plot 16 bit pixel int 5.5.5//////////////////////////////</span>
DDrawObj::PlotPixel555(<span class="cpp-keyword">int</span> x, <span class="cpp-keyword">int</span> y,
<span class="cpp-keyword">int</span> red, <span class="cpp-keyword">int</span> green, <span class="cpp-keyword">int</span> blue,
USHORT *VideoBuffer, <span class="cpp-keyword">int</span> lPitch)
{
USHORT pixel = RGB16BIT555(red, green, blue);
VideoBuffer[x+y*(lPitch >> <span class="cpp-number">1</span>)] = pixel;
<span class="cpp-keyword">return</span> <span class="cpp-number">1</span>;
}
<span class="cpp-comment">//Plot Pixel in 8 Bit Mode//////////////////////////////////</span>
DDrawObj::Plot8(<span class="cpp-keyword">int</span> x, <span class="cpp-keyword">int</span> y, <span class="cpp-comment">//Pos' of pixel</span>
UCHAR color,
UCHAR *buffer,
<span class="cpp-keyword">int</span> mempitch)
{
<span class="cpp-comment">//this function plots a single pixel</span>
buffer[x+y*mempitch] = color;
<span class="cpp-keyword">return</span> <span class="cpp-number">1</span>;
}<span class="cpp-comment">//end Plot8</span>
<span class="cpp-comment">///////////////////////////////////////////////////////////////</span>
DDrawObj::Render( RECT Player, RECT CPU, RECT Ball )
{
<span class="cpp-comment">//clear the struct</span>
memset(&ddsd, <span class="cpp-number">0</span>, <span class="cpp-keyword">sizeof</span>(ddsd));
<span class="cpp-comment">//always tell it how big it is</span>
ddsd.dwSize = <span class="cpp-keyword">sizeof</span>(ddsd);
<span class="cpp-comment">//clear the struct</span>
memset(&ddbltfx, <span class="cpp-number">0</span>, <span class="cpp-keyword">sizeof</span>(ddbltfx));
<span class="cpp-comment">//always tell it how big it is</span>
ddbltfx.dwSize = <span class="cpp-keyword">sizeof</span>(ddbltfx);
<span class="cpp-comment">//set soem aliases to make the code cleaner</span>
<span class="cpp-keyword">int</span> mempitch = (<span class="cpp-keyword">int</span>)ddsd.lPitch;
UCHAR* VideoBuffer = (UCHAR *)ddsd.lpSurface;
USHORT* VideoBuffer16 = (USHORT *)ddsd.lpSurface;
<span class="cpp-comment">//clear screan</span>
ddbltfx.dwFillColor = <span class="cpp-number">0</span>;
lpddsBack->Blt(NULL,NULL,NULL,DDBLT_WAIT|DDBLT_COLORFILL,&ddbltfx);
<span class="cpp-comment">//////////////////////////////////////////////</span>
<span class="cpp-keyword">if</span>(BitMode == <span class="cpp-number">565</span>)
ddbltfx.dwFillColor =RGB16BIT565( <span class="cpp-number">31</span>, <span class="cpp-number">63</span>, <span class="cpp-number">31</span>);
<span class="cpp-keyword">if</span>(BitMode == <span class="cpp-number">555</span>)
ddbltfx.dwFillColor =RGB16BIT555( <span class="cpp-number">31</span>, <span class="cpp-number">31</span>, <span class="cpp-number">31</span>);
<span class="cpp-comment">//////////////////////////////////////////////</span>
lpddsBack->Blt(&Player,
NULL, NULL,
DDBLT_COLORFILL |
DDBLT_WAIT,
&ddbltfx);
lpddsBack->Blt(&CPU,
NULL, NULL,
DDBLT_COLORFILL |
DDBLT_WAIT,
&ddbltfx);
lpddsBack->Blt(&Ball,
NULL, NULL,
DDBLT_COLORFILL |
DDBLT_WAIT,
&ddbltfx);
lpddsPrimary->Flip(NULL, DDFLIP_WAIT);
lpddsBack->Lock(NULL, &ddsd, DDLOCK_SURFACEMEMORYPTR | DDLOCK_WAIT, NULL);
lpddsBack->Unlock(NULL);
Sleep(<span class="cpp-number">500</span>);
<span class="cpp-keyword">return</span>(<span class="cpp-number">1</span>);
} <span class="cpp-comment">// end DDRawObj::Render</span>
<span class="cpp-comment">/////////////////////////////////////////////////////////////</span>
</pre></div><!–ENDSCRIPT–>