📄 gamemap.cpp
字号:
// GameMap.cpp: implementation of the CGameMap class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "GameMap.h"
#include "MainGame.h"
#include <fstream.h>
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CGameMap::CGameMap(int level):CContainerObject(this)
{
////////////////////////////////////////
LevelMap[0]="level\\level0.dat";
LevelMap[1]="level\\level1.dat";
LevelMap[2]="level\\level2.dat";
LevelMap[3]="level\\level3.dat";
LevelMap[4]="level\\level4.dat";
LevelMap[5]="level\\level5.dat";
LevelMap[6]="level\\level6.dat";
LevelMap[7]="level\\level7.dat";
LevelMap[8]="level\\level8.dat";
LevelMap[9]="level\\level9.dat";
LevelMap[10]="level\\level10.dat";
LevelMap[11]="level\\level11.dat";
LevelMap[12]="level\\level12.dat";
//////////////////////////////////////////
this->level=level;
ReadGameMap();
ChangeGameMap();
strcpy(name,"Gamemap");
fugai=1;
}
CGameMap::~CGameMap()
{
}
void CGameMap::ReadGameMap()
{
ifstream fin(LevelMap[level]);
for(int i=0;i<15;i++)
for(int j=0;j<20;j++)
fin>>Map[i][j];
return; //图通过调文件
}
void CGameMap::ChangeGameMap()
{
int i,j,m,n;
for(i=0;i<15;i++)
for(j=0;j<20;j++)
{
for(m=0;m<4;m++)
for(n=0;n<4;n++)
GameMap[m+4*i][n+4*j]=Map[i][j];
}
//////////////////////////////
for(i=13*4;i<13*4+2;i++)
for(j=9*4;j<11*4;j++)GameMap[i][j]=0;
for(i=14*4;i<15*4;i++)
for(j=9*4+2;j<11*4-2;j++)GameMap[i][j]=5;
///////////////////////////////
return;
}
void CGameMap::DrawGroundMap()
{
int i,j,pos;
CMainGame *pWnd=(CMainGame*)AfxGetMainWnd();
for(i=0;i<15;i++)
for(j=0;j<20;j++)
{
switch(Map[i][j])
{
case 0: pos=0; break;
case 1: pos=1; break;
case 2: pos=2; break;
case 3: pos=3; break;
case 4: pos=4; break;
case 5: pos=5; break;
case 6: pos=6; break;
}//注意:画图时px转化成的是纵坐标
CRect rt1(32*j,32*i,32*(j+1),32*(i+1));
CRect rt2(pos*32,0,(pos+1)*32,32);
pWnd->BltBitMap(pWnd->lpBackBuffer,rt1,pWnd->lpBKGObject[3],rt2);
}//for
CRect rt1(32*9+16,32*14,32*(10)+16,32*15);
CRect rt2(5*32,0,(5+1)*32,32);
pWnd->BltBitMap(pWnd->lpBackBuffer,rt1,pWnd->lpBKGObject[3],rt2);
return;
}
void CGameMap::DrawGrass()
{
CMainGame *pWnd=(CMainGame*)AfxGetMainWnd();
for(int i=0;i<15;i++)
for(int j=0;j<20;j++)
if(Map[i][j]==2)
{
CRect rt1(32*j,32*i,32*(j+1),32*(i+1));
CRect rt2(2*32,0,3*32,32);
pWnd->BltBitMap(pWnd->lpBackBuffer,rt1,pWnd->lpBKGObject[3],rt2);
}
return;
}
void CGameMap::FuGaiMap()
{
int i,j,m,n;
CMainGame *pWnd=(CMainGame*)AfxGetMainWnd();
for(i=0;i<15;i++)
for(j=0;j<20;j++)
{
if(Map[i][j]==3 || Map[i][j]==1)
{
for(m=0;m<4;m++)
for(n=0;n<4;n++)
if(GameMap[m+4*i][n+4*j]==0)
{
CRect rt1(8*(n+4*j),8*(m+4*i),8*(n+4*j+1),8*(m+4*i+1));
CRect rt2(0,0,32,32);
pWnd->BltBitMap(pWnd->lpBackBuffer,rt1,pWnd->lpBKGObject[3],rt2);
}//if
}//if
}//for
return;
}
void CGameMap::GetDefend(int n)
{
int i,j;
Map[13][9]=Map[13][10]=Map[14][9]=Map[14][10]=n;
for(i=13*4+2;i<15*4;i++)
for(j=9*4;j<11*4;j++)GameMap[i][j]=n;
for(i=14*4;i<15*4;i++)
for(j=9*4+2;j<11*4-2;j++)GameMap[i][j]=5;
}
void CGameMap::displayObject()
{
//////画地图
DrawGroundMap();
FuGaiMap();
if(fugai==0)
{
CMainGame *pWnd=(CMainGame*)AfxGetMainWnd();
CRect rt1(32*9+16,32*14,32*(10)+16,32*15);
CRect rt2(6*32,0,(6+1)*32,32);
pWnd->BltBitMap(pWnd->lpBackBuffer,rt1,pWnd->lpBKGObject[3],rt2);
}
}
bool CGameMap::ActiveObject()
{
displayObject();
return true;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -