cmap.cpp
来自「symbian 的一个 二维飞行游戏 源码 及相关技术文章」· C++ 代码 · 共 172 行
CPP
172 行
// Copyright 2002 Kenneth Guy,
//
// CMap.cpp
/** \file CMap.cpp
implementation of class CMap */
#include "CMap.h"
#include "CGame.h"
#include <e32svr.h>
#include <e32base.h>
#include "TMapLineType.h"
/** Constructor
see CMap::NewL() for parameters */
CMap::CMap(CGame &aGame,const TUint16* aMapSprites,const TInt16* aMapData)
: iMapData(aMapData), iMapSprites(aMapSprites), iGame(aGame) {
};
/** Leave safe construction.
\param aGame where to add bad guys
\param aMapSprites background sprites each 64x50 pixels
\param aMapData lines of map data, see enum TMapLineType
*/
CMap* CMap::NewL(CGame &aGame,const TUint16* aMapSprites,
const TInt16* aMapData) {
CMap* self= new (ELeave) CMap(aGame,aMapSprites,aMapData);
CleanupStack::PushL(self);
self->ConstructL();
CleanupStack::Pop(self);
return(self);
}
/** 2nd phase Constuctor
Get the screen base from RScreenUtils. Allocate the offscreen
map and plot the first 11 lines of the background.
*/
void CMap::ConstructL() {
// get the base address of screen memory
RScreenUtils screen;
User::LeaveIfError(screen.Open());
iScreenBase=screen.ScreenBase();
screen.Close();
// offscreen map,
// longer than the screen so we can scroll one set of map sprites
// off while the next is scrolling on, also space above and bellow
// so that we can move sprites on and off
iOffScreenMap=new (ELeave) TUint16[(11*64)*248];
for(TInt i=0;i<(11*64)*248;i++)
iOffScreenMap[i]=0x0000;
iDrawArea=iOffScreenMap+((11*64)*24);
// Point at which to draw the next line of map sprites
iMapDrawPoint=iDrawArea;
// where to start copying to the screen
iBlitStart=iDrawArea;
// end of the draw area,
iDrawEnd=iDrawArea+((11*64)*224);
// keeps track of when we need to plot a new line of map sprites
iBlitPoint=0;
// draw first screen full of map
for(TInt i=0;i<11;i++)
ProcessMapLine();
}
/** destructor */
CMap::~CMap() {
delete [] iOffScreenMap;
}
/** What will be copied to top left of visible screen */
TUint16* CMap::BlitStart() {
return iBlitStart;
}
/** The end of the offscreen map */
TUint16* CMap::DrawEnd() {
return iDrawEnd;
}
/** Have we got to the end of the map data. */
TBool CMap::Finished() {
return iFinished;
}
/** Scroll map.
Scrolls the map by first adding 4 pixels to the point at which we
copy to the screen. Then it checks if we need to plot a new row
of map sprites (may sprite is 64 pixels wide so every 16 times
round we will need to), if so it calls ProcessMapLine() to plot
the sprites and add any bad guys.
Unless we have hit the end of the map, then do nothing.
*/
void CMap::ScrollMap() {
if(!(iMapData[0] & EMapLineEndOfMap)) {
iBlitStart+=4;
if(iBlitStart >= iDrawEnd)
iBlitStart=iDrawArea;
// every 16*4 pixels (a map sprite is 64 pixels wide), we need to plot
// another line of map sprites
iBlitPoint++;
if(iBlitPoint>=16) {
iBlitPoint=0;
ProcessMapLine();
}
} else {
// scroll last line of sprites all the way onto the screen.
if(iBlitPoint <24) {
iBlitPoint++;
iBlitStart+=4;
if(iBlitStart >= iDrawEnd)
iBlitStart=iDrawArea;
} else {
iFinished=ETrue;
}
}
};
/** Process a line of map data.
Map data consits of one row of background sprites, and then zero
or more bad guys to add. see enum TMapDataLine for more information.
Leaves the iMapData pointing to the next line of background sprites.
*/
void CMap::ProcessMapLine() {
PlotMapLineAsm();
while(iMapData[0] & EMapLineObject) {
iGame.AddBadGuy(iMapData[0],iMapData+1);
iMapData+=8;
}
}
/** @fn void CMap::BlitAsm()
Copy the offscreen map to the screen.
Copies from iBlitStart to the screen, will wrap when it reaches iDrawEnd
*/
/** @fn void CMap::PlotMapLineAsm()
Plot the next line of map sprites.
This plots the next vertical line of four map sprites to the offscreen
map.
*/
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?