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

📄 map.cpp

📁 3D俄罗斯方块源码.rar
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/********************************************************************
文件名: MAP.cpp
Copyright (c)2004  红孩儿工作室
创建人  : 卞安
创建时间: 2004-5-18 12:33:30
版本: 1.0
类名: CMAP
说明:
	地图数据类
********************************************************************/
#include "MAP.h"
#include "BASIC.h"
#define LEV1 0
#define LEV2 2000
#define LEV3 4000
#define LEV4 6000
#define LEV5 8000
#define LEV6 10000
#define LEV7 12000
#define LEV8 14000
#define LEV9 16000
#define LEV10 18000
void CALLBACK TimerProc(HWND hWnd,UINT nMsg,UINT nTimerid,DWORD dwTime);
bool Go1=false;//是否下落(一格一格)
bool Go2=false;
int g_row1=19;
int g_row2=19;
bool Isshow=true;//是否显示
bool Isshow2=true;
bool Go3=false;//结束后用来显示动画
bool Go4=false;
int g_count=5;
int g_count2=5;
bool Go12=false;//碰撞后显示动画
bool Go22=false;
bool g_bToButtom=false;//是否可以下落至低部
bool g_bToButtom2=false;
bool g_bIsDown=false;//是否正在下落至低部
bool g_bIsDown2=false;
//---------------------------------------------------------------
/********************************************************************
函数名  : init
输入参数: 
    _which:哪个主角
	hWnd:主窗口
	g_pD3DDevice:D3D设备
	g_pInfo:游戏信息结构

输出参数: 
	TRUE	成功
	FALSE	失败
功能描述:
	初始化主角类
全局变量: 无
调用模块: 无
********************************************************************/
bool CMAP::init(int _type,int _level,int _row,bool _shownext,LPDIRECT3DDEVICE8 pD3DDevice,HWND _hWnd,C2DSOUND *_sound,C2DSOUND *_sound2)
{ 
	m_IsshowNext=_shownext;
	g_level=_level;
	m_type=_type;
	m_hWnd=_hWnd;
	m_pD3DDevice=pD3DDevice;
	m_sound=_sound;
	m_sound2=_sound2;
	RandMap(_row);
	if(FAILED(m_sound->Load("sou\\bottom.wav")))return false;
	if(FAILED(m_sound2->Load("sou\\xiao.wav")))return false;
	for(int i=0;i<9;i++)
	{
		m_tile[i]=new CCuboid(m_pD3DDevice);
		m_tile[i]->SetSize(10.0,10.0,10.0);
		char filename[50];
		wsprintf(filename,"tex\\wood%d.jpg",i);
		m_tile[i]->SetTexture(filename);
	}	
    SetTimer(m_hWnd,1,m_speed,TimerProc);
	SetTimer(m_hWnd,2,m_speed,TimerProc);
	m_level=AddLevel();
	return true;
	
}
/********************************************************************
函数名  : Render
输入参数: 无
输出参数: 无
功能描述:
         渲染
全局变量: 无
调用模块: 无
********************************************************************/
void CMAP::Render()
{
	for(int i=0;i<20;i++)
		for(int j=0;j<10;j++)
		{
			if(m_map[i][j]==1)
			{
				D3DXMATRIX matWorld;
				D3DXMatrixIdentity(&matWorld);
				if(m_type==2)
				{
					D3DXMatrixTranslation(&matWorld,130+j*10,-40+(-10)*i,-5.0);
				}
				else
				{
					D3DXMatrixTranslation(&matWorld,10+j*10,-40+(-10)*i,-5.0);
				}
				m_pD3DDevice->SetTransform( D3DTS_WORLD, &matWorld);
				m_tile[8]->Render();
			}
		}
		//---------当前方块渲染------------
		if(m_type==1)
		{
			
			if(m_finish==false)
			{
				if(Isshow)
				{
					for(int i2=0;i2<4;i2++)
						for(int j2=0;j2<4;j2++)
						{
							if(m_thistile->m_struct[i2][j2]==1)
							{
								D3DXMATRIX matWorld;
								D3DXMatrixIdentity(&matWorld);
								if(g_bIsDown)
								{
								D3DXMatrixTranslation(&matWorld,10+m_x*10+j2*10,-40+(-10)*m_fy+(-10)*i2,-5.0);
								}
								else
								{
								D3DXMatrixTranslation(&matWorld,10+m_x*10+j2*10,-40+(-10)*m_y+(-10)*i2,-5.0);
								}
								m_pD3DDevice->SetTransform( D3DTS_WORLD, &matWorld);
								m_tile[m_thistile->Getstyle()-1]->Render();
							}
						}
				}
				if(Go1==true)
				{
					GoDown(m_thistile);
				}
				Go1=false;
				if(g_count==1)
				{
					if(Go3==true)
					{			
						if(m_cancon==false)
						{
							m_cancon=true;		
							Isshow=true;
							if(DoXiaoAni()==true)
							{
								Go3=false;
							}
						}
					}
				}
						if(g_bToButtom)//如果要下落至低部
						{
			              GoButtom(m_thistile);
						  g_bToButtom=false;
						}
			}
			else
			{
				GoFinish1();
			}
			
		}
		else
		{
			if(m_finish==false)
			{
				if(Isshow2)
				{
					for(int i2=0;i2<4;i2++)
						for(int j2=0;j2<4;j2++)
						{
							if(m_thistile->m_struct[i2][j2]==1)
							{
								D3DXMATRIX matWorld;
								D3DXMatrixIdentity(&matWorld);
								if(g_bIsDown2)
								{
								D3DXMatrixTranslation(&matWorld,130+m_x*10+j2*10,-40+(-10)*m_fy+(-10)*i2,-5.0);
								}
								else
								{
								D3DXMatrixTranslation(&matWorld,130+m_x*10+j2*10,-40+(-10)*m_y+(-10)*i2,-5.0);
								}
								m_pD3DDevice->SetTransform( D3DTS_WORLD, &matWorld);
								m_tile[m_thistile->Getstyle()-1]->Render();
							}
						}
				}
				if(Go2==true)
				{
					GoDown(m_thistile);
				}
				Go2=false;
				if(g_count2==1)
				{
					
					if(Go4==true)	
					{
						
						if(m_cancon==false)
						{
							m_cancon=true;
							Isshow2=true;
							if(DoXiaoAni()==true)
							{
								Go4=false;		
							}
						}
					}
				}
					   if(g_bToButtom2)//如果要下落至低部
						{
			              GoButtom(m_thistile);
						  g_bToButtom2=false;
						}
			}
			else
			{
				GoFinish2();
			}
			
		}

		
		RenderNext();
}
/********************************************************************
函数名  : RenderNext
输入参数: 无
输出参数: 无
功能描述:
         渲染一个方块
全局变量: 无
调用模块: 无
********************************************************************/
void CMAP::RenderNext()
{
	if(m_IsshowNext==true)
	{
		//---------下一个方块渲染------------
		for(int i5=0;i5<4;i5++)
			for(int j6=0;j6<4;j6++)
			{
				if(m_lasttile->m_struct[i5][j6]==1)
				{
					D3DXMATRIX matWorld2,matWorld3;
					D3DXMatrixIdentity(&matWorld3);
					D3DXMatrixRotationY( &matWorld3, timeGetTime()/1000.f );
					D3DXMatrixIdentity(&matWorld2);
					if(m_type==2)
					{
						D3DXMatrixTranslation(&matWorld2,190+j6*10,10+(-10)*i5,-5.0);
					}
					else
					{
						D3DXMatrixTranslation(&matWorld2,70+j6*10,10+(-10)*i5,-5.0);
					}
					D3DXMatrixMultiply(&matWorld3,&matWorld3,&matWorld2);
					m_pD3DDevice->SetTransform( D3DTS_WORLD, &matWorld3);
					m_tile[m_lasttile->Getstyle()-1]->Render();
				}
			}
	}
}
/********************************************************************
函数名  : RandMap
输入参数: _row 行数
输出参数: 无
功能描述:
         随机生成地图
全局变量: 无
调用模块: 无
********************************************************************/
void CMAP::RandMap(int _row)
{
	m_nowrow=_row;
	for(int i=0;i<_row;i++)
	{
		for(int j=0;j<10;j++)
		{
			srand(timeGetTime());
			::_sleep(20);
			if(rand()%4==1)
			{
				m_map[19-i][j]=1;
			}
		}
		if(m_map[19-i][0]==m_map[19-i][1])
		{
			m_map[19-i][rand()%9]=1;
			m_map[19-i][rand()%9+1]=0;
		}
	}
}
/********************************************************************
函数名  : AddToMap
输入参数: _row 行数
输出参数: 无
功能描述:
         使行数增加
全局变量: 无
调用模块: 无
********************************************************************/
void CMAP::AddToMap(int _row)
{
	for(int count=0;count<_row;count++)
	{
		for(int i=0;i<19;i++)
		{
			for(int j=0;j<10;j++)
			{
				m_map[i][j]=m_map[i+1][j];
			}
		}
	}
	for(int i2=0;i2<_row;i2++)
		for(int j2=0;j2<10;j2++)
		{
			m_map[19-i2][j2]=0;
		}
		//-------机率问题---------
		for(int i3=0;i3<_row;i3++)
		{
			for(int j3=0;j3<10;j3++)
			{
				srand(timeGetTime());
				::_sleep(20);
				if(rand()%4==1)
				{
					m_map[19-i3][j3]=1;
				}
			}
			if(m_map[19-i3][0]==m_map[19-i3][1])
			{
				m_map[19-i3][rand()%9]=1;
				m_map[19-i3][rand()%9+1]=0;
			}
		}
}
/********************************************************************
函数名  : IsAttack
输入参数: _tile为方块
输出参数: 无
功能描述:
         判断碰撞
全局变量: 无
调用模块: 无
********************************************************************/
bool CMAP::IsAttack(CELSTILE *_tile)
{
    for(int i=0;i<4;i++)
		for(int j=0;j<4;j++)
		{
			if(_tile->m_struct[i][j]==1)
			{
				if(m_y+i==19)return true;
				if(m_map[m_y+i+1][m_x+j]==1)
					return true;
			}
		}
		return false;
}
/********************************************************************
函数名  : GoDown
输入参数: _tile为方块
输出参数: 无
功能描述:
         下落
全局变量: 无
调用模块: 无
********************************************************************/
void CMAP::GoDown(CELSTILE *_tile)
{
	if(false==IsAttack(_tile))
	{
        m_y++;
	}
	else
	{
		DoAttack(_tile);	
	}
}
/********************************************************************
函数名  : GoButtom
输入参数: _tile为方块
输出参数: 无
功能描述:
         下落至低部
全局变量: 无
调用模块: 无
********************************************************************/
void CMAP::GoButtom(CELSTILE *_tile)
{   
	static float addspeed=0.3;
	
	if(false==IsAttack(_tile))
	{
		addspeed+=0.02;
        m_fy+=addspeed;	
		m_y=(int)m_fy;
	}
	else
	{
		DoAttack(_tile);	
		if(m_type==1)
		{
		KillTimer(m_hWnd,11);
		g_bIsDown=false;
		addspeed=0.3;
		}
		else
		{
        KillTimer(m_hWnd,12);
		g_bIsDown2=false;
		addspeed=0.3;
		}
	}	
}

/********************************************************************
函数名  : StartGoButtom
输入参数: _tile为方块
输出参数: 无
功能描述:
         开始下落至低部
全局变量: 无
调用模块: 无
********************************************************************/
void CMAP::StartGoButtom()
{
		if(m_type==1)
		{
	SetTimer(m_hWnd,11,1,TimerProc);
	g_bIsDown=true;
		}
		else
        {
	SetTimer(m_hWnd,12,1,TimerProc);
	g_bIsDown2=true;
		}
		m_fy=(float)m_y;
}
/********************************************************************
函数名  : 构造函数
输入参数: 无
输出参数: 无
功能描述:
         初始化
全局变量: 无
调用模块: 无
********************************************************************/
CMAP::CMAP()
{
	m_x=3;
	m_y=0;
    m_score=0;//分数
    m_level=1;//级别
	m_speed=2000;//速度
	m_finish=false;//是否结束
	m_Isdown=false;//是否在下落
	m_cancon=true;
}
 /********************************************************************
函数名  : 析构函数
输入参数: 
输出参数: 
功能描述:
       删除指针并释放变量
全局变量: 无
调用模块: 无
********************************************************************/
CMAP::~CMAP()
{
	for(int i=0;i<9;i++)
		SAFE_DELETE(m_tile[i]);
}
/********************************************************************
函数名  : CleanUp
输入参数: 无
输出参数: 无
功能描述:
        删除指针并释放变量
全局变量: 无
调用模块: 无
********************************************************************/
void CMAP::CleanMap()
{
	for(int i=0;i<20;i++)
		for(int j=0;j<10;j++)
		{
			m_map[i][j]=0;
		}
}
/********************************************************************
函数名  : AddLevel
输入参数: 无
输出参数: 无
功能描述:
         等级判断
全局变量: 无
调用模块: 无
********************************************************************/
int CMAP::AddLevel()
{
	if(m_score>=LEV10)
	{
		return g_level+9;
	}
	if(m_score>=LEV9)
	{
		return g_level+8;
	}
	if(m_score>=LEV8)
	{
		return g_level+7;
	}
	if(m_score>=LEV7)
	{
		return g_level+6;
	}
	if(m_score>=LEV6)
	{
		return g_level+5;
	}
	if(m_score>=LEV5)
	{
		return g_level+4;
	}
	if(m_score>=LEV4)

⌨️ 快捷键说明

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