📄 mopoidgameengine.h
字号:
/*
* ============================================================================
* Name : CMopoidGameEngine from MopoidGameEngine.h
* Part of : Mopoid
* Created : 16.01.2004 by Andreas Jakl / Mopius - http://www.mopius.com/
* Description:
* The game-engine. Handles the control of the gameflow.
* Version : 1.02
* Copyright:
* 'Mopoid' is free software; you can redistribute
* it and/or modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*
* 'Mopoid' is distributed in the hope that it
* will be useful, but WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with 'Mopoid'; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
* ============================================================================
*/
// -----------------------------------------------------------------------
// Interface of CMopoidGameEngine
// -----------------------------------------------------------------------
#ifndef MOPOIDGAME_ENGINE_H
#define MOPOIDGAME_ENGINE_H
#include <e32std.h>
#include <e32base.h>
#include <e32math.h>
// TODO: Add include file for file operations
// ...
#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 "UpdateAO.h"
#include "MopoidLevels.h"
#include "MopoidSettings.h"
#include "SoundManager.h"
#define DELETE_AND_NULL(p) {delete p; p = NULL;}
#define MOPOID_FILE_VERSION_NUMBER 1
_LIT(KMopoidDataFile, "settings.dat");
// Forward declarations
class CUpdateAO;
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 MUpdateAOCallback
{
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:
/**
* Update the back buffer with the current game data.
*/
void DrawFrame() const;
/**
* Resets ball, panel and player data and updates the back buffer.
*/
void StartNewGame();
/**
* Pauses the current game.
*/
void PauseGame();
/**
* Resumes a paused game.
*/
void ResumeGameL();
/**
* Save the current highscore to a file.
*/
void SaveGameProgressL();
/**
* Modify the volume
*/
void SetSoundLevelL(TBool aOnOff);
private:
CMopoidGameEngine(CMopoidContainer* aOwningControl);
// -----------------------------------------------------------------------
// Routine that initializes components owned by this Container
// -----------------------------------------------------------------------
void InitComponentsL();
// -----------------------------------------------------------------------
// Routine that cleans up engine components owned by this Engine
// -----------------------------------------------------------------------
void CleanupComponents();
/**
* 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(void);
/**
* 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 AnimateBall();
// from MUpdateAOCallback
TBool RepeatedAction(void);
void CancelAsyncs(void);
/**
* 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.
*/
TMopoidSettings iSettings;
/**
* Stores if the game is currently in the foreground (if not, the game must
* not be running).
*/
TBool iHaveFocus;
private:
// -----------------------------------------------------------------------
//NOTE: The follwing section is managed by the IDE - DO NOT MODIFY
//IDE-MANAGED-START
/* 27.11.04 21:14 */
//IDE-MANAGED-END
// -----------------------------------------------------------------------
/**
* Pointer to the container that owns this engine.
*/
CMopoidContainer* iOwningControl;
/**
* Active object responsible for continuously calling the DoFrame()-function
* to calculate the next frame.
*/
CUpdateAO* iUpdateAO; // active object to allow regular updates
/**
* Class that stores and manages the sprite bitmaps.
*/
CSpriteHandler* iSpriteHandler;
/**
* Responsible for loading and storing level data.
*/
CMopoidLevels* iLevels;
/**
* Contains the current level layout and provides ways to access and modify it.
*/
TMopoidGrid iGrid;
/**
* Information about the panel.
*/
TPanel iPanel;
/**
* Information abou the ball.
*/
TBall iBall;
/**
* Seed for random number generator.
*/
TInt64 iRandSeed;
/**
* 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;
/**
* Stores and manages sounds.
*/
CSoundManager* iSoundManager;
/**
* The periodic timer used to decrease score over time and keep backlight on.
*/
CPeriodic* iPeriodicTimer;
};
#endif // MopoidGame_ENGINE_H
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -