快上网专注成都网站设计 成都网站制作 成都网站建设
成都网站建设公司服务热线:028-86922220

网站建设知识

十年网站开发经验 + 多家企业客户 + 靠谱的建站团队

量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决

c语言小游戏-创新互联

#include

创新互联公司坚持“要么做到,要么别承诺”的工作理念,服务领域包括:网站建设、网站设计、企业官网、英文网站、手机端网站、网站推广等服务,满足客户于互联网时代的巴彦网站设计、移动媒体设计的需求,帮助企业找到有效的互联网解决方案。努力成为您成熟可靠的网络建设合作伙伴!

#include

#include

#include"function.h"

LRESULT CALLBACK WndProc(HWND hwnd,UINT msg,UINT wparam,UINT lparam);

int WINAPI WinMain(HINSTANCE hinstance,HINSTANCE hpre,LPSTR lPstring,int ncmd)

{

MSG msg;

WNDCLASS wnd;

wnd.hIcon=LoadIcon(hinstance,"DICO");

wnd.hCursor=LoadCursor(NULL,IDC_ARROW);

wnd.cbClsExtra=0;

wnd.cbWndExtra=0;

wnd.hbrBackground=NULL;

wnd.hInstance=hinstance;

wnd.lpfnWndProc=(WNDPROC)WndProc;

wnd.lpszClassName="Game";

wnd.lpszMenuName=NULL;

wnd.style=CS_HREDRAW|CS_VREDRAW;

if(!RegisterClass(&wnd))

return FALSE;

hwnd=CreateWindow("Game","鸭子跳跃",WS_OVERLAPPED|WS_MINIMIZEBOX|WS_SYSMENU,400,50,500,580,NULL,NULL,hinstance,NULL);

ShowWindow(hwnd,ncmd);

UpdateWindow(hwnd);

srand((unsigned)time(NULL));

hdc=GetDC(hwnd);

hdcmem=CreateCompatibleDC(hdc);

hdcm=CreateCompatibleDC(hdc);

bufdc=CreateCompatibleDC(hdc);

Loadmap(hinstance);

SelectObject(hdcmem,hBm);

SelectObject(bufdc,hbk);

fp=fopen("Record","rb");

if(fp)

{

fread(mode,sizeof(int),4,fp);//读取记录

fclose(fp);

}

Menu=1;

Tn=1;

BTn=0;

t1=GetTickCount();

int i,k,high;

high=40;

do

{

if(PeekMessage(&msg,NULL,0,0,PM_REMOVE))

{

TranslateMessage(&msg);

DispatchMessage(&msg);

}

else

{

t2=GetTickCount();

if(t2-t1>=50)

{

if(Menu)

{

SelectObject(hdcmem,hf);

SelectObject(hdcm,Bkg[Tn].hbm);

BitBlt(hdcmem,0,0,Bkg[Tn].bm.bmWidth,Bkg[Tn].bm.bmHeight,hdcm,0,0,SRCCOPY);

for(i=0,k=0;i<18;i++)

{

if(U[i].TestShow())

{

U[i].SetPoint(high+k*60);

U[i].PaintUI();

k++;

}

}

if(help||record)

{

HPEN hp;

HBRUSH hbr;

hp=CreatePen(PS_SOLID,0,RGB(0,0,0));

hbr=CreateSolidBrush(RGB(160,215,100));

SelectObject(hdcmem,hp);

SelectObject(hdcmem,hbr);

RoundRect(hdcmem,100,100,400,360,10,10);

DeleteObject(hp);

DeleteObject(hbr);

SetBkMode(hdcmem,TRANSPARENT);

SetTextColor(hdcmem,RGB(0,0,0));

SelectObject(hdcmem,hftxt);

if(help)

for(i=0;i<6;i++)

TextOut(hdcmem,110,120+i*30,helptxt[i],strlen(helptxt[i]));

else

{

char txt[40];

for(i=0;i<4;i++)

{

sprintf(txt,"%s%d",scoretxt[i],mode[i]);

TextOut(hdcmem,130,140+i*35,txt,strlen(txt));

}

}

SelectObject(hdcmem,hf);

U[18].PaintUI();

}

SelectObject(hdcm,Duck[0][1].chm);

BitBlt(hdcmem,70,320,Duck[0][1].bm.bmWidth,Duck[0][1].bm.bmHeight,hdcm,0,0,SRCAND);

SelectObject(hdcm,Duck[0][1].hbm);

BitBlt(hdcmem,70,320,Duck[0][1].bm.bmWidth,Duck[0][1].bm.bmHeight,hdcm,0,0,SRCPAINT);

BitBlt(hdc,0,0,500,1000,hdcmem,0,0,SRCCOPY);

}

else

{

Move();

Paint();

}

t1=t2;

}

}

}while(msg.message!=WM_QUIT);

return msg.wParam;

}

LRESULT CALLBACK WndProc(HWND hwnd,UINT msg,UINT wparam,UINT lparam)

{

int i,j;

POINT p;

switch(msg)

{

case WM_MOUSEMOVE:

p.x=LOWORD(lparam);

p.y=HIWORD(lparam);

i=19;

if(record||help)

{

i--;

if(U[i].MouseInUI(p))

U[i].SetColor(1);

else

U[i].SetColor(0);

}

else

{

for(i--;i>=0;i--)

{

if(U[i].TestShow()&&U[i].MouseInUI(p))

{

U[i].SetColor(1);

if(i<=2)

Tn=i;

else if(i<=9)

BTn=i;

break;

}

else

U[i].SetColor(0);

}

}

for(i--;i>=0;i--)

U[i].SetColor(0);

return 0;

case WM_LBUTTONDOWN:

for(i=18;i>=0;i--)

{

if(U[i].TestShow()&&U[i].TestColor())

{

U[i].Respond();

U[i].SetColor(0);

break;

}

}

return 0;

case WM_KEYDOWN:

switch(wparam)

{

case VK_LEFT:

duck.Dn=0;

duck.a1=-3;

break;

case VK_RIGHT:

duck.Dn=1;

duck.a1=3;

break;

case VK_SPACE:

atk=1;

break;

}

return 0;

case WM_KEYUP:

switch(wparam)

{

case VK_LEFT:

duck.v1=0;

duck.a1=0;

break;

case VK_RIGHT:

duck.v1=0;

duck.a1=0;

break;

}

return 0;

case WM_DESTROY:

DeleteObject(hf);

DeleteObject(hftxt);

DeleteObject(hBm);

DeleteObject(hpr);

DeleteObject(Chpr);

DeleteObject(hbk);

DeleteObject(Green.hbm);

DeleteObject(Green.chm);

DeleteObject(Blue.hbm);

DeleteObject(Blue.chm);

DeleteObject(Gray.hbm);

DeleteObject(Gray.chm);

DeleteObject(White.hbm);

DeleteObject(White.chm);

DeleteObject(Bullet.hbm);

DeleteObject(Bullet.chm);

DeleteObject(Attack.hbm);

DeleteObject(Attack.chm);

for(i=0;i<10;i++)

{

if(i<2)

{

for(j=0;j<2;j++)

{

DeleteObject(Prop_help[i][j].hbm);

DeleteObject(Prop_help[i][j].chm);

}

}

if(i<3)

{

DeleteObject(Bkg[i].hbm);

DeleteObject(Bkg[i].chm);

}

if(i<4)

{

DeleteObject(Brown[i].hbm);

DeleteObject(Brown[i].chm);

}

if(i<8)

{

DeleteObject(Time[i].hbm);

DeleteObject(Time[i].chm);

}

if(i<5)

{

DeleteObject(Prop_take[i].hbm);

DeleteObject(Prop_take[i].chm);

for(j=0;j<2;j++)

{

DeleteObject(Duck[i][j].hbm);

DeleteObject(Duck[i][j].chm);

}

}

if(i<7)

{

DeleteObject(Monster[i].hbm);

DeleteObject(Monster[i].chm);

}

DeleteObject(Number[i].hbm);

DeleteObject(Number[i].chm);

}

DeleteDC(hdcmem);

DeleteDC(hdcm);

DeleteDC(bufdc);

ReleaseDC(hwnd,hdc);

PostQuitMessage(0);

return 0;

default:

return DefWindowProc(hwnd,msg,wparam,lparam);

}

}

使用VC++进行可视化编程,调用了操作系统提供的API,VC6.0编译通过,在Windows系统上运行。

创新互联www.cdcxhl.cn,专业提供香港、美国云服务器,动态BGP最优骨干路由自动选择,持续稳定高效的网络助力业务部署。公司持有工信部办法的idc、isp许可证, 机房独有T级流量清洗系统配攻击溯源,准确进行流量调度,确保服务器高可用性。佳节活动现已开启,新人活动云服务器买多久送多久。


本文标题:c语言小游戏-创新互联
URL地址:http://6mz.cn/article/ddpppd.html

其他资讯