📄 ctilemap.cpp
字号:
/*
============================================================================
* Name : CTileMap.cpp
* Part of : 2DExample
* Description : Implementation of CTileMap
* Copyright (c) 2007 Nokia Corporation
============================================================================
*/
// INCLUDE FILES
#include "CTileMap.h"
#include "CChrMonster.h"
#include "CSprite.h"
const TInt KEmptyTile = 1;
CTileMap* CTileMap::NewL( CBitmap* aBitmap, TSize aSize, const TUint8* aMap, MSystem* aSystem )
{
CTileMap* self = new( ELeave )CTileMap( aBitmap, aSize, aMap,/* aGlobal, */ aSystem );
CleanupStack::PushL( self );
self->ConstructL();
CleanupStack::Pop( self );
return self;
}
CTileMap::~CTileMap()
{
}
CTileMap::CTileMap( CBitmap* aBitmap, TSize aSize, const TUint8* aMap, MSystem* aSystem )
: iBitmap( aBitmap )
, iSize( aSize )
, iSystem( aSystem )
{
iMap[ 0 ] = aMap;
iMap[ 1 ] = iMap[ 0 ] + iSize.iWidth * iSize.iHeight;
iMap[ 2 ] = iMap[ 1 ] + iSize.iWidth * iSize.iHeight;
}
void CTileMap::ConstructL()
{
}
void CTileMap::Draw( CBitmap& aTarget, const TPoint& aCamera )
{
TInt x,y;
TInt i;
for( i=1; i>=0; i-- )
{
for( y = 0; y<22;y++ )
{
for( x = 0; x<255; x++ )
{
TInt tile = iMap[ i ][ x + y * iSize.iWidth ];
if( tile == 1 ) continue;
iBitmap->SetDrawRect( TRect( 0+(tile*8),0, 8+(tile*8), 8 ) );
iBitmap->Draw( aTarget, TPoint( x*8, y*8 ) - aCamera );
}
}
}
}
TInt CTileMap::Tile( const TPoint& aPixel, TInt aLayer )
{
TInt x = aPixel.iX / 8;
TInt y = aPixel.iY / 8;
if( x>=0 && y>=0 && x<iSize.iWidth && y<iSize.iHeight )
{
return iMap[ aLayer ][ x + y * iSize.iWidth ];
}
return KEmptyTile;
}
// End of file
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -