⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.cpp

📁 Astar 精灵版本 Astar 精灵版本
💻 CPP
字号:
#include <windows.h>
#include "Astart.h"
#include "Sprite.h"
#include "List.h"
#include "List.cpp"
#define KEYDOWN(vk_code) ((GetAsyncKeyState(vk_code) & 0x8000) ? 1 : 0)
TCHAR szAppClassName[] = TEXT("ShengHun");				// WNCLASS名
HINSTANCE hInst;	// 当前实例
HWND hWnd;
HDC hdc;
HBITMAP backbitmap;
HBITMAP zabitmap;
int manx = 0;
int many = 408;
Sprite a("未命名.bmp","人物.bmp",RGB(255,0,255),8,4);

int map[6][13] = {
{ 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 1, 1, 1 },
{ 1, 1, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0 },
{ 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0 },
{ 1, 1, 1, 1, 1, 0, 0, 1, 0, 0, 1, 0, 0 },
{ 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 1, 0 }
};
// 此代码模块中包含的函数的前向声明:
ATOM				MyRegisterClass(HINSTANCE hInstance);
BOOL				InitInstance(HINSTANCE, int);
LRESULT CALLBACK	WndProc(HWND, UINT, WPARAM, LPARAM);
int APIENTRY WinMain(HINSTANCE hInstance,
                     HINSTANCE hPrevInstance,
                     LPTSTR    lpCmdLine,
                     int       nCmdShow)
{
 	// TODO: 在此放置代码。
	MSG msg;
	// 初始化全局字符串
	MyRegisterClass(hInstance);
	// 执行应用程序初始化:
	if (!InitInstance (hInstance, nCmdShow)) 
	{
		return FALSE;
	}
	hdc = GetDC(hWnd);
	backbitmap = (HBITMAP)LoadImage(NULL,"未命名.bmp",IMAGE_BITMAP,0,0, LR_CREATEDIBSECTION | LR_LOADFROMFILE);
	zabitmap = (HBITMAP)LoadImage(NULL,"人物.bmp",IMAGE_BITMAP,0,0, LR_CREATEDIBSECTION | LR_LOADFROMFILE);
	HDC mdc = CreateCompatibleDC(hdc);
	RECT rect;
	GetClientRect(hWnd,&rect);
	SelectObject(mdc,backbitmap);
	BitBlt(hdc,0,0,rect.right - rect.left,rect.bottom - rect.top,mdc,0,0,SRCCOPY);
	SelectObject(mdc,zabitmap);
	TransparentBlt(hdc,manx,many,96,136,mdc,0,272,96,136,RGB(255,0,255));

	while (true) 
	{
		if(KEYDOWN(VK_ESCAPE))
		{
			SendMessage(hWnd,WM_DESTROY,0,0);
		}
		if( PeekMessage( &msg, NULL, 0,0 ,PM_REMOVE) )
       {
			if(msg.message==WM_QUIT)
				break;
            TranslateMessage( &msg );
            DispatchMessage( &msg );
       }
	   if( KEYDOWN(VK_LEFT) )
	   {
		   if(manx>=20)
		   {
				a.Show(hdc,manx,many,-6,0);
				manx-=48;
				a.Show(hdc,manx,many,-6,0);
				manx-=48;
		   }
	   }
	   else if( KEYDOWN(VK_RIGHT) )
	   {
		   if(manx <= rect.right - 70)
		   {
				a.Show(hdc,manx,many,6,0);
				manx+=48;
				a.Show(hdc,manx,many,6,0);
				manx+=48;
		   }
	   }
	   else if( KEYDOWN(VK_UP) )
	   {
		   if(many >=0)
		   {
				a.Show(hdc,manx,many,0,-8);
				many-=68;
				a.Show(hdc,manx,many,0,-8);
				many-=68;
		   }
	   }
	   else if( KEYDOWN(VK_DOWN) )
	   {
		   if(many <= rect.bottom - 100)
		   {
				a.Show(hdc,manx,many,0,8);
				many+=68;
				a.Show(hdc,manx,many,0,8);
				many+=68;
		   }
	   }
	   else if( KEYDOWN(VK_RBUTTON))
	   {
			a.Show(hdc,manx,many,0,0);
	   }
	}
	return (int) 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			= LoadIcon(NULL, IDI_INFORMATION);
	wcex.hCursor		= LoadCursor(NULL, IDC_ARROW);
	wcex.hbrBackground	= (HBRUSH)GetStockObject(BLACK_BRUSH);
	wcex.lpszMenuName	= NULL;
	wcex.lpszClassName	= szAppClassName;
	wcex.hIconSm		= LoadIcon(wcex.hInstance, NULL);

	return RegisterClassEx(&wcex);
}

BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
   hInst = hInstance; // 将实例句柄存储在全局变量中

   hWnd = CreateWindow(szAppClassName,NULL,WS_POPUP ,CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInstance, NULL);

   if (!hWnd)
   {
      return FALSE;
   }

   ShowWindow(hWnd, SW_SHOWMAXIMIZED);
   UpdateWindow(hWnd);

   return TRUE;
}

LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	switch (message) 
	{
	case WM_DESTROY:
		PostQuitMessage(0);
		break;
	case WM_LBUTTONDOWN:
		{
			int x = LOWORD(lParam);
			int y =  HIWORD(lParam);
			Astart as(map,13,6,manx/96+many/136*13,x/96+y/136*13);
			if(as.Find())
			{
				as.GetResult();
				for(int i=as.value_list.Length(); i>=1; i--)
				{
					Rect b;
					as.value_list.Find(i,b);
					if(b.map_x > manx/96)
					{
						a.Show(hdc,manx,many,12,0);
						manx+=96;
					}
					if(b.map_x < manx/96)
					{
						a.Show(hdc,manx,many,-12,0);
						manx-=96;
					}
					if(b.map_y > many/136)
					{
						a.Show(hdc,manx,many,0,16);
						many+=136;
					}
					if(b.map_y < many/136)
					{
						a.Show(hdc,manx,many,0,-16);
						many-=136;
					}
				}
			}

		}
	default:
		return DefWindowProc(hWnd, message, wParam, lParam);
	}
	return 0;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -