//这个是在主函数中添加的

//游戏循环
while (msg.message != WM_QUIT)
{
if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
else
{
tNow = GetTickCount();
if (tNow - tPre >= 100)//相差0.1秒时再进行重绘操作
MyPaint(hdc);
}
}

 


//--------------------------------------------InitInstance() 函数----------------------------------------------
//加载资源
//-------------------------------------------------------------------------------------------------------------
BOOL InitInstance(HINSTANCE hInstance, int nShowCmd)
{
char filename[20] = "";
HBITMAP bmp;

//创建窗口第三步:正式创建窗口
//创建窗口函数
hwnd = CreateWindow("GameClass", WINDOW_TITLE, WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);
if (!hwnd)
{
return FALSE;
}
//创建窗口第四步:窗口的移动,显示和更新
MoveWindow(hwnd, 250, 80, WINDOW_WIDTH, WINDOW_HEIGHT, true);//调整窗口显示时的位置及窗口的大小
ShowWindow(hwnd, nShowCmd);//设定显示窗口时的状态
UpdateWindow(hwnd);//将窗口绘制于显示设备上

hdc = GetDC(hwnd);
mdc = CreateCompatibleDC(hdc);
bufdc = CreateCompatibleDC(hdc);
bmp = CreateCompatibleBitmap(hdc, 640, 480);

SelectObject(mdc, bmp);

dra = (HBITMAP)LoadImage(NULL, "dra.bmp", IMAGE_BITMAP, 760, 198, LR_LOADFROMFILE);
bg = (HBITMAP)LoadImage(NULL, "bg.bmp", IMAGE_BITMAP, 640, 480, LR_LOADFROMFILE);

num = 0; //显示图号
x = 640; //贴图起始x坐标
y = 360; //贴图起始y坐标

MyPaint(hdc);


return TRUE;
}

//--------------------------------------------MyPaint() 函数---------------------------------------------------
//绘制图形
//-------------------------------------------------------------------------------------------------------------
void MyPaint(HDC hdc)
{
if (num == 8)
num = 0;

//mdc中贴上背景图
SelectObject(bufdc, bg);
BitBlt(mdc, 0, 0, 640, 480, bufdc, 0, 0, SRCCOPY);

//mdc中进行透明处理
SelectObject(bufdc, dra);
BitBlt(mdc, x, y, 95, 99, bufdc, num * 95, 99, SRCAND);
BitBlt(mdc, x, y, 95, 99, bufdc, num * 95, 0, SRCPAINT);

//将最后画面显示在窗口中
BitBlt(hdc, 0, 0, 640, 480, mdc, 0, 0, SRCCOPY);

tPre = GetTickCount(); //记录此次绘图时间
num++;

x -= 20; //计算下次贴图坐标
if (x <= -95)
x = 640;
}


//--------------------------------------------Game_CleanUp() 函数----------------------------------------------
//资源清理函数,在此函数中进行退出前的资源的清理工作
//-------------------------------------------------------------------------------------------------------------
BOOL Game_CleanUp()
{
DeleteDC(mdc);
DeleteDC(hdc);
DeleteObject(dra);
DeleteObject(bg);
return TRUE;
}

 

 

如需整体运行框架,请点击: 游戏框架

游戏开发的梦想

梦开始的地方

posted on 2015-11-22 23:36  zishen  阅读(351)  评论(0编辑  收藏  举报