⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cmodeltitle.cpp

📁 基于SYMBIAN OS,series 60平台的经典游戏,超级马力
💻 CPP
字号:
/*
* ============================================================================
*  Name     : CModelTitle from CModelTitle.h
*  Part of  : 2DExample
*  Created  : 01/01/2005 by Forum Nokia
*  Version  : 1.0
*  Copyright: Nokia Corporation
* ============================================================================
*/

// INCLUDE FILES
#include "CModelTitle.h"
#include "CBitmap.h"
#include "CSprite.h"
#include "level0.h"
#include "MCharacter.h"
#include "CTileMap.h"
#include "CChrPlayer.h"
#include "CFont.h"



CModelTitle* CModelTitle::NewL( MSystem* aSystem )
	{
	CModelTitle* self = new( ELeave )CModelTitle( aSystem );
	CleanupStack::PushL( self );
	self->ConstructL();
	CleanupStack::Pop( self );
	return self;
	}



CModelTitle::~CModelTitle()
	{
	}



CModelTitle::CModelTitle( MSystem* aSystem )
	: iSystem( aSystem )
	{
	
	}



void CModelTitle::ConstructL()
	{
	iAudio = EFalse;
	}



void CModelTitle::ActivateL()
	{
	TFileName file;
	file.Copy( iSystem->Path() );
	file.Append( _L("title.mbm") );
	iBmTitle = CBitmap::NewL( file, 0 );

	file.Copy( iSystem->Path() );
	file.Append( _L("font.mbm" ) );
	iBmFont = CBitmap::NewL( file, 0 );

	iFont = CBmFont::NewL( iBmFont, iSystem );

	iBmFont->SetMaskColor( 0 );		

	iCursorPos = 0;
	}



void CModelTitle::Deactivate()
	{
	iBmTitle->Destroy();
	delete iBmTitle;
	iBmTitle = NULL;

	iBmFont->Destroy();
	delete iBmFont;
	iBmFont = NULL;

	delete iFont;
	}



void CModelTitle::Move()
	{
	}



void CModelTitle::Draw( CBitmap& aTarget )
	{	
	HandleKeys();

	TInt xPos = aTarget.Size().iWidth - 160;
	TInt yPos = aTarget.Size().iHeight - 80;

	aTarget.Clear( TRgb( 0,0,0 ) );
	
	// position title to center, if screen width > title bitmap width
	TInt xOffset = (aTarget.Size().iWidth - iBmTitle->Size().iWidth) / 2;
	if(xOffset < 0)
			xOffset = 0;
			
	iBmTitle->Draw( aTarget, TPoint( xOffset, 0 ) );

	TRect cursorRect = TRect( xPos-1, yPos+(iCursorPos*20), xPos+102, yPos+ 16 +(iCursorPos*20) );
	DrawRect( aTarget, cursorRect );

	TBuf8<16> txt;
	txt.Copy( _L( "START GAME" ) );
	iFont->DrawText ( aTarget, txt, TPoint ( xPos, yPos ) );
	txt.Copy( _L( "HELP" ) );
	iFont->DrawText ( aTarget, txt, TPoint ( xPos, yPos+20 ) );
	if( iAudio )
		{
		txt.Copy( _L( "AUDIO ON" ) );
		}
	else
		{
		txt.Copy( _L("AUDIO OFF") );
		}
	iFont->DrawText ( aTarget, txt, TPoint ( xPos, yPos+40 ) );
	txt.Copy( _L( "QUIT" ) );
	iFont->DrawText ( aTarget, txt, TPoint ( xPos, yPos+60 ) );
	}



