#include <windows.h>
#include <ddraw.h>
#include "ddutil.h"
#include "stdio.h"
#include "resource.h"
//Download by http://www.codefans.net
//函数声明
INT UpdateFrame();
LRESULT CALLBACK WindowFunc(HWND,UINT,WPARAM,LPARAM);
BOOL InitDDraw( void );
void GetRect(RECT* rect, long left, long top, long width, long height);
void Flip(void);
void DrawAll();
void InitData();
void CheckHit();
void StepAll();
void StartGame();
void DrawNumber(LPDIRECTDRAWSURFACE dd,LPDIRECTDRAWSURFACE ss,int num,int x,int y,int width,int height);
//全局变量
char szClassName[] = "ForEpork";
HWND hwnd;
HINSTANCE hInst;
BOOL bActive;
DWORD delay; //延时
DWORD dwTickCount,dwLastTickCount;
//关于游戏的全局变量
BOOL hit,get;
POINT pos; //木锤位置
int forewidth, foreheight;//前台页面的宽度和高度
RECT backrect; //后台页面映射矩形
int backwidth, backheight;//后台页面的宽度和高度
int mouse[9]; //老鼠洞出现东东的纪录
POINT holepos[9]; //老鼠洞的位置
POINT mousepos[9]; //老鼠头的位置
int status[9]; //老鼠状态,0-4
int behit[9]; //老鼠各个被打的纪录
int mousewidth;
int mouseheight;
POINT pt;
int time; //剩余时间
int score; //分数
int GameStatus; //游戏状态
//DirectDraw变量
LPDIRECTDRAW lpDD;
LPDIRECTDRAWCLIPPER lpClipper;
LPDIRECTDRAWSURFACE lpDDSFront; //以下均为DirectDrawSurface对象
LPDIRECTDRAWSURFACE lpDDSBack;
LPDIRECTDRAWSURFACE lpDDSMouse[3];
LPDIRECTDRAWSURFACE lpDDSHammer;
LPDIRECTDRAWSURFACE lpDDSBk;
LPDIRECTDRAWSURFACE lpDDSLogo;
LPDIRECTDRAWSURFACE lpDDSBow;
LPDIRECTDRAWSURFACE lpDDSFig;
LPDIRECTDRAWSURFACE lpDDSHamfig;
LPDIRECTDRAWSURFACE lpDDSTime;
LPDIRECTDRAWSURFACE lpDDSScore[3];
INT WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nMode)
{
MSG msg;
WNDCLASSEX wcl;
wcl.cbClsExtra = 0;
wcl.cbSize = sizeof(WNDCLASSEX);
wcl.cbWndExtra = 0;
wcl.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH);
wcl.hCursor = LoadCursor(NULL,IDC_ARROW);
wcl.hIcon = LoadIcon(hInstance,"IDI_ICON1");
wcl.hIconSm = LoadIcon(NULL,IDI_WINLOGO);
wcl.hInstance = hInstance;
wcl.lpfnWndProc = WindowFunc;
wcl.lpszClassName = szClassName;
wcl.lpszMenuName = NULL;
wcl.style = 0;
if (!RegisterClassEx(&wcl)) return 0;
hwnd = CreateWindow(
szClassName,
"打老鼠",
WS_SYSMENU|WS_CAPTION|WS_MINIMIZEBOX|WS_POPUP,
180,
80,
433,
348,
HWND_DESKTOP,
NULL,
hInstance,
NULL);
ShowWindow(hwnd,nMode);
UpdateWindow(hwnd);
if (!InitDDraw())
{
MessageBox(GetActiveWindow(), "初始化DirectDraw过程中出错!请检查你是否正确的安装了DirectX。", "Error", MB_OK );
return 0;
}
hInst = hInstance;
InitData();
SetTimer(hwnd,1,200,NULL);
SetTimer(hwnd,2,1000,NULL);
while(1)
{
if( PeekMessage(&msg,NULL,0,0,PM_NOREMOVE))
{
if (!GetMessage(&msg,NULL,0,0))
{
return msg.wParam;
}
TranslateMessage(&msg);
DispatchMessage(&msg);
}
else if( bActive)
{
UpdateFrame();
}
else
{
WaitMessage();
}
}
KillTimer(hwnd,1);
return msg.wParam;
}
LRESULT CALLBACK WindowFunc(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam)
{
switch(message)
{
case WM_ACTIVATEAPP://
bActive = wParam;
break;
case WM_CREATE:
//写入注册表
HKEY hRegKey;
unsigned long result;
char version[10];
sprintf(version,"1.00");
RegCreateKeyEx(HKEY_CURRENT_USER,"Software\\Raynor Game\\For Epork",0,"Epork",0,KEY_ALL_ACCESS,
NULL,&hRegKey,&result);
if (result == REG_CREATED_NEW_KEY)
{
RegSetValueEx(hRegKey,"Version",0,REG_SZ,(LPBYTE)version,4);
}
else
{
RegSetValueEx(hRegKey,"Version",0,REG_SZ,(LPBYTE)version,4);
}
RegCloseKey(hRegKey);
break;
case WM_SETCURSOR:
SetCursor(NULL);
break;
case WM_KEYDOWN:
switch (char(wParam))
{
case VK_SUBTRACT:
delay += 2;
break;
case VK_ADD:
if (delay>2) delay -= 2;
break;
case VK_ESCAPE:
MessageBox(hwnd,"送给你的...:)\n From:\n 耗子\nhttp://rpg.3322.net\n Raynor@ah163.com","关于这个游戏",MB_OK);
PostQuitMessage(0);
break;
}
break;
case WM_LBUTTONDOWN:
if (GameStatus == 1)
{
hit = true;
get = false;
}
else
{
StartGame();
}
break;
case WM_LBUTTONUP:
hit = false;
break;
case WM_DESTROY:
MessageBox(hwnd,"送给你的...:)\n From:\n 耗子\nhttp://rpg.3322.net\n Raynor@ah163.com","关于这个游戏",MB_OK);
PostQuitMessage(0);
break;
case WM_MOUSEMOVE:
pos.x = LOWORD(lParam);
pos.y = HIWORD(lParam);
break;
case WM_TIMER:
if (bActive)
{
switch (wParam)
{
case 1:
StepAll();
break;
case 2:
time --;
break;
}
}
break;
default:
return DefWindowProc(hwnd,message,wParam,lParam);
break;
}
return 0;
}
INT UpdateFrame()
{
if (bActive)
{
dwTickCount = GetTickCount();
if ((dwTickCount - dwLastTickCount) <= delay)
{
return 0;
}
dwLastTickCount = dwTickCount;
//Here to add my code...
DrawAll();
CheckHit();
Flip();
}
return 1;
}
BOOL InitDDraw()
{
DWORD dwFlags;
DDSURFACEDESC ddsd;
//创建DirectDraw对象
DirectDrawCreate(NULL, &lpDD, NULL);
//设置协作级别为窗口模式
dwFlags = DDSCL_NORMAL;
lpDD->SetCooperativeLevel(hwnd, dwFlags);
//创建主页面
ZeroMemory(&ddsd, sizeof(ddsd));
ddsd.dwSize = sizeof(ddsd);
ddsd.dwFlags = DDSD_CAPS;
ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
lpDD->CreateSurface(&ddsd, &lpDDSFront, NULL);
//创建离屏页面
ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
RECT rect;
GetClientRect(hwnd, &rect);
forewidth=rect.right-rect.left;
foreheight=rect.bottom-rect.top;
GetRect(&backrect, 0, 0, 433,348);
ddsd.dwWidth = backwidth=forewidth;
ddsd.dwHeight = backheight=foreheight;
lpDD->CreateSurface( &ddsd, &lpDDSBack, NULL );
//创建老鼠页面
ddsd.dwWidth = 124;
ddsd.dwHeight = 425;
lpDD->CreateSurface( &ddsd, &lpDDSMouse[0], NULL );
lpDD->CreateSurface( &ddsd, &lpDDSMouse[1], NULL );
lpDD->CreateSurface( &ddsd, &lpDDSMouse[2], NULL );
DDReLoadBitmap(lpDDSMouse[0], "MOUSE00.BMP");
DDReLoadBitmap(lpDDSMouse[1], "MOUSE01.BMP");
DDReLoadBitmap(lpDDSMouse[2], "MOUSE02.BMP");
DDSetColorKey(lpDDSMouse[0],RGB(0,0,255));
DDSetColorKey(lpDDSMouse[1],RGB(0,0,255));
DDSetColorKey(lpDDSMouse[2],RGB(0,0,255));
//创建木锤
ddsd.dwWidth = 68;
ddsd.dwHeight = 136;
lpDD->CreateSurface( &ddsd, &lpDDSHammer, NULL );
DDReLoadBitmap(lpDDSHammer, "HAM.BMP");
DDSetColorKey(lpDDSHammer,RGB(0,0,255));
//创建火花
ddsd.dwWidth = 68;
ddsd.dwHeight = 24;
lpDD->CreateSurface( &ddsd, &lpDDSBow, NULL );
DDReLoadBitmap(lpDDSBow, "Bow.BMP");
DDSetColorKey(lpDDSBow,RGB(255,0,127));
//创建标题
ddsd.dwWidth = 319;
ddsd.dwHeight = 56;
lpDD->CreateSurface( &ddsd, &lpDDSLogo, NULL );
DDReLoadBitmap(lpDDSLogo, "logo.BMP");
DDSetColorKey(lpDDSLogo,RGB(0,0,255));
//创建背景
ddsd.dwWidth = 433;
ddsd.dwHeight = 348;
lpDD->CreateSurface( &ddsd, &lpDDSBk, NULL );
DDReLoadBitmap(lpDDSBk, "BK.BMP");
//创建时间
ddsd.dwWidth = 45;
ddsd.dwHeight = 13;
lpDD->CreateSurface( &ddsd, &lpDDSTime, NULL );
DDReLoadBitmap(lpDDSTime, "Time.BMP");
DDSetColorKey(lpDDSTime,RGB(255,0,127));
//创建数字
ddsd.dwWidth = 260;
ddsd.dwHeight = 38;
lpDD->CreateSurface( &ddsd, &lpDDSHamfig, NULL );
DDReLoadBitmap(lpDDSHamfig, "Hamfig.BMP");
DDSetColorKey(lpDDSHamfig,RGB(255,0,127));
//创建数字
ddsd.dwWidth = 160;
ddsd.dwHeight = 23;
lpDD->CreateSurface( &ddsd, &lpDDSFig, NULL );
DDReLoadBitmap(lpDDSFig, "fig.BMP");
DDSetColorKey(lpDDSFig,RGB(255,0,127));
//创建分数页面
ddsd.dwWidth = 43;
ddsd.dwHeight = 25;
lpDD->CreateSurface( &ddsd, &lpDDSScore[0], NULL );
lpDD->CreateSurface( &ddsd, &lpDDSScor
没有合适的资源?快使用搜索试试~ 我知道了~
mice.rar_Mice_VC 游戏
共27个文件
bmp:13个
cpp:2个
h:2个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 196 浏览量
2022-09-21
05:47:57
上传
评论
收藏 66KB RAR 举报
温馨提示
VC 打老鼠 //关于游戏的全局变量 BOOL hit,get POINT pos //木锤位置 int forewidth, foreheight //前台页面的宽度和高度 RECT backrect //后台页面映射矩形 int backwidth, backheight //后台页面的宽度和高度 int mouse[9] //老鼠洞出现东东的纪录 POINT holepos[9] //老鼠洞的位置 POINT mousepos[9] //老鼠头的位置 int status[9] //老鼠状态,0-4 int behit[9] //老鼠各个被打的纪录 int mousewidth int mouseheight POINT pt int time //剩余时间 int score //分数 int GameStatus //游戏状态
资源推荐
资源详情
资源评论
收起资源包目录
mice.rar (27个子文件)
codefans.net
epoch
Script1.aps 17KB
SCORE01.BMP 2KB
epoch.plg 1KB
HAMBNS.FLC 12KB
Score02.bmp 2KB
Score03.bmp 2KB
epoch.dsp 4KB
FIG.BMP 5KB
Mouse01.bmp 53KB
icon1.ico 766B
HAMFIG.BMP 11KB
ham.bmp 10KB
Script1.rc 2KB
epoch.ncb 57KB
DDUTIL.H 1KB
TIME.BMP 2KB
epoch.dsw 533B
score.dat 4B
Bk.bmp 149KB
BOW.BMP 3KB
Ddutil.cpp 8KB
epoch.opt 53KB
resource.h 501B
main.cpp 17KB
Mouse00.bmp 53KB
Mouse02.bmp 53KB
logo.bmp 19KB
共 27 条
- 1
资源评论
寒泊
- 粉丝: 86
- 资源: 1万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功