资源图片
//全局变量
HBITMAP girl[7];
HDC mdc, hdc;
int num;
//--------------------------------------------InitInstance() 函数----------------------------------------------
//加载资源
//-------------------------------------------------------------------------------------------------------------
BOOL InitInstance(HINSTANCE hInstance, int nShowCmd)
{
HWND hwnd;
char filename[20] = "";
int i;
//创建窗口第三步:正式创建窗口
//创建窗口函数
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);
for (i = 0; i < 7; i++)
{
wsprintf(filename, "girl%d.bmp", i);
girl[i] = (HBITMAP)LoadImage(NULL, filename, IMAGE_BITMAP, 640, 480, LR_LOADFROMFILE);
}
num = 0;
//设置动画时间器: 0.3秒运行一次
SetTimer(hwnd, 1, 300, NULL);
MyPaint(hdc);
return TRUE;
}
//--------------------------------------------MyPaint() 函数---------------------------------------------------
//绘制图形
//-------------------------------------------------------------------------------------------------------------
void MyPaint(HDC hdc)
{
if (num > 6)
{
num = 0;
}
SelectObject(mdc, girl[num]);
BitBlt(hdc, 0, 0, 600, 450, mdc, 0, 0, SRCCOPY);
num++;
}
//--------------------------------------------Game_CleanUp() 函数----------------------------------------------
//资源清理函数,在此函数中进行退出前的资源的清理工作
//-------------------------------------------------------------------------------------------------------------
BOOL Game_CleanUp(HWND hwnd)
{
DeleteDC(mdc);
DeleteDC(hdc);
KillTimer(hwnd, 1);
for (int i = 0; i < 7; i++)
{
DeleteObject(girl[i]);
}
return TRUE;
}
如需整体运行框架,请点击: 游戏框架
游戏开发的梦想
梦开始的地方