Windows编程无聊小游戏

自己做了一个Windows编程无聊小游戏,分享一下



#include <windows.h>
#include <stdio.h>
#include <time.h>
#include "resource.h"
#pragma comment(lib,"Msimg32.lib")
LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);
//定义
HBITMAP hbm1,hbm2,hbm3,hbm4,hbm5,hbm6,hbm7,hbm8,hbm9,hbm10,hbm11,hbm12,hbm13,hbm14,hbm15,hbm16,hbm17;
HBITMAP hbm18,hbm19,hbm20,hbm21,hbm22,hbm23;
HDC hdc,mdc,bufdc;
HINSTANCE hInst;             
HWND hWnd;
RECT rect;
DWORD tPre,tNow;
int num,x,y,map,flag,num1,win,t;
int x2,y2; 
//结构体定义
typedef struct Man
{
int x;
int y;
int dir;
int move;
int die;
int num;
int blood;
}Man;
Man man;


typedef struct Fire
{
int x;
int y;
int dir;
int str;
int num;
}Fire;
Fire fire[6];
Fire mushroom[2];
Fire ghost[3];


typedef struct Key
{
int x;
int y;
int use;
}Key;
Key key[5];
Key door[3];
//函数定义
ATOM MyRegisterClass(HINSTANCE hInstance);
BOOL InitInstance(HINSTANCE, int);
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
void MyPaint(HDC hdc);
void Judge();
void reset();




int APIENTRY WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow)
{
MSG msg;
MyRegisterClass(hInstance);
if (!InitInstance (hInstance, nCmdShow)) 
{
return FALSE;
}
GetMessage(&msg,NULL,NULL,NULL); 
    while( msg.message!=WM_QUIT )
    {
        if( PeekMessage( &msg, NULL, 0,0 ,PM_REMOVE) )
        {
            TranslateMessage( &msg );
            DispatchMessage( &msg );
        }
else
{
tNow = GetTickCount();
if(tNow-tPre >= 100)
{
Judge();
MyPaint(hdc);
}
}
    }

return msg.wParam;
}


ATOM MyRegisterClass(HINSTANCE hInstance)
{
WNDCLASSEX wcex;

wcex.cbSize = sizeof(WNDCLASSEX); 
wcex.style = CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc = (WNDPROC)WndProc;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = hInstance;
wcex.hIcon = NULL;
wcex.hCursor = NULL;
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wcex.lpszMenuName = NULL;
wcex.lpszClassName = "canvas";
wcex.hIconSm = NULL;

return RegisterClassEx(&wcex);
}


BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
HBITMAP bmp;
hInst = hInstance;

hWnd = CreateWindow("canvas", "My_Windows" , WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);

if (!hWnd)
{
return FALSE;
}
//初始化
MoveWindow(hWnd,80,25,1200,680,true);
ShowWindow(hWnd, nCmdShow);
UpdateWindow(hWnd);

hdc = GetDC(hWnd);
mdc = CreateCompatibleDC(hdc);
bufdc = CreateCompatibleDC(hdc);

bmp = CreateCompatibleBitmap(hdc,1200,680);
SelectObject(mdc,bmp);

map=1;
flag=1001;
t=0;


x=780;
y=120;
num=0;
win=0;
//人物初始化
man.x = 0;
man.y = 520;
man.dir = 0;
man.move=0;
man.blood=9;
num = 0;
man.num=0;
//障碍物初始化
fire[0].x=1300;
fire[0].y=260;
fire[0].dir=1;
fire[0].num=0;
fire[1].x=1400;
fire[1].y=400;
fire[1].dir=1;
fire[1].num=0;
fire[2].x=1200;
fire[2].y=540;
fire[2].dir=1;
fire[2].num=0;
fire[3].x=1000;
fire[3].y=400;
fire[3].dir=1;
fire[3].num=0;
fire[3].str=0;
fire[4].x=0;
fire[4].y=0;
fire[4].num=0;


mushroom[0].x=400;
mushroom[0].y=290;
mushroom[0].dir=0;
mushroom[0].num=0;
mushroom[1].x=800;
mushroom[1].y=520;
mushroom[1].dir=1;
mushroom[1].num=0;


ghost[0].x=400;
ghost[0].y=300;
ghost[0].dir=0;
ghost[0].num=0;
ghost[1].x=400;
ghost[1].y=400;
ghost[1].dir=1;
ghost[1].num=0;
ghost[2].x=1100;
ghost[2].y=500;
ghost[2].dir=0;
ghost[2].num=0;
//钥匙初始化
key[0].x=400;
key[0].y=290;
key[0].use=1;


key[1].x=800;
key[1].y=500;
key[1].use=1;


key[2].use=1;
//传送门初始化
door[0].x=1050;
door[0].y=520;
door[1].x=0;
door[1].y=520;
door[2].x=950;
door[2].y=550;
num1=0;
//图片载入
hbm1 = LoadBitmap(hInstance,MAKEINTRESOURCE(IDB_BITMAP1));
hbm2 = LoadBitmap(hInstance,MAKEINTRESOURCE(IDB_BITMAP2));
hbm3 = LoadBitmap(hInstance,MAKEINTRESOURCE(IDB_BITMAP3));
hbm4 = LoadBitmap(hInstance,MAKEINTRESOURCE(IDB_BITMAP4));
hbm5 = LoadBitmap(hInstance,MAKEINTRESOURCE(IDB_BITMAP5));
hbm6 = LoadBitmap(hInstance,MAKEINTRESOURCE(IDB_BITMAP6));
hbm7 = LoadBitmap(hInstance,MAKEINTRESOURCE(IDB_BITMAP7));
hbm8 = LoadBitmap(hInstance,MAKEINTRESOURCE(IDB_BITMAP8));
hbm9 = LoadBitmap(hInstance,MAKEINTRESOURCE(IDB_BITMAP9));
hbm10 = LoadBitmap(hInstance,MAKEINTRESOURCE(IDB_BITMAP10));
hbm11 = LoadBitmap(hInstance,MAKEINTRESOURCE(IDB_BITMAP11));
hbm12 = LoadBitmap(hInstance,MAKEINTRESOURCE(IDB_BITMAP12));
hbm13 = LoadBitmap(hInstance,MAKEINTRESOURCE(IDB_BITMAP13));
hbm14 = LoadBitmap(hInstance,MAKEINTRESOURCE(IDB_BITMAP14));
hbm15 = LoadBitmap(hInstance,MAKEINTRESOURCE(IDB_BITMAP15));
hbm16 = LoadBitmap(hInstance,MAKEINTRESOURCE(IDB_BITMAP16));
hbm17 = LoadBitmap(hInstance,MAKEINTRESOURCE(IDB_BITMAP17));
hbm18 = LoadBitmap(hInstance,MAKEINTRESOURCE(IDB_BITMAP18));
hbm19 = LoadBitmap(hInstance,MAKEINTRESOURCE(IDB_BITMAP19));
    hbm20 = LoadBitmap(hInstance,MAKEINTRESOURCE(IDB_BITMAP20));
hbm21 = LoadBitmap(hInstance,MAKEINTRESOURCE(IDB_BITMAP21)); 
hbm22 = LoadBitmap(hInstance,MAKEINTRESOURCE(IDB_BITMAP22)); 
hbm23 = LoadBitmap(hInstance,MAKEINTRESOURCE(IDB_BITMAP23)); 
//绘图
MyPaint(hdc);

return TRUE;
}
//判定函数
void Judge()
{
GetClientRect(hWnd,&rect);
int h,w,i;
num++;
if (num==4) num=0;
//火球和蘑菇移动位置判定
mushroom[0].num++;
if (mushroom[0].num==3) mushroom[0].num=0;
if (mushroom[0].y<300) {mushroom[0].y=301;mushroom[0].dir=0;}
else if (mushroom[0].y>550) {mushroom[0].y=549;mushroom[0].dir=1;}
if (mushroom[0].dir==1) {mushroom[0].y=mushroom[0].y-10;}
else if (mushroom[0].dir==0) {mushroom[0].y=mushroom[0].y+10;}


mushroom[1].num++;
if (mushroom[1].num==3) mushroom[1].num=0;
if (mushroom[1].y<300) {mushroom[1].y=301;mushroom[1].dir=0;}
else if (mushroom[1].y>550) {mushroom[1].y=549;mushroom[1].dir=1;}
if (mushroom[1].dir==1) {mushroom[1].y=mushroom[1].y-10;}
else if (mushroom[1].dir==0) {mushroom[1].y=mushroom[1].y+10;}




fire[0].num=fire[0].num+1;
fire[0].x=fire[0].x-20;
if (fire[0].x<rect.left-200) fire[0].x=1100;
if (fire[0].num==3) fire[0].num=0;
fire[1].num=fire[1].num+1;
fire[1].x=fire[1].x-25;
if (fire[1].x<rect.left-200) fire[1].x=1100;
if (fire[1].num==3) fire[1].num=0;
fire[2].num=fire[2].num+1;
fire[2].x=fire[2].x-15;
if (fire[2].x<rect.left-200) fire[2].x=1100;
if (fire[2].num==3) fire[2].num=0;


//大怪兽位置判定
fire[3].num=fire[3].num+1;
fire[4].num++;
if (fire[4].num==6) fire[4].num=0;
if (fire[3].num==5) fire[3].num=0;
if (key[2].use==1&&flag==1001)
{
if (fire[3].num==5)
{
h=rand()%5;
w=rand()%5;
if (h==4)
{
if (fire[3].dir==1) fire[3].dir=0;
else if (fire[3].dir==0) fire[3].dir=1;
}
if (w==0)
{
if (fire[3].str==1) fire[3].str=0;
else if (fire[3].str==0) fire[3].str=1;
}
fire[3].num=0;
}
if (fire[3].dir==1) fire[3].x=fire[3].x-10;
else if (fire[3].dir==0) fire[3].x=fire[3].x+10;
if (fire[3].str==0) fire[3].y=fire[3].y-4;
else if (fire[3].str==1) fire[3].y=fire[3].y+4;
if (fire[3].y<200) {fire[3].y=200;fire[3].str=1;}
if (fire[3].y>470) {fire[3].y=470;fire[3].str=0;}
if (fire[3].x<50) {fire[3].x=50;fire[3].dir=0;}
if (fire[3].x>955) {fire[3].x=955;fire[3].dir=1;}
if (fire[3].dir==1)
{
key[2].x=fire[3].x+195;
key[2].y=fire[3].y+120;
}
else if (fire[3].dir==0)
{
key[2].x=fire[3].x-50;
key[2].y=fire[3].y+120;
}
}
else 
if (key[2].use==0)
{
if (flag>0&&flag<=1000) 
{
if (fire[3].x>=man.x) fire[3].dir=1;
else if (fire[3].x<man.x) fire[3].dir=0;
flag=flag-50;
fire[4].x=fire[3].x+45;
fire[4].y=fire[3].y-35;
}
else 
if (flag==0)
{
if (fire[3].num==5) fire[3].num=0;
if (man.x+50<=fire[3].x+98&&man.y+50<=fire[3].y+85)
{
fire[3].str=0;
fire[3].dir=1;
}
else
if (man.x+50>fire[3].x+98&&man.y+50<=fire[3].y+85)
{
fire[3].str=0;
fire[3].dir=0;
}
else 
if (man.x+50<=fire[3].x+98&&man.y+50>fire[3].y+85)
{
fire[3].str=1;
fire[3].dir=1;
}
else
if (man.x+50>fire[3].x+98&&man.y+50>fire[3].y+85)
{
fire[3].str=1;
fire[3].dir=0;
}
if (fire[3].dir==1) fire[3].x=fire[3].x-15;
else if (fire[3].dir==0) fire[3].x=fire[3].x+15;
if (fire[3].str==0) fire[3].y=fire[3].y-8;
else if (fire[3].str==1) fire[3].y=fire[3].y+8;
if (fire[3].y<200) {fire[3].y=200;fire[3].str=1;}
if (fire[3].y>470) {fire[3].y=470;fire[3].str=0;}
if (fire[3].x<50) {fire[3].x=50;fire[3].dir=0;}
if (fire[3].x>955) {fire[3].x=955;fire[3].dir=1;}
fire[4].x=fire[3].x+45;
fire[4].y=fire[3].y-35;
}
}


num1++;
if (num1%3==0) num1=0;
//小幽灵位置判定
ghost[0].num++;
if (ghost[0].num==9) ghost[0].num=0;
if (ghost[0].dir==0) ghost[0].x=ghost[0].x-10;
else if (ghost[0].dir==1) ghost[0].x=ghost[0].x+10;
if (ghost[0].x<0) {ghost[0].x=0;ghost[0].dir=1;}
else if (ghost[0].x>400) {ghost[0].x=400;ghost[0].dir=0;}


ghost[1].num++;
if (ghost[1].num==9) ghost[1].num=0;
if (ghost[1].dir==0) ghost[1].x=ghost[1].x-10;
else if (ghost[1].dir==1) ghost[1].x=ghost[1].x+10;
if (ghost[1].x<400) {ghost[1].x=400;ghost[1].dir=1;}
else if (ghost[1].x>800) {ghost[1].x=800;ghost[1].dir=0;}


ghost[2].num++;
if (ghost[2].num==9) ghost[2].num=0;
if (ghost[2].dir==0) ghost[2].x=ghost[2].x-10;
else if (ghost[2].dir==1) ghost[2].x=ghost[2].x+10;
if (ghost[2].x<800) {ghost[2].x=800;ghost[2].dir=1;}
else if (ghost[2].x>1100) {ghost[2].x=1100;ghost[2].dir=0;}


//人物位置判定
if (man.move==1)
{
if (man.dir==0)
{
man.y=man.y+15;
}
else if (man.dir==1)
{
man.x=man.x-20;
}
else if (man.dir==3)
{
man.y=man.y-15;
}
else if (man.dir==2)
{
man.x=man.x+20;
}
man.num++;
if (man.num==4) man.num=0; 
}
if (man.y>=520) man.y=520;
if (man.x<rect.left-20) man.x=rect.left-20;
if (man.y<rect.top+200) man.y=rect.top+200;
if (man.x>=1100) man.x=1100;

if (map==1)
{
if (man.x>1000&&man.y>450) 
{
if (man.dir==0) {map=2;man.x=0;man.y=400;}
else if (man.dir==2) {map=2;man.x=50;}
}
}
else if (map==2)
{
if (man.x<50&&man.y>450) 
{
if (man.dir==0) {map=1;man.x=1050;man.y=400;}
else if (man.dir==1) {map=1;man.x=1000;}
}
}
//人物得到钥匙判定
if (man.x+50>400&&man.x+50<450&&man.y+50>270&&man.y+50<360&&map==1&&key[0].use==1) {key[0].use=0;win++;}
if (man.x+50>800&&man.x+50<850&&man.y+50>480&&man.y+50<570&&map==1&&key[1].use==1) {key[1].use=0;win++;}
if (man.x+50>key[2].x-20&&man.x+50<key[2].x+70&&man.y+50>key[2].y-40&&man.y+50<key[2].y+90&&map==2&&key[2].use==1) 
{
key[2].use=0;
win++;
flag=1000;
if (fire[3].x>=man.x) fire[3].dir=1;
else if (fire[3].x<man.x) fire[3].dir=0;
fire[4].x=fire[3].x+45;
fire[4].y=fire[3].y-35;
}
//人物受伤判定
if (map==1)
{
for (i=0;i<=1;i++)
{
if (man.x+50>=mushroom[i].x+5&&man.x+50<=mushroom[i].x+60&&man.y+50>=mushroom[i].y&&man.y+50<=mushroom[i].y+50) man.blood--;
}
for (i=0;i<=2;i++)
{
if (man.x+50>=fire[i].x&&man.x<=fire[i].x+90&&man.y+50>=fire[i].y&&man.y+50<=fire[i].y+50) man.blood--;
}
}
else if (map==2)
{
for (i=0;i<=2;i++)
{
if (man.x+50>=ghost[i].x&&man.x<=ghost[i].x+20&&man.y+50>=ghost[i].y-10&&man.y+50<=ghost[i].y+40) man.blood--;
}
if (man.x+50>=fire[3].x&&man.x<=fire[3].x+120&&man.y+50>=fire[3].y&&man.y+50<=fire[3].y+120) man.blood--;
}
//获胜判定
if (man.x>=950&&man.y>=500&&win==3&&map==2)
{
win=4;
}
if (man.blood==0) win=-1;
}
//绘图函数
void MyPaint(HDC hdc)
{
BITMAP bm;
if (win==-1)
{
//失败后贴图
SelectObject(bufdc,hbm21);
BitBlt(mdc,0,0,1200,680,bufdc,0,0,SRCCOPY);
SelectObject(bufdc,hbm23);
BitBlt(mdc,350,250,512,343,bufdc,0,0,SRCCOPY);
SelectObject(bufdc,hbm6);
GetObject(hbm6,sizeof(BITMAP),&bm);
TransparentBlt(mdc,600,400,bm.bmWidth/4,bm.bmHeight,bufdc,bm.bmWidth*num/4,0,bm.bmWidth/4,bm.bmHeight,RGB(255,255,255));
BitBlt(hdc,0,0,1200,680,mdc,0,0,SRCCOPY);
t=1;
}
else if (win==4)
{
//获胜后贴图
SelectObject(bufdc,hbm21);
BitBlt(mdc,0,0,1200,680,bufdc,0,0,SRCCOPY);
SelectObject(bufdc,hbm22);
BitBlt(mdc,350,250,512,343,bufdc,0,0,SRCCOPY);
SelectObject(bufdc,hbm6);
GetObject(hbm6,sizeof(BITMAP),&bm);
TransparentBlt(mdc,600,400,bm.bmWidth/4,bm.bmHeight,bufdc,bm.bmWidth*num/4,0,bm.bmWidth/4,bm.bmHeight,RGB(255,255,255));
BitBlt(hdc,0,0,1200,680,mdc,0,0,SRCCOPY);
man.blood=100;
t=1;
}
else 
if (win<=3)
{
//背景贴图
if (map==1)
{
SelectObject(bufdc,hbm2);
BitBlt(mdc,0,0,1200,680,bufdc,0,0,SRCCOPY);
}
else if (map==2)
{
SelectObject(bufdc,hbm13);
BitBlt(mdc,0,0,1200,680,bufdc,0,0,SRCCOPY);
}
//对话框贴图
SelectObject(bufdc,hbm12);                     
TransparentBlt(mdc,860,35,216,120,bufdc,0,0,216,120,RGB(255,255,255));
//头像贴图
SelectObject(bufdc,hbm7);
GetObject(hbm7,sizeof(BITMAP),&bm);
TransparentBlt(mdc,50,50,bm.bmWidth,bm.bmHeight,bufdc,0,0,bm.bmWidth,bm.bmHeight,RGB(255,255,255));



//血条贴图
if (man.blood==9)
{
SelectObject(bufdc,hbm8);
GetObject(hbm8,sizeof(BITMAP),&bm);
TransparentBlt(mdc,200,55,bm.bmWidth,bm.bmHeight,bufdc,0,0,bm.bmWidth,bm.bmHeight,RGB(255,255,255));
}
else if (man.blood>=6&&man.blood<9)
{
SelectObject(bufdc,hbm9);
GetObject(hbm9,sizeof(BITMAP),&bm);
TransparentBlt(mdc,200,55,bm.bmWidth,bm.bmHeight,bufdc,0,0,bm.bmWidth,bm.bmHeight,RGB(255,255,255));
}
else if (man.blood>=3&&man.blood<6)
{
SelectObject(bufdc,hbm10);
GetObject(hbm10,sizeof(BITMAP),&bm);
TransparentBlt(mdc,200,55,bm.bmWidth,bm.bmHeight,bufdc,0,0,bm.bmWidth,bm.bmHeight,RGB(255,255,255));
}
else if (man.blood<=3)
{
SelectObject(bufdc,hbm11);
GetObject(hbm11,sizeof(BITMAP),&bm);
TransparentBlt(mdc,200,55,bm.bmWidth,bm.bmHeight,bufdc,0,0,bm.bmWidth,bm.bmHeight,RGB(255,255,255));
}
//NPC贴图
SelectObject(bufdc,hbm6);
GetObject(hbm6,sizeof(BITMAP),&bm);
TransparentBlt(mdc,x,y,bm.bmWidth/4,bm.bmHeight,bufdc,bm.bmWidth*num/4,0,bm.bmWidth/4,bm.bmHeight,RGB(255,255,255));

//不同地图上的怪物、钥匙、传送门贴图
if (map==1)
{
SelectObject(bufdc,hbm18);
GetObject(hbm18,sizeof(BITMAP),&bm);
TransparentBlt(mdc,door[0].x,door[0].y,bm.bmWidth,bm.bmHeight,bufdc,0,0,bm.bmWidth,bm.bmHeight,RGB(255,255,255));
SelectObject(bufdc,hbm4);
GetObject(hbm4,sizeof(BITMAP),&bm);
TransparentBlt(mdc,fire[0].x,fire[0].y,bm.bmWidth/3,bm.bmHeight,bufdc,bm.bmWidth*fire[0].num/3,0,bm.bmWidth/3,bm.bmHeight,RGB(255,255,255));
TransparentBlt(mdc,fire[1].x,fire[1].y,bm.bmWidth/3,bm.bmHeight,bufdc,bm.bmWidth*fire[1].num/3,0,bm.bmWidth/3,bm.bmHeight,RGB(255,255,255));
TransparentBlt(mdc,fire[2].x,fire[2].y,bm.bmWidth/3,bm.bmHeight,bufdc,bm.bmWidth*fire[2].num/3,0,bm.bmWidth/3,bm.bmHeight,RGB(255,255,255));
SelectObject(bufdc,hbm5);
GetObject(hbm5,sizeof(BITMAP),&bm);
TransparentBlt(mdc,mushroom[0].x,mushroom[0].y,bm.bmWidth/3,bm.bmHeight,bufdc,bm.bmWidth*mushroom[0].num/3,0,bm.bmWidth/3,bm.bmHeight,RGB(255,255,255));
TransparentBlt(mdc,mushroom[1].x,mushroom[1].y,bm.bmWidth/3,bm.bmHeight,bufdc,bm.bmWidth*mushroom[1].num/3,0,bm.bmWidth/3,bm.bmHeight,RGB(255,255,255));
SelectObject(bufdc,hbm17);
GetObject(hbm17,sizeof(BITMAP),&bm);
if (key[0].use==1) TransparentBlt(mdc,key[0].x,key[0].y,bm.bmWidth,bm.bmHeight,bufdc,0,0,bm.bmWidth,bm.bmHeight,RGB(255,255,255));
if (key[1].use==1) TransparentBlt(mdc,key[1].x,key[1].y,bm.bmWidth,bm.bmHeight,bufdc,0,0,bm.bmWidth,bm.bmHeight,RGB(255,255,255));
}
else if (map==2)
{
SelectObject(bufdc,hbm18);
GetObject(hbm18,sizeof(BITMAP),&bm);
TransparentBlt(mdc,door[1].x,door[1].y,bm.bmWidth,bm.bmHeight,bufdc,0,0,bm.bmWidth,bm.bmHeight,RGB(255,255,255));
SelectObject(bufdc,hbm20);
GetObject(hbm20,sizeof(BITMAP),&bm);
TransparentBlt(mdc,door[2].x,door[2].y,bm.bmWidth/3,bm.bmHeight,bufdc,bm.bmWidth*num1/3,0,bm.bmWidth/3,bm.bmHeight,RGB(255,255,255));
if (ghost[0].dir==0) 
{
SelectObject(bufdc,hbm3);
GetObject(hbm3,sizeof(BITMAP),&bm);
TransparentBlt(mdc,ghost[0].x,ghost[0].y,bm.bmWidth/9,bm.bmHeight,bufdc,bm.bmWidth*ghost[0].num/9,0,bm.bmWidth/9,bm.bmHeight,RGB(255,255,255));
}
else if (ghost[0].dir==1)
{
SelectObject(bufdc,hbm14);
GetObject(hbm14,sizeof(BITMAP),&bm);
TransparentBlt(mdc,ghost[0].x,ghost[0].y,bm.bmWidth/9,bm.bmHeight,bufdc,bm.bmWidth*ghost[0].num/9,0,bm.bmWidth/9,bm.bmHeight,RGB(255,255,255));
}

if (ghost[1].dir==0) 
{
SelectObject(bufdc,hbm3);
GetObject(hbm3,sizeof(BITMAP),&bm);
TransparentBlt(mdc,ghost[1].x,ghost[1].y,bm.bmWidth/9,bm.bmHeight,bufdc,bm.bmWidth*ghost[1].num/9,0,bm.bmWidth/9,bm.bmHeight,RGB(255,255,255));
}
else if (ghost[1].dir==1)
{
SelectObject(bufdc,hbm14);
GetObject(hbm14,sizeof(BITMAP),&bm);
TransparentBlt(mdc,ghost[1].x,ghost[1].y,bm.bmWidth/9,bm.bmHeight,bufdc,bm.bmWidth*ghost[1].num/9,0,bm.bmWidth/9,bm.bmHeight,RGB(255,255,255));
}

if (ghost[2].dir==0) 
{
SelectObject(bufdc,hbm3);
GetObject(hbm3,sizeof(BITMAP),&bm);
TransparentBlt(mdc,ghost[2].x,ghost[2].y,bm.bmWidth/9,bm.bmHeight,bufdc,bm.bmWidth*ghost[2].num/9,0,bm.bmWidth/9,bm.bmHeight,RGB(255,255,255));
}
else if (ghost[2].dir==1)
{
SelectObject(bufdc,hbm14);
GetObject(hbm14,sizeof(BITMAP),&bm);
TransparentBlt(mdc,ghost[2].x,ghost[2].y,bm.bmWidth/9,bm.bmHeight,bufdc,bm.bmWidth*ghost[2].num/9,0,bm.bmWidth/9,bm.bmHeight,RGB(255,255,255));
}
if (fire[3].dir==1) 
{
SelectObject(bufdc,hbm15);
GetObject(hbm15,sizeof(BITMAP),&bm);
TransparentBlt(mdc,fire[3].x,fire[3].y,bm.bmWidth/5,bm.bmHeight,bufdc,bm.bmWidth*fire[3].num/5,0,bm.bmWidth/5,bm.bmHeight,RGB(255,255,255));
}
else if (fire[3].dir==0)
{
SelectObject(bufdc,hbm16);
GetObject(hbm16,sizeof(BITMAP),&bm);
TransparentBlt(mdc,fire[3].x,fire[3].y,bm.bmWidth/5,bm.bmHeight,bufdc,bm.bmWidth*fire[3].num/5,0,bm.bmWidth/5,bm.bmHeight,RGB(255,255,255));
}
SelectObject(bufdc,hbm17);
GetObject(hbm17,sizeof(BITMAP),&bm);
if (key[2].use==1) TransparentBlt(mdc,key[2].x,key[2].y,bm.bmWidth,bm.bmHeight,bufdc,0,0,bm.bmWidth,bm.bmHeight,RGB(255,255,255));
if (flag<=1000&&flag>=0) 
{
SelectObject(bufdc,hbm19);
GetObject(hbm19,sizeof(BITMAP),&bm);
TransparentBlt(mdc,fire[4].x,fire[4].y,bm.bmWidth/6,bm.bmHeight,bufdc,bm.bmWidth*fire[4].num/6,0,bm.bmWidth/6,bm.bmHeight,RGB(255,255,255));
}
}
SelectObject(bufdc,hbm1);
GetObject(hbm1,sizeof(BITMAP),&bm);
TransparentBlt(mdc,man.x,man.y,bm.bmWidth/4,bm.bmHeight/4,bufdc,bm.bmWidth*man.num/4,bm.bmHeight*man.dir/4,bm.bmWidth/4,bm.bmHeight/4,RGB(255,255,255));


BitBlt(hdc,0,0,1200,680,mdc,0,0,SRCCOPY);
}


tPre = GetTickCount();    
}
void reset()
{
map=1;
flag=1001;
t=0;


x=780;
y=120;
num=0;
win=0;
//人物初始化
man.x = 0;
man.y = 520;
man.dir = 0;
man.move=0;
man.blood=9;
num = 0;
man.num=0;
//障碍物初始化
fire[0].x=1300;
fire[0].y=260;
fire[0].dir=1;
fire[0].num=0;
fire[1].x=1400;
fire[1].y=400;
fire[1].dir=1;
fire[1].num=0;
fire[2].x=1200;
fire[2].y=540;
fire[2].dir=1;
fire[2].num=0;
fire[3].x=1000;
fire[3].y=400;
fire[3].dir=1;
fire[3].num=0;
fire[3].str=0;
fire[4].x=0;
fire[4].y=0;
fire[4].num=0;


mushroom[0].x=400;
mushroom[0].y=290;
mushroom[0].dir=0;
mushroom[0].num=0;
mushroom[1].x=800;
mushroom[1].y=520;
mushroom[1].dir=1;
mushroom[1].num=0;


ghost[0].x=400;
ghost[0].y=300;
ghost[0].dir=0;
ghost[0].num=0;
ghost[1].x=400;
ghost[1].y=400;
ghost[1].dir=1;
ghost[1].num=0;
ghost[2].x=1100;
ghost[2].y=500;
ghost[2].dir=0;
ghost[2].num=0;
//钥匙初始化
key[0].x=400;
key[0].y=290;
key[0].use=1;


key[1].x=800;
key[1].y=500;
key[1].use=1;


key[2].use=1;
//传送门初始化
door[0].x=1050;
door[0].y=520;
door[1].x=0;
door[1].y=520;
door[2].x=950;
door[2].y=550;
num1=0;
}


LRESULT CALLBACK WndProc(HWND hWnd,UINT message,WPARAM  wParam,LPARAM lParam)
{
//人物行走按键响应
switch (message)
{
case WM_LBUTTONDOWN:
x2=LOWORD(lParam);
y2=HIWORD(lParam);
if (t==1)
{
if (x2>=350&&x2<=530&&y2>=366&&y2<=422) reset();
}
break;
case WM_KEYDOWN:
if (wParam=='W')
{
man.dir=3;
man.move=1;
}
else if (wParam=='S')
{
man.dir=0;
man.move=1;
}
else if (wParam=='A')
{
man.dir=1;
man.move=1;
}
else if (wParam=='D')
{
man.dir=2;
man.move=1;
}
break;
case WM_KEYUP:
man.move=0;
man.num=0;
break;
case WM_DESTROY:    
DeleteDC(mdc);
DeleteDC(bufdc);
DeleteObject(hbm1);
DeleteObject(hbm2);
ReleaseDC(hWnd,hdc);
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
   return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值