void CModelTitle::DrawRect( CBitmap& aTarget, TRect aRect )
	{
	TRgb aRgb = TRgb( 255,0,0 );

	TInt divider;
	TUint32 longword = 0;

	switch( aTarget.Mode() )
		{
		case EColor4K:
			{
			longword = aRgb.Color4K();
			longword |= longword << 16;
			divider = 2;
			break;
			}
		case EColor64K:
			{
			longword = aRgb.Color64K();
			longword |= longword << 16;
			divider = 2;
			break;
			}
		default:
			{
			longword = aRgb.Color16M();
			divider = 1;
			break;
			}
		}

	TUint32* p = ( TUint32* )aTarget.Data();

	for( TInt x=aRect.iTl.iX; x < aRect.iBr.iX; x++ )
		{
		for( TInt y=aRect.iTl.iY; y < aRect.iBr.iY; y++ )
			{
			p[ (x + y * aTarget.Size().iWidth) / divider ] = longword;
			}
		}
	}

void CModelTitle::HandleKeys()
	{

	if( iLastKey != EStdKeyUpArrow )
		{
		if( iSystem->KeyState( EStdKeyUpArrow ) ) 
			{
			CursorUp( EStdKeyUpArrow );
			}
		}
	if( iLastKey != EStdKeyDownArrow )
		{
		if( iSystem->KeyState( EStdKeyDownArrow )  ) 
			{
			CursorDown( EStdKeyDownArrow );
			}
		}
	if( iLastKey != iSystem->SelectKey() )
		{
		if( iSystem->KeyState( iSystem->SelectKey() ) )
			{
			Fire( iSystem->SelectKey() );
			}
		}

	// Nokia 9300 / Nokia 9500 has two sets of navigation keys
	if( iLastKey != EStdKeyDevice8 )
		{
		if( iSystem->KeyState( EStdKeyDevice8 ) ) 
			{
			CursorUp( EStdKeyDevice8 );
			}
		}
	if( iLastKey != EStdKeyDevice9 )
		{
		if( iSystem->KeyState( EStdKeyDevice9 )  ) 
			{
			CursorDown( EStdKeyDevice9 );
			}
		}
	if( iLastKey != iSystem->OkKey() )
		{
		if( iSystem->KeyState( iSystem->OkKey() ) )
			{
			Fire( iSystem->OkKey() );
			}
		}

	// Reset key states if key when released
	if( ( iLastKey == EStdKeyUpArrow )  &&( !iSystem->KeyState( EStdKeyUpArrow ) ) )
		{
		iLastKey = 0;
		}
	if( ( iLastKey == EStdKeyDevice8 )  &&( !iSystem->KeyState( EStdKeyDevice8 ) ) )
		{
		iLastKey = 0;
		}
	if( ( iLastKey == EStdKeyDownArrow )  && (!iSystem->KeyState( EStdKeyDownArrow ) ) )
		{
		iLastKey = 0;
		}
	if( ( iLastKey == EStdKeyDevice9 )  && (!iSystem->KeyState( EStdKeyDevice9 ) ) )
		{
		iLastKey = 0;
		}
	if( ( iLastKey == iSystem->OkKey() )  && (!iSystem->KeyState( iSystem->OkKey() ) ) )
		{
		iLastKey = 0;
		}
	if( ( iLastKey == iSystem->SelectKey() )  && (!iSystem->KeyState( iSystem->SelectKey() ) ) )
		{
		iLastKey = 0;
		}
	}

void CModelTitle::CursorUp( TInt aLastKey )
	{
	if( iCursorPos > 0 )
		{
			iCursorPos--;
		}
	iLastKey = aLastKey;
	}

void CModelTitle::CursorDown( TInt aLastKey )
	{
	if ( iCursorPos < 3 )
		{
			iCursorPos++;
		}
	iLastKey = aLastKey;
	}

void CModelTitle::Fire( TInt aLastKey )
	{
	switch ( iCursorPos )
		{
			case 0:
				{
				iSystem->ChangeModelL( EModelGame );
				break;
				}
			case 1:
				{
				iSystem->ChangeModelL( EModelHelp );
				break;
				}
			case 2:
				{
				iSystem->ToggleAudio();
				// Toggle Audio off -> on -> off
				if( iAudio )
					{
					iAudio = EFalse;
					}
				else
					{
					iAudio = ETrue;
					}
				break;
				}
			case 3:
				{
				iSystem->PrepareExit();
				break;
				}
		}

	iLastKey = aLastKey;
	}
	
// End of file

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -