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

📄 mydraw.cpp

📁 推箱子游戏 为研究A*寻路算法的实现
💻 CPP
字号:
// MyDraw.cpp: implementation of the CMyDraw class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "MyDraw.h"

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CMyDraw::CMyDraw()
{

}

CMyDraw::~CMyDraw()
{

}

BOOL CMyDraw::InitMyDraw(HINSTANCE hInstance, HWND hWnd)
{
	hdc = GetDC(hWnd);
	
	hMemDC1 = CreateCompatibleDC(hdc);
	hMemDC2 = CreateCompatibleDC(hdc);
	hMemDC3 = CreateCompatibleDC(hdc);
	hMemDC4 = CreateCompatibleDC(hdc);
	hMemDC5 = CreateCompatibleDC(hdc);
	hMemDC6 = CreateCompatibleDC(hdc);
	hMemDC7 = CreateCompatibleDC(hdc);
	hMemDC8 = CreateCompatibleDC(hdc);
	hMemDC9 = CreateCompatibleDC(hdc);
	hMemDC10 = CreateCompatibleDC(hdc);
	hBitmap1 = LoadBitmap(hInstance,MAKEINTRESOURCE(IDB_BITMAP1));
	hBitmap2 = LoadBitmap(hInstance,MAKEINTRESOURCE(IDB_BITMAP2));	
	hBitmap3 = LoadBitmap(hInstance,MAKEINTRESOURCE(IDB_BITMAP3));	
	hBitmap4 = LoadBitmap(hInstance,MAKEINTRESOURCE(IDB_BITMAP4));
	hBitmap5 = LoadBitmap(hInstance,MAKEINTRESOURCE(IDB_BITMAP5));
	hBitmap6 = LoadBitmap(hInstance,MAKEINTRESOURCE(IDB_BITMAP6));
	hBitmap7 = LoadBitmap(hInstance,MAKEINTRESOURCE(IDB_BITMAP7));
	hBitmap8 = LoadBitmap(hInstance,MAKEINTRESOURCE(IDB_BITMAP8));
	hBitmap9 = LoadBitmap(hInstance,MAKEINTRESOURCE(IDB_BITMAP9));
	hBitmap10 = LoadBitmap(hInstance,MAKEINTRESOURCE(IDB_BITMAP10));
	SelectObject(hMemDC1,hBitmap1);
	SelectObject(hMemDC2,hBitmap2);
	SelectObject(hMemDC3,hBitmap3);
	SelectObject(hMemDC4,hBitmap4);
	SelectObject(hMemDC5,hBitmap5);
	SelectObject(hMemDC6,hBitmap6);
	SelectObject(hMemDC7,hBitmap7);
	SelectObject(hMemDC8,hBitmap8);
	SelectObject(hMemDC9,hBitmap9);
	SelectObject(hMemDC10,hBitmap10);
    return TRUE;
}
//绘制界面
BOOL CMyDraw::DrawJM(int map[9][8])
{
	int i,j; 

	for(i=0;i<8;i++)
	{
		for(j=0;j<9;j++)
		{
			BitBlt(hdc,40*i,30*j,40,30,hMemDC1,0,0,SRCCOPY);
			if(map[j][i] == 1)
				BitBlt(hdc,40*i,30*j,40,30,hMemDC3,0,0,SRCCOPY); 
			if(map[j][i] == 2)
				BitBlt(hdc,40*i,30*j,40,30,hMemDC2,0,0,SRCCOPY); 
		}		
	}
	return TRUE;
}
//绘制人物正面
BOOL CMyDraw::DrawBaby(POINT point)
{
	BitBlt(hdc,40*point.x,30*point.y,40,30,hMemDC5,0,0,SRCAND);
	BitBlt(hdc,40*point.x,30*point.y,40,30,hMemDC5,40,0,SRCPAINT);
	return TRUE;
}
//绘制人物左面
BOOL CMyDraw::DrawBabyL(POINT point)
{
	BitBlt(hdc,40*point.x,30*point.y,40,30,hMemDC7,0,0,SRCAND);
	BitBlt(hdc,40*point.x,30*point.y,40,30,hMemDC7,40,0,SRCPAINT);
	return TRUE;
}
//绘制人物右面
BOOL CMyDraw::DrawBabyR(POINT point)
{
	BitBlt(hdc,40*point.x,30*point.y,40,30,hMemDC8,0,0,SRCAND);
	BitBlt(hdc,40*point.x,30*point.y,40,30,hMemDC8,40,0,SRCPAINT);
	return TRUE;
}
//绘制人物背面
BOOL CMyDraw::DrawBabyB(POINT point)
{
	BitBlt(hdc,40*point.x,30*point.y,40,30,hMemDC9,0,0,SRCAND);
	BitBlt(hdc,40*point.x,30*point.y,40,30,hMemDC9,40,0,SRCPAINT);
	return TRUE;
}
//绘制盒子
BOOL CMyDraw::DrawBox(POINT point)
{
	BitBlt(hdc,40*point.x,30*point.y,40,30,hMemDC4,0,0,SRCAND);
	BitBlt(hdc,40*point.x,30*point.y,40,30,hMemDC4,40,0,SRCPAINT);
	return TRUE;
}
//绘制盒子
BOOL CMyDraw::DrawBoxn(POINT point)
{
	BitBlt(hdc,40*point.x,30*point.y,40,30,hMemDC10,0,0,SRCAND);
	BitBlt(hdc,40*point.x,30*point.y,40,30,hMemDC10,40,0,SRCPAINT);
	return TRUE;
}

//绘制背景
BOOL CMyDraw::DrawBg(POINT point)
{
	BitBlt(hdc,40*point.x,30*point.y,40,30,hMemDC1,0,0,SRCCOPY);
	return TRUE;
}

//绘制旗子
BOOL CMyDraw::DrawFlag(POINT point)
{
	BitBlt(hdc,40*point.x,30*point.y,40,30,hMemDC6,0,0,SRCCOPY);
	return TRUE;
}

//移动人物
POINT CMyDraw::BabyMove(POINT strpt, POINT endpt,int& babyn)
{
	if(BackDriect(strpt,endpt) == 1)   //调用左移
	{
		DrawBg(strpt);
		DrawBabyR(endpt);
		babyn=1;
	}
	if(BackDriect(strpt,endpt) == 2)   //调用右移
	{
		DrawBg(strpt);
		DrawBabyL(endpt);
		babyn=2;
	}
	if(BackDriect(strpt,endpt) == 3)   //调用上移
	{
		DrawBg(strpt);
		DrawBaby(endpt);
		babyn=3;
	}
	if(BackDriect(strpt,endpt) == 4)   //调用下移
	{
		DrawBg(strpt);
		DrawBabyB(endpt);
		babyn=4;
	}
    return endpt;
}

//返回终点在起点的上、下、左、右方向
int CMyDraw::BackDriect(POINT strpt, POINT endpt)
{
	int k;
    if((endpt.x-1-strpt.x == 0) && (endpt.y-strpt.y == 0))   //左方
		return k=1;
	if((endpt.x+1-strpt.x == 0) && (endpt.y-strpt.y == 0))   //右方
		return k=2;
	if((endpt.x-strpt.x == 0) && (endpt.y-1-strpt.y == 0))   //上方
		return k=3;
	if((endpt.x-strpt.x == 0) && (endpt.y+1-strpt.y == 0))   //下方
		return k=4;
	return 0;
}

⌨️ 快捷键说明

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