www.pudn.com > Example2D.rar > CTileMap.cpp


/* 
* ============================================================================ 
*  Name     : CTileMap from CTileMap.h 
*  Part of  : 2DExample 
*  Created  : 01/01/2005 by Forum Nokia 
*  Version  : 1.0 
*  Copyright: 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