?? demo9_2a.cpp
字號(hào):
DInput_Shutdown();
// unload the bitmap file
Unload_Bitmap_File(&bitmap8bit);
// delete all bobs and bitmaps
Destroy_BOB(&buttons);
Destroy_BOB(&pointer);
Destroy_Bitmap(&cpanel);
Destroy_Bitmap(&canvas);
// shutdonw directdraw
DDraw_Shutdown();
// return success
return(1);
} // end Game_Shutdown
///////////////////////////////////////////////////////////
int Game_Main(void *parms, int num_parms)
{
// this is the workhorse of your game it will be called
// continuously in real-time this is like main() in C
// all the calls for you game go here!
int index; // looping var
// check of user is trying to exit
if (KEY_DOWN(VK_ESCAPE) || KEY_DOWN(VK_SPACE))
PostMessage(main_window_handle, WM_DESTROY,0,0);
// start the timing clock
Start_Clock();
// clear the drawing surface
DDraw_Fill_Surface(lpddsback, 0);
// get the mouse data
DInput_Read_Mouse();
// move the mouse cursor
mouse_x+=(mouse_state.lX);
mouse_y+=(mouse_state.lY);
// test bounds
// first x boundaries
if (mouse_x >= screen_width)
mouse_x = screen_width-1;
else
if (mouse_x < 0)
mouse_x = 0;
// now the y boundaries
if (mouse_y >= screen_height)
mouse_y= screen_height-1;
else
if (mouse_y < 0)
mouse_y = 0;
// position the pointer bob to the mouse coords
pointer.x = mouse_x - 16;
pointer.y = mouse_y - 16;
// test what the user is doing with the mouse
if ((mouse_x > 3) && (mouse_x < 500-3) &&
(mouse_y > 3) && (mouse_y < SCREEN_HEIGHT-3))
{
// mouse is within canvas region
// if left button is down then draw
if (mouse_state.rgbButtons[0])
{
// test drawing mode
if (buttons_state[BUTTON_PENCIL])
{
// draw a pixel
Draw_Pixel(mouse_x, mouse_y, mouse_color, canvas.buffer, canvas.width);
Draw_Pixel(mouse_x+1, mouse_y, mouse_color, canvas.buffer, canvas.width);
Draw_Pixel(mouse_x, mouse_y+1, mouse_color, canvas.buffer, canvas.width);
Draw_Pixel(mouse_x+1, mouse_y+1, mouse_color, canvas.buffer, canvas.width);
}
else
{
// draw spray
for (index=0; index<10; index++)
{
// get next particle
int sx=mouse_x-8+rand()%16;
int sy=mouse_y-8+rand()%16;
// make sure particle is in bounds
if (sx > 0 && sx < 500 && sy > 0 && sy < screen_height)
Draw_Pixel(sx, sy, mouse_color, canvas.buffer, canvas.width);
} // end for index
} // end else
} // end if left button
else // right button is eraser
if (mouse_state.rgbButtons[1])
{
// test drawing mode
if (buttons_state[BUTTON_PENCIL])
{
// erase a pixel
Draw_Pixel(mouse_x, mouse_y, 0, canvas.buffer, canvas.width);
Draw_Pixel(mouse_x+1, mouse_y, 0, canvas.buffer, canvas.width);
Draw_Pixel(mouse_x, mouse_y+1, 0, canvas.buffer, canvas.width);
Draw_Pixel(mouse_x+1, mouse_y+1, 0, canvas.buffer, canvas.width);
} // end if
else
{
// erase spray
for (index=0; index<20; index++)
{
// get next particle
int sx=mouse_x-8+rand()%16;
int sy=mouse_y-8+rand()%16;
// make sure particle is in bounds
if (sx > 0 && sx < 500 && sy > 0 && sy < screen_height)
Draw_Pixel(sx, sy, 0, canvas.buffer, canvas.width);
} // end for index
} // end else
} // end if left button
} // end if
else
if ( (mouse_x > 500+16) && (mouse_x < 500+16+8*9) &&
(mouse_y > 8) && (mouse_y < 8+32*9))
{
// within palette
// test if button left button is down
if (mouse_state.rgbButtons[0])
{
// see what color cell user is pointing to
int cell_x = (mouse_x - (500+16))/9;
int cell_y = (mouse_y - (8))/9;
// change color
mouse_color = cell_x + cell_y*8;
} // end if
} // end if
else
if ((mouse_x > 500) && (mouse_x < (500+100)) &&
(mouse_y > 344) && (mouse_y < (383+34)) )
{
// within button area
// test for each button
for (index=0; index<4; index++)
{
if ((mouse_x > buttons_x[index]) && (mouse_x < (buttons_x[index]+32)) &&
(mouse_y > buttons_y[index]) && (mouse_y < (buttons_y[index]+34)) )
break;
} // end for
// at this point we know where the user is, now determine what he
// is doing with the buttons
switch(index)
{
case BUTTON_SPRAY:
{
// if left button is down simply activate spray mode
if (mouse_state.rgbButtons[0])
{
// depress button
buttons_state[index] = 1;
// de-activate pencil mode
buttons_state[BUTTON_PENCIL] = 0;
} // end if
else
{
// make sure button is up
// buttons_state[index] = 0;
} // end else
} break;
case BUTTON_PENCIL:
{
// if left button is down activate spray mode
if (mouse_state.rgbButtons[0])
{
// depress button
buttons_state[index] = 1;
// de-activate spray mode
buttons_state[BUTTON_SPRAY] = 0;
} // end if
else
{
// make sure button is up
// buttons_state[index] = 0;
} // end else
} break;
case BUTTON_ERASE:
{
// test if left button is down, if so clear screen
if (mouse_state.rgbButtons[0])
{
// clear memory
memset(canvas.buffer,0,canvas.width*canvas.height);
// depress button
buttons_state[index] = 1;
} // end if
else
{
// make sure button is up
buttons_state[index] = 0;
} // end else
} break;
case BUTTON_EXIT:
{
// test if left button down, if so bail
if (mouse_state.rgbButtons[0])
PostMessage(main_window_handle, WM_DESTROY,0,0);
} break;
} // end switch
} // end if
else
{
// no mans land
} // end else
// lock back buffer
DDraw_Lock_Back_Surface();
// draw the canvas
Draw_Bitmap(&canvas, back_buffer, back_lpitch,0);
// draw control panel
Draw_Bitmap(&cpanel,back_buffer,back_lpitch,0);
// unlock back buffer
DDraw_Unlock_Back_Surface();
// draw the color palette
for (int col=0; col < 256; col++)
{
Draw_Rectangle(500+16+(col%8)*9, 8+(col/8)*9,
500+16+(col%8)*9+8, 8+(col/8)*9+8,
col,lpddsback);
} // end for col
// draw the current color selected
Draw_Rectangle(533,306,533+34,306+34,mouse_color,lpddsback);
// draw the buttons
for (index=0; index<4; index++)
{
// set position of button bob
buttons.x = buttons_x[index];
buttons.y = buttons_y[index];
// now select the on/off frame based on if the
// button is off
if (buttons_state[index]==0)
buttons.curr_frame = index;
else // button is on
buttons.curr_frame = index+4;
// draw the button
Draw_BOB(&buttons, lpddsback);
} // end for index
static int green = 0;
// display coords
sprintf(buffer,"Pointer (%d,%d)",mouse_x,mouse_y);
Draw_Text_GDI(buffer, 8,screen_height - 16,RGB(0,255,0),lpddsback);
Draw_Text_GDI("T3D Paint Version 2.0 - Press <ESC> to Exit.",0,0,RGB(0,(green & 255),0),lpddsback);
// a little animation
++green;
// draw the cursor last
Draw_BOB(&pointer,lpddsback);
// flip the surfaces
DDraw_Flip();
// sync to 30 fps
Wait_Clock(30);
// return success
return(1);
} // end Game_Main
//////////////////////////////////////////////////////////
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -