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

📄 bullet.cpp

📁 Win32项目,类似坦克大战的游戏"忘记喧嚣". 游戏的各系统完整,闪屏,道具.碰撞等等....推荐
💻 CPP
字号:
#include ".\bullet.h"

Bullet::Bullet(HDC hdc, HDC mdc, HDC bufdc)
{
	b_hdc = hdc;
	b_mdc = mdc;
	b_bufdc = bufdc;
	b_laserMap[0] = (HBITMAP)::LoadImage(NULL, "../res/graphics/laser1_h.bmp", IMAGE_BITMAP, 10, 10, LR_LOADFROMFILE);
	b_laserMap[1] = (HBITMAP)::LoadImage(NULL, "../res/graphics/laser1_v.bmp", IMAGE_BITMAP, 10, 10, LR_LOADFROMFILE);
	b_laserMap[2] = (HBITMAP)::LoadImage(NULL, "../res/graphics/laser2_h.bmp", IMAGE_BITMAP, 10, 10, LR_LOADFROMFILE);
	b_laserMap[3] = (HBITMAP)::LoadImage(NULL, "../res/graphics/laser2_v.bmp", IMAGE_BITMAP, 10, 10, LR_LOADFROMFILE);
	b_explode     = (HBITMAP)::LoadImage(NULL, "../res/graphics/setup2.bmp", IMAGE_BITMAP, 560, 56, LR_LOADFROMFILE);
	b_point.x = 0;
	b_point.y = 0;	
	b_xV = 0;
	b_yV = 0;
	b_M  = 0;
	b_rect.bottom = 0;
	b_rect.left   = 0;
	b_rect.right  = 0;
	b_rect.top    = 0;
	b_explodeTurn = 0;
	b_exit = false;
	b_exploding = false;
}

Bullet::~Bullet(void)
{
	for (int i=0; i<4; i++)
	{
		::DeleteObject(b_laserMap[i]);
	}
	::DeleteObject(b_explode);
	::DeleteDC(b_bufdc);
	::DeleteDC(b_mdc);
	::DeleteDC(b_hdc);
}

void Bullet::ShowBullet(void)
{
	if (b_exit)
	{
		::SelectObject(b_mdc, b_laserMap[b_M]);
		::TransparentBlt(b_bufdc,b_point.x, b_point.y, 10, 10, b_mdc, 0, 0, 10, 10, RGB(0,255,0));
	}
}

void Bullet::ShowExplode(int x, int y)
{
	if (b_exploding)
	{
		::SelectObject(b_mdc, b_explode);
		::TransparentBlt(b_bufdc,x, y, 40, 40, b_mdc, b_explodeTurn*56+4, 4, 40, 40, RGB(255,0,255));
		++b_explodeTurn;
	}

	if (b_explodeTurn == 9)
	{
		b_explodeTurn = 0;
		b_exploding = false;
	}
}

void Bullet::SetRect(int x, int y)
{
	b_rect.left = x;
	b_rect.top = y;
	b_rect.right = b_rect.left + 10;
	b_rect.bottom = b_rect.top + 10;
}

bool Bullet::BulletHitMap(Map *map, int x, int y)
{
	RECT temp;
	SetRect(x, y);
	for (int i=0; i<TILE_H; i++)
	{
		for (int j=0; j<TILE_W; j++)
		{
			if (map->m_map[i][j]==1 || map->m_map[i][j]==3)
			{
				map->SetRect(i, j);

				if (IntersectRect(&temp, &b_rect, &(map->m_rect)) || IntersectRect(&temp, &b_rect, &(map->m_kingRect)))
				{
					b_exploding = true;               // 显示爆炸
					ShowExplode(x-20, y-20);

					if (map->m_map[i][j] == 1)
					{
						map->m_map[i][j] = 0;
					}
					return true;				
				}
			}
		}
	}
	return false;
}

bool Bullet::BulletHitKing(Map *map, int x, int y)
{
	RECT temp;
	SetRect(x, y);
	map->SetKingRect();
	if (IntersectRect(&temp, &b_rect, &(map->m_kingRect)))
	{
		return true;				
	}
	return false;
}

⌨️ 快捷键说明

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