📄 mopoidgameengine.h
字号:
/*
========================================================================
Name : MopoidGameEngine.h
Author :
Copyright :
Description : The game-engine. Handles control of the gameflow.
License :
========================================================================
*/
#ifndef MOPOIDGAMEENGINE_H
#define MOPOIDGAMEENGINE_H
#include <e32std.h>
#include <e32base.h>
#include <e32math.h>
// TODO: Add include file for file operations
#include <s32file.h>
#include <Mopoid.rsg>
#include "MopoidContainer.h"
#include "MopoidSharedData.h"
#include "MopoidPanel.h"
#include "MopoidBall.h"
#include "MopoidGrid.h"
#include "SpriteHandler.h"
#include "KeyHandler.h"
#include "MopoidLevels.h"
#include "MopoidSettings.h"
#include "SoundManager.h"
#include "CommonFunctions.h"
#define DELETE_AND_NULL(p) {delete p; p = NULL;}
#define MOPOID_FILE_VERSION_NUMBER 1
_LIT(KMopoidDataFile, "settings.dat");
// Forward declarations
class CMopoidContainer;
// Class declaration
/**
* Takes care of the actual game. Manages the updates of the objects and the
* backbuffer bitmap.
*/
class CMopoidGameEngine : public CBase
{
public:
enum TMopoidSounds
{ESoundHit = 0, ESoundBounce, ENumSounds};
// -----------------------------------------------------------------------
// Creates a CMopoidGameEngine object
// -----------------------------------------------------------------------
static CMopoidGameEngine * NewL(CMopoidContainer* aOwningControl);
// -----------------------------------------------------------------------
// Creates a CMopoidGameEngine object
// -----------------------------------------------------------------------
static CMopoidGameEngine * NewLC(CMopoidContainer* aOwningControl);
// -----------------------------------------------------------------------
// Destroys Engine
// -----------------------------------------------------------------------
~CMopoidGameEngine();
// -----------------------------------------------------------------------
// Performs second phase construction of this Engine
// -----------------------------------------------------------------------
void ConstructL();
public:
/**
* When the screen size is set or changed, this method should
* be called so that the back buffer can be created in the
* correct size and the draw rectangle can be calculated based
* on this.
*/
void SetScreenSize(const TSize& aNewSize);
/**
* Update the back buffer with the current game data.
*/
void DrawFrame() const;
/**
* Resets ball, panel and player data and updates the back buffer.
*/
void StartNewGameL();
/**
* Pauses the current game.
*/
void PauseGame();
/**
* Resumes a paused game.
*/
void ResumeGameL();
/**
* Save the current highscore to a file.
*/
void SaveGameProgressL();
TBool IsSoundOn();
/**
* Modify the volume
*/
void SetSoundLevelL(TBool aOnOff);
private:
CMopoidGameEngine(CMopoidContainer* aOwningControl);
/**
* Delete the back buffer bitmap and its other cached objects (context, device).
*/
void DeleteBackBuffer();
/**
* Create a back buffer bitmap (and context + device) with the specified size.
*/
void CreateBackBufferL(const TSize& aSize);
/**
* Load sound files into the sound manager class.
*/
void LoadSoundsL();
/**
* Set ball and panel to their initial centered positions.
*/
void ResetBallAndPanel();
/**
* Does all necessary steps to calculate the next frame. Includes
* updating of the back buffer.
* @return whether another game frame should be calculated or not.
* For example if the game is finished, this would be EFalse.
*/
TBool DoFrame();
/**
* Draw the ingame information text to the screen.
*/
void DrawTextL() const;
/**
* Convert a point from the virtual game coordinate system
* to the screen coordinate system.
*/
const TPoint ConvToScreenCoord(const TPoint& aGameCoord) const;
/**
* Calculate the time that has passed since the last frame.
*/
void CalcTimeDifference();
/**
* Do all necessary steps to animate the panel according to its parameters.
*/
void AnimatePanel();
/**
* Do all necessary steps to animate the ball according to its parameters.
*/
void AnimateBallL();
/**
* Start the timer when waiting for the user to return to an area or when
* searching for a new area.
*/
void StartTimerL();
/**
* Stops the timer when the search is complete or the game is exited.
*/
void StopTimer();
/**
* The timer callback function. Has to be static to be called by the active
* object of the timer.
* @param aObject this class.
* @return whether the timer should continue.
*/
static TInt TimerCallBack(TAny* aObject);
/**
* The non-static timer function that does the work.
* @return whether the timer should continue.
*/
TInt DoCallBack();
/**
* Load the highscore from a file.
*/
void LoadGameProgressL();
public:
/**
* Back buffer bitmap
*/
CFbsBitmap* iBackBufferBmp;
/**
* Stores keyboard input until it is needed.
*/
TKeyHandler iKeyHandler;
/**
* Contains settings and game data.
*/
CMopoidSettings* iSettings;
/**
* Stores if the game is currently in the foreground (if not, the game must
* not be running).
*/
TBool iHaveFocus;
private:
/**
* Pointer to the container that owns this engine.
*/
CMopoidContainer* iOwningControl;
/**
* Class that stores and manages the sprite bitmaps.
*/
CSpriteHandler* iSpriteHandler;
/**
* Responsible for loading and storing level data.
*/
TMopoidLevels iLevels;
/**
* Contains the current level layout and provides ways to access and modify it.
*/
CMopoidGrid* iGrid;
/**
* Information about the panel.
*/
TPanel iPanel;
/**
* Information abou the ball.
*/
TBall iBall;
/**
* Graphics context of back buffer bitmap
*/
CFbsBitGc* iBackBufferBmpGc;
/**
* Drawing Device of back buffer bitmap.
*/
CFbsBitmapDevice* iBackBufferBmpDrawingDevice;
/**
* Time of the last frame update. Stored to calculate the difference to the new frame time.
*/
TTime iLastFrameTime;
/**
* Time that has passed since the last update.
*/
TReal iThisFrameStep;
/**
* Time when the score was decreased the last time (e.g. every 5 seconds).
*/
TTime iLastScoreDecreaseTime;
/**
* Stores and manages sounds.
*/
CSoundManager* iSoundManager;
/**
* The periodic timer used to do the game updates,
* decrease score over time and keep backlight on.
*/
CPeriodic* iPeriodicTimer;
RFs iFs;
};
#endif // MOPOIDGAMEENGINE_H
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -