?? map.cpp
字號:
/********************************************************************
文件名: 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 + -