?? level.h
字號:
/*
* ==============================================================================
* Name : Level.h
* Part of : RGA Game Example
* Interface :
* Description : game level
* 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 __LEVEL_H__
#define __LEVEL_H__
#include "ExampleApplication.h"
#include "Tree.h"
#include "Sprite.h"
#include "RotatingSprite.h"
#include <lights.h> // rga
// forward declarations
class CPlayer;
class CGhost;
class CLevelParser;
/**
* MapBlock
* structure hold information of single map block
* bitmaps are not owned by level
*/
struct TMapBlock
{
TInt iID;
IBitmap* iBitmap;
};
enum ELevelState
{
ELevelStateRunning = 0,
ELevelStateStarting,
ELevelStateGameOver,
ELevelStateComplete
};
class CLevel : public CBase
{
public:
CLevel(CExampleApplication& aApp);
virtual ~CLevel();
/**
* Init
* initialise level from given level file
* @param aFilename level filename
* @return KErrNone if successfull
*/
TInt Init(const TDesC& aFilename, TReal64 aTotalMoney);
/**
* Update
* Update level objects, sprites
* @param aFrametime frame time in seconds
* @return game running:EAppUpdateStateContinue
* game over: EAppUpdateStateInitMenu
* game over & new high score: EAppUpdateStateInitNewHighScore
* level complete: EAppUpdateStateInitGame
*/
EAppUpdateState Update(const TReal64 aFrametime);
/**
* Draw
* draw the level map and extra objects like trees
* grass and buildings
* @param aContext graphics context to draw to
*/
void Draw(IGraphicsContext& aContext);
/**
* SizeInPixels
* @return map size in pixels
*/
TSize SizeInPixels() const;
/**
* SizeInBlocks
* @return map size in blocks
*/
TSize SizeInBlocks() const;
/**
* IdFromCoordinate
* @param aCoordinate pixel coordinate on level
* @return block id at given pixel coordinate, or -1 if
* coordinate is out of map
*/
TInt IdFromCoordinate(const TPoint& aCoordinate);
/**
* BlockIndicesFromCoordinate
* @param aCoordinate pixel coordinate on level
* @return block map indices on given pixel coordinate, or -1,-1 if out of map
*/
TPoint BlockIndicesFromCoordinate(const TPoint& aCoordinate);
/**
* SpriteBlock
* compute block where sprite is at
* @param aSprite
* @return block map indices on given pixel coordinate, or -1,-1 if out of map
*/
TPoint SpriteBlock(CSpriteBase& aSprite);
/**
* CheckCameraLimits
* check that camera is within the limits of level
* camera position is changed if necessary.
*/
void CheckCameraLimits();
/**
* LevelState
* @return current state of the level
*/
ELevelState LevelState() const;
/**
* RemainingMoney
* @return amount of money currently left
*/
TReal64 RemainingMoney() const;
/**
* KeyDown
* This handler is called by the game state to pass keypresses to level
* @param aKeyCode RGA input key code of the pressed key
*/
void KeyDown(TUint32 aKeyCode);
private: // new functions
/**
* UpdateGame
* update game when its running normally
* @param aFrametime frametime of the application
*/
void UpdateGame(TReal64 aFrametime);
/**
* DrawRadar
* draw the level radar to application back buffer
* @param aRect rectangle to draw radar to
*/
void DrawRadar(const TRect& aRect);
/**
* UpdateInfoAreaText
* @param aLevelMoney amount of level money to print
* @param aTotalMoney amount of total money to print
*/
void UpdateInfoAreaText(const TReal64 aLevelMoney,
const TReal64 aTotalMoney);
/**
* CreateTreeLayers
* create rotated layers for trees
* these layers are shared with all trees on
* the level
* @param aNumLayers number of layers to create
* @param aBitmap tree image
* @param aMask tree alpha mask
* @param aHeight total height of the layers. This value is
* divided to the layers evenly. More height
* layer has, more perspective effect is
* used when drawing
* @param aLayerArray pointer to array that stores the layer
* @return KErrNone if successful
*/
TInt CreateTreeLayers( const TInt aNumLayers,
IBitmap* aBitmap,
IBitmap* aMask,
const TReal64 aHeight,
RArray<TTreeLayer>* aLayerArray);
/**
* ReleaseTreeLayers
* release layer data allocated in CreateTreeLayers function
* @param aLayerArray pointer to array which data is released
*/
void ReleaseTreeLayers(RArray<TTreeLayer>& aLayerArray);
/**
* DeleteSpriteArray
* @param aArray sprite array to delete
*/
void DeleteSpriteArray(RArray<CSpriteBase*>& aArray);
/**
* AddBush
* add new bush sprite to specified position on level
* @param aPos position of the sprite
*/
void AddBush(const TPoint& aPos);
/**
* AddTree
* add new tree to specified position on level
* @param aPos center position of the tree
* @param aLayerArray pointer to array where to get tree layers
*/
void AddTree(const TPoint& aPos, RArray<TTreeLayer>* aLayerArray);
/**
* AddGhost
* create new ghost and add to sprite list
* @param aStartPos starting position of the ghost
* @param aEndPos 'move-to' position of the ghost
* @param aExtraParam ghost specific value
* @param aBitmapIndex type of the ghost
*/
void AddGhost( const TPoint& aStartPos,
const TPoint& aEndPos,
const TInt aExtraParam,
const TInt aBitmapIndex);
/**
* AddBonus
* add bonus items to level
* @param aPos position of the bonus
* @param aBitmapIndex type of the bonus
* @param aId bonus identifier
*/
void AddBonus( const TPoint& aPos,
const TInt aBitmapIndex,
const TUint32 aId);
/**
* LoadCoordinate
* load coordinate from level file
* @param aParser level parser object
* @return block coordinate
*/
TPoint LoadCoordinate(CLevelParser& aParser);
/**
* LoadPixelCoordinate
* load pixel coordinate from level file
* @param aParser level parser object
* @return coordinate
*/
TPoint LoadPixelCoordinate(CLevelParser& aParser);
/**
* BlinkBacklight
* set backlight blinking if not blinking already
*/
void BlinkBacklight();
private: // data
CExampleApplication& iApp;
TSize iBackBufferSize;
TInt iMapWidth;
TInt iMapHeight;
TMapBlock* iBlocks;
TVector2 iCamera;
TReal64 iWaterAnimationPhase;
CPlayer* iPlayer;
TPoint iGoalBlock;
TReal64 iRemainingMoney;
TReal64 iMoneyWasteSpeed;
TReal64 iTotalMoney;
TReal64 iTempRemainingMoney;
HBufC* iLevelName;
RArray<CSpriteBase*> iSprites;
RArray<CSpriteBase*> iGhosts;
RArray<CSpriteBase*> iBonuses;
RArray<CSpriteBase*> iTrees;
RArray<TTreeLayer> iTree01Layers;
RArray<TTreeLayer> iTree02Layers;
IBitmap* iTextBuffer;
IGraphicsContext* iTextBufferContext;
TReal64 iInfoAreaUpdateTimer;
ELevelState iLevelState;
TReal64 iStateTimer;
TUint32 iCurrentBonus;
TReal64 iBonusTimer;
ILight* iBackLight;
TReal64 iBlinkInterval;
TInt iBlinkCount;
TBool iShowFPS;
CSettings* iSettings;
};
#endif /*__LEVEL_H__*/
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -