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

📄 exampleapplication.h

📁 RGA: Biowaste Game Example This C++ application demonstrates how to create a 2D mobile game for S60
💻 H
字号:
/*
* ==============================================================================
*  Name        : ExampleApplication.h
*  Part of     : RGA Game Example
*  Interface   :
*  Description : RGA example application class
*  Version     : 1.0
*
*  Copyright (c) 2007-2008 Nokia Corporation.
*  This material, including documentation and any related
*  computer programs, is protected by copyright controlled by
*  Nokia Corporation.
* ==============================================================================
*/

#ifndef __EXAMPLEAPPLICATION_H__
#define __EXAMPLEAPPLICATION_H__

#include "ApplicationBase.h"
#include "AppState.h"
#include "HighScores.h"
#include "Settings.h"
#include "RGAExampleConstants.h"
#include "Texts.h"

#include <highlevelaudio.h>		//rga

// for asking if device is in silent mode
#include <centralrepository.h>
#include <ProfileEngineSDKCRKeys.h>


class CExampleApplication :	public CApplicationBase,
							public IAudioObjectObserver
	{
	public:
		CExampleApplication();
		virtual ~CExampleApplication();

		/**
		 * InitResources
		 * load application graphics and audio files
		 * This function is called by intro state after
		 * it has displayed the 'Loading...' text
		 * @return KErrNone or an error code
		 */
		TInt InitResources();

		/**
		 * Bitmap
		 * @param aBitmapId Id from RGAExampleConstants.h
		 * @return pointer to game bitmap
		 */
		IBitmap* Bitmap(TUint aBitmapId);
		
		/**
		 * Mask
		 * @param aBitmapId Id from RGAExampleConstants.h
		 * @return pointer to game bitmap mask, or NULL if not created
		 */
		IBitmap* Mask(TUint aBitmapId);

		
		/**
		 * NormalFont
		 * @return game normal font
		 */
		const CFont* NormalFont() const;
		
		/**
		 * BigFont
		 * @return game big font
		 */
		const CFont* BigFont() const;
		
		/**
		 * SmallFont
		 * @return game small font
		 */
		const CFont* SmallFont() const;
		
		/**
		 * HighScores
		 * @return pointer to high scores table
		 */
		CHighScores* HighScores();
		
		/**
		 * Settings
		 * @return pointer to application settings
		 */
		CSettings* Settings();
		
		/**
		 * SetLastGameScore
		 * function stores the score from last game played
		 * this way it can be passed to new high score state
		 * @param aScore score of the last game
		 */
		void SetLastGameScore(const TReal64 aScore);
		
		/**
		 * LastGameScore
		 * @return score of the last game played
		 */
		TReal64 LastGameScore();
		
		/**
		 * SetInfoAreaText
		 * set text to info area
		 * @param aText text to display
		 * @param aPriorityMsg if ETrue, message is shown for
		 * 		10 seconds and no other than another priority message is shown
		 */
		void SetInfoAreaText(const TDesC& aText, TBool aPriorityMsg);
		
		/**
		 * DrawTextToBitmap
		 * draw text into the bitmap
		 * @param aBitmap bitmap to draw into
		 * @param aContext graphics context associated with aBitmap
		 * @param aText text to draw
		 * @param aFont font to use
		 * @param aColor color to use
		 * @return KErrNone or error code
		 */
		TInt DrawTextToBitmap(	IBitmap* aBitmap,
								IGraphicsContext* aContext,
								const TDesC& aText,
								const CFont* aFont,
								TRgb aColor);
		
		
		/**
		 * BlendRect
		 * blend a rectangle on backbuffer using 50% alpha
		 * @param aRect rectangle to blend
		 */
		void BlendRect(const TRect& aRect);

		

		/**
		 * PlayAudio
		 * @param aIndex index of audio buffer (from RGAExampleConstants.h)
		 * @param aLoop play in infinite loop
		 */
		void PlayAudio(TInt aIndex, TBool aLoop = EFalse);
		
		/**
		 * RePlayAudio
		 * set position of the buffer to 0 and play
		 * @param aIndex index of audio buffer (from RGAExampleConstants.h)
		 */
		void RePlayAudio(TInt aIndex);

		/**
		 * StopAudio
		 * stop audio playback
		 * @param aIndex index of audio buffer (from RGAExampleConstants.h)
		 */
		void StopAudio(TInt aIndex);
		
		/**
		 * SetAudioVolume
		 * @param aIndex index of audio buffer (from RGAExampleConstants.h)
		 * @param aVolume volume to set 0-100
		 */
		void SetAudioVolume(TInt aIndex, TInt aVolume);
		
		/**
		 * SetMasterVolume
		 * @param aVolume volume to set (0-100)
		 */
		void SetMasterVolume(TInt aVolume);
		
		/**
		 * MasterVolume
		 * @return current master volume (0-100)
		 */
		TInt MasterVolume() const;
		
		/**
		 * AudioEnabled
		 * @return ETrue if audio is enabled, EFalse otherwise
		 */
		TBool AudioEnabled() const;
		
		
	private:	// from CApplicationBase
		virtual TInt OnInitialize();
		virtual void OnClose();
		virtual void OnDraw(IGraphicsContext& aContext);
	
	private:	// from IApplicationStateObserver 
		virtual void FocusGained() NO_THROW;


	private:	// from IInputDeviceObserver
		virtual void InputKeyPressed(	IInputDevice& aDevice,
										uint64 aTimeStamp,
										uint32 aKeyCode ) NO_THROW;
		
	private:	// from IDisplayObserver
	    virtual void DisplayOrientationChanged(
	                                    uint32 aDisplayIndex,
	                                    GraphicsOrientationType aType,
	                                    GraphicsOrientationAngle aAngle ) NO_THROW;
	    
	private:	// from IAlarmObserver
		virtual void AlarmOccurence( AlarmType aType ) NO_THROW;
	    
	private:	// from ITelephonyObserver
	    virtual void IncomingCall() NO_THROW;
	    virtual void IncomingMessage( MessageType aMessage ) NO_THROW;


	private:	// from IAudioObjectObserver
        virtual void HandleAudioObjectStatus( IAudioObject& aAudioObject,
                                              const AudioObjectStatus aStatus,
                                              const uint32 aLoopCount ) NO_THROW;
        virtual void InitializeComplete( IAudioObject& aAudioObject,
                                         ReturnCode aReturnCode ) NO_THROW;
	    
		
	private:	// new functions
		/**
		 * LoadGraphicsL
		 * load graphics files
		 * @return KErrNone or error
		 */
		TInt LoadGraphicsL();
		
		/**
		 * LoadBitmapAndMask
		 * load single bitmap and its mask
		 * @param aId id of the bitmap
		 * @param aFilename file to load
		 * @param aAlphaBits number of bits to use with alpha mask, or 0 to disable alpha
		 * @return KErrNone or error
		 */
		TInt LoadBitmapAndMask(TUint aId, const TDesC& aFilename, TInt aAlphaBits);
		
		/**
		 * InitAudio
		 * initialise audio playback and load audio clips
		 * @return KErrNone or error
		 */
		TInt InitAudio();
		
		/**
		 * ChangeAppStateL
		 * change application state
		 * @param aState new state identifier
		 * @return KErrNone or error
		 */
		TInt ChangeAppStateL(EAppUpdateState aState);
		
		/**
		 * DrawInfoArea
		 * draw information area to the bottom of the screen
		 * @param aContext context to draw infoarea into
		 */
		void DrawInfoArea(IGraphicsContext& aContext);
		
		
	private:	// Data
		CAppState*				iState;
		
		RArray<IBitmap*>		iBitmaps;
		RArray<IBitmap*>		iMasks;
		
		CFont*					iNormalFont;
		CFont*					iBigFont;
		CFont*					iSmallFont;
		
		CHighScores*			iHighScores;
		TReal64					iLastGameScore;
		
		CSettings*				iSettings;
		
		IBitmap*				iInfoAreaBuffer;
		IGraphicsContext*		iInfoAreaBufferContext;
		TReal64					iInfoAreaPriorityMsgTimer;
		
		// audio members
		IAudioMixer*			iAudioMixer;
        IAudioData*				iAudioData[KAudioNumFiles];
        IAudioSound*			iAudioSound[KAudioNumFiles];
        CRepository*			iRepository;	// for checking silent mode
        TBool					iAudioEnabled;
	};

#endif /* __EXAMPLEAPPLICATION_H__ */


⌨️ 快捷键说明

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