Home » Source Code » A 3D RPG Based on Ogre and ODE

A 3D RPG Based on Ogre and ODE

maninwest
2015-02-25 03:32:40
The author
View(s):
Download(s): 0
Point (s): 1 
Category Category:
VC8.0VC8.0 CPlusPlus, C-C++C++

Description

Translated by  maninwest@Codeforge  Author:lxdfigo @ Codeproject
In this article, I introduce a solution of 3D RPG based on Ogre Graphics Engine, ODE Physics Engine, CEGUI, and other tools. The framework is described and the full resource and source code is on https://github.com/lxdfigo/Space-Knight.
Background 
Space Knight is a cartoon I  watched when I was a child and I 'm also a game fan. So I use what I learned before to develop the cartoon to an RPG. Here displaying what lib I used in my game
Ogre: I use Ogre as the Graphics Engine. It can choose DirectX or OpenGL to render the scene.
OED: I use OgreOde which combines the Ogre with the ODE to build the physical world in my game.
CEGUI: It is used to construct the UI in the game such as main menu, trade menu, function menu etc.
3D Max: The models in our game is built by 3D Max and is exported by a  plugin. 
DirectShow and Fmod: They are used to play the video and the audio. 
Using the code
As told before, the application  bases on several libs. Here are the UML figure of my game framework. 


There are several module in the application, There are Mission Module, Role Module, AI Module, UI Module,  Tool Module and Media Module.
The Mission Module controls the mission of the game and it contains the BaseMission class, FirstMissionclass and etc. Each class represents a mission in the game. The base class also control the most modules.
The Role Module controls the players in the game such as the main player, space knight, the monster Lada, the NPC, and etc. These entities are managed by the entity manager and are checked if they have collision in each frame. The part of Role Module is also controlled by the AI Module. 
The AI Module uses state machine to simulate the role's AI. Each role having the AI has its own state class and the class defines its behaviors. It can be easily changed and extended. 
The UI Module using CEGUI to display the UI of the game. It receive the input from the user and post the message to other modules. It uses OIS to receive the keyboard message and the mouse message.  Each menu on the screen is a script file rendered by CEGUI. 
The Tool Module controls the tools, medicines and other objects in the game such as the chest on the road or the  opening door.  Most tools are built by the status from the XML file.  
The Media Module is a simple adapter of Fmod and DirectShow. It play the sound of the battle or the background and the video of the opening play.


The base class of the mission contains a lot of members and functions. It uses the UI module to display the menu, the Media module to play the sound, the Role module to update the entities. It also builds the graphic world and the physical world. It has the function to move to the next mission, load the saved mission or game over. 
The state machine shows it contains three main state the previous state, the current state and the global state. The state has four behavior Enter, Exit, Execute, and OnMessage. If a role receive a message and it give to the state machine it let the current state execute and transfer to the next state. 

// //Here is the Base Mission class //  class BaseMission: public OgreOde::CollisionListener, public OgreOde::StepListener, public OgreOde::TriangleMeshRayListener
{ public:
        ....


    OgreOde::World                       *mWorld;
    OgreOde::Space                       *mSpace;
    OgreOde::StepHandler                 *mStepper;
    OgreOde::TriangleMeshGeometry* terrainTriMeshGeom;


    OgreOde::InfinitePlaneGeometry *mGround; 


    GameFrame *gameFrame;


    Ogre::Root*              mRoot;
    Ogre::Camera*          mCamera;
    Ogre::SceneManager*      mSceneMgr;
    Ogre::RenderWindow*      mWindow;
    CEGUI::System*   mGUISystem;


    FrameListener* mFrameListener;
    BaseMissionListener* mMissionListener;
    GuiListener *mGuiListener;


    Overlay *talkOverlay,*gameOverlay,*blackOverlay,*loadingOverlay,*missionIntruOverlay;


    CEGUI::Window* gameSheet,* opSheet,* quitSheet,
        * gameOverSheet,* loadSheet,* intruduceSheet,
        * useButton,*noUseButton,* currentPackage;


    std::vector animationStates;
    std::vector mModels;
    std::vector mGeoms;
    std::vector nodes;
    std::vector staticThings;
    std::vector monsters;


    Role *mainModel;
    BaseSound *mSound;
    
    SceneNode * _rocket_node_explosion;
    ParticleSystem * _rocketParticles_explosion; public :
    BaseMission(Ogre::RenderWindow* mW, Ogre::Root* mR, Ogre::Camera* mC, 
                 Ogre::SceneManager* mS,CEGUI::System*   mG,GameFrame *); virtual void Render(); virtual void Clean(); virtual void InitObjects(); virtual void createFrameListener(); virtual void NextMission(); virtual void upDate(); virtual void createScene(); virtual void UpdateGUI(void); virtual void initDemoEventWiring(void);


        ...


    Ogre::SceneManager* getSceneManager(void) const { return mSceneMgr; }
    Ogre::RenderWindow* getRenderWindow(void) const { return mWindow; } void resetParticleSystem(Ogre::ParticleSystem *ps, bool enable, const Ogre::Real delay); virtual void GameOver(); void LoadGame(int i);
}; // // Here is part of the state machine of the AI in the game. // template  class StateMachine
{ private:
    entity_type *m_pOwner;
    State *m_pCurrentState;
    State *m_pPreviousState;
    State *m_pGlobalState; public:
    StateMachine(entity_type *owner):m_pOwner(owner),
       m_pCurrentState(NULL),m_pPreviousState(NULL),m_pGlobalState(NULL){} void SetCurrentState(State *s){m_pCurrentState = s;} void SetPreviousState(State *s){m_pPreviousState = s;} void SetGlobalState(State *s){m_pGlobalState = s;}
...
}; template  class State
{ public: virtual bool OnMessage(entity_type *,Telegram &msg) = 0; virtual void Enter(entity_type *) = 0; virtual void Exit(entity_type *) = 0; virtual void Execute(entity_type *) = 0; virtual ~State(){}
};

Operation and Result


The operation of the game:
Move: W, A, S, D
Fire: mouse, Z, C, V
Mission Pass: Y
Menu: F1 
Our game has seven missions which include two boss mission and one transfer mission. Here shows some picture of my game. 


Sponsored links

File list

Tips: You can preview the content of files by clicking file names^_^
Name Size Date
BaseGameEntity.h258.00 B2009-02-21 16:50
CaneState.cpp1.81 kB2009-06-07 22:32
CaneState.h1,004.00 B2009-05-24 15:35
ChestState.cpp630.00 B2009-03-26 15:30
ChestState.h371.00 B2009-03-26 15:27
DaJiaState.cpp5.48 kB2009-06-07 22:32
DaJiaState.h2.03 kB2009-03-02 13:25
DBoyState.cpp2.49 kB2009-03-02 13:08
DBoyState.h1.16 kB2009-02-24 20:25
EntityManager.cpp483.00 B2009-02-21 16:53
EntityManager.h621.00 B2009-02-21 16:14
FeelerState.cpp1.88 kB2009-06-07 22:32
FeelerState.h1.03 kB2009-03-27 12:46
FlyLaDaState.cpp3.06 kB2009-06-07 22:32
FlyLaDaState.h1.29 kB2009-03-02 14:16
LaDaBossState.cpp660.00 B2009-06-07 22:32
LaDaBossState.h455.00 B2009-05-24 15:20
LaDaState.cpp3.46 kB2009-06-07 22:32
LaDaState.h1.47 kB2009-04-18 22:26
MessageDispatcher.cpp1.01 kB2009-05-07 13:37
MessageDispatcher.h554.00 B2009-02-21 16:44
SpaceKnightState.cpp11.92 kB2009-03-24 19:02
SpaceKnightState.h5.63 kB2009-03-24 19:01
SpaceShipState.cpp1.99 kB2009-03-24 18:20
SpaceShipState.h1.13 kB2009-02-27 15:03
State.h336.00 B2009-02-21 16:43
StateMachine.h1.77 kB2009-03-24 17:47
StayLaDaState.cpp660.00 B2009-06-07 22:32
StayLaDaState.h455.00 B2009-03-27 13:09
Telegram.h407.00 B2009-06-07 22:32
WalkWormState.cpp3.71 kB2009-06-07 22:32
WalkWormState.h1.64 kB2009-05-06 10:50
BaseApplication.h6.99 kB2009-04-29 16:43
BaseFrameListener.h8.59 kB2009-03-01 13:44
BaseSound.cpp1.76 kB2010-03-06 11:53
BaseSound.h525.00 B2010-03-06 11:53
OgreCEGUIRenderer.cpp28.00 kB2008-11-04 19:01
OgreCEGUIRenderer.h15.09 kB2008-11-04 19:01
Dialogue_1.xml3.43 kB2009-03-09 20:36
Dialogue_2.xml1.10 kB2009-03-09 20:45
Dialogue_3.xml373.00 B2009-03-09 20:49
Dialogue_4.xml645.00 B2009-03-09 20:53
Dialogue_5.xml500.00 B2009-05-05 17:56
Dialogue_6.xml184.00 B2009-05-05 18:12
Dialogue_7.xml175.00 B2009-05-24 18:13
DirectShow.cpp9.06 kB2009-05-19 10:16
DirectShow.h1.94 kB2009-08-27 19:36
fmod.h41.62 kB2004-07-29 19:09
Fmodvc.lib151.71 kB2004-07-29 19:09
GameFrame.cpp3.09 kB2009-08-01 18:01
GameFrame.h1.40 kB2009-06-11 20:07
Loads.xml549.00 B2009-05-24 16:49
Main.cpp910.00 B2009-03-24 15:41
MainValue.cpp88.00 B2009-03-24 15:24
MainValue.h139.00 B2009-03-24 15:24
media.cfg323.00 B2008-08-28 18:36
BaseMission.cpp29.05 kB2009-08-27 19:58
BaseMission.h5.43 kB2009-06-11 13:26
DBoyListener.cpp6.31 kB2009-06-11 12:36
DBoyListener.h1.93 kB2009-06-11 12:35
Final.cpp6.30 kB2009-06-11 12:57
Final.h1.69 kB2009-06-11 12:47
FirstBossMission.cpp14.32 kB2009-06-14 14:44
FirstBossMission.h2.27 kB2009-05-08 17:53
FirstMission.cpp29.51 kB2009-07-05 11:17
FirstMission.h2.09 kB2009-05-24 16:59
ForthMission.cpp17.16 kB2009-06-14 14:44
ForthMission.h2.36 kB2009-05-08 17:51
GuiListener.cpp10.01 kB2009-03-25 19:10
GuiListener.h2.33 kB2009-03-03 17:59
MainMenu.cpp21.08 kB2009-08-27 18:50
MainMenu.h3.97 kB2009-05-05 10:43
SecondBossMission.cpp26.95 kB2009-06-11 13:26
SecondBossMission.h3.00 kB2009-05-24 15:35
SecondMission.cpp18.64 kB2009-06-14 14:46
SecondMission.h2.42 kB2009-05-08 17:51
SpaceKnightListener.cpp6.96 kB2009-06-11 12:34
SpaceKnightListener.h1.91 kB2009-06-11 12:24
SpaceShipListener.cpp6.16 kB2009-06-11 12:36
SpaceShipListener.h1.94 kB2009-06-11 12:35
ThirdMission.cpp20.12 kB2009-06-14 14:46
ThirdMission.h2.53 kB2009-05-08 17:12
TransitionMission.cpp27.76 kB2009-06-13 14:24
TransitionMission.h2.38 kB2009-05-08 16:43
BenTi.cpp788.00 B2009-03-25 15:33
BenTi.h262.00 B2009-04-18 20:46
Bullets.cpp3.64 kB2009-04-07 17:34
Bullets.h895.00 B2009-04-18 20:42
Cane01.cpp7.09 kB2009-05-24 16:04
Cane01.h1.45 kB2009-05-24 15:35
CollisionTestedObject.cpp802.00 B2009-03-25 20:58
CollisionTestedObject.h907.00 B2009-03-25 20:48
DaJia.cpp9.38 kB2009-04-18 22:42
DaJia.h1.57 kB2009-04-18 20:42
DBoy.cpp8.69 kB2009-06-07 21:31
DBoy.h1.68 kB2009-04-24 14:27
Feeler01.cpp7.14 kB2009-05-06 11:07
Feeler01.h1.47 kB2009-04-18 20:42
FeiMan.cpp794.00 B2009-03-25 15:45
FeiMan.h263.00 B2009-04-18 20:46
FlyLaDa01.cpp7.32 kB2009-05-07 14:02
FlyLaDa01.h1.45 kB2009-04-18 20:42
LaDa01.cpp8.66 kB2009-05-07 13:37
LaDa01.h1.52 kB2009-04-24 13:53
LaDaBoss01.cpp5.73 kB2009-05-24 15:42
LaDaBoss01.h1.29 kB2009-05-24 15:36
LaDaTree01.cpp3.84 kB2009-04-18 21:26
LaDaTree01.h782.00 B2009-04-24 14:29
LuoYaLu.cpp1.52 kB2009-03-25 15:57
LuoYaLu.h402.00 B2009-04-18 20:46
MainSpaceShip.cpp9.05 kB2009-05-07 14:08
MainSpaceShip.h1.51 kB2009-04-24 14:26
MiLi.cpp1.31 kB2009-03-25 16:00
MiLi.h364.00 B2009-04-18 20:46
Model.cpp824.00 B2009-03-25 15:27
Model.h892.00 B2009-04-18 20:42
Role.cpp555.00 B2009-04-18 21:07
Role.h637.00 B2009-03-29 16:28
SpaceKnight.cpp12.49 kB2009-03-25 21:18
SpaceKnight.h2.58 kB2009-05-01 13:56
StayLaDa01.cpp5.60 kB2009-05-07 13:37
StayLaDa01.h1.30 kB2009-04-18 20:42
WalkWorm01.cpp7.51 kB2009-06-07 22:13
WalkWorm01.h1.55 kB2009-05-06 10:50
WaterMesh.cpp10.67 kB2008-11-04 19:01
WaterMesh.h1.94 kB2009-05-29 00:53
YaKi.cpp1.28 kB2009-03-25 16:01
YaKi.h364.00 B2009-04-18 20:46
ogre.cfg460.00 B2009-07-05 11:20
Plugins.cfg378.00 B2009-07-05 11:19
quake3settings.cfg83.00 B2008-08-28 18:36
resource.h432.00 B2008-12-02 21:37
resources.cfg902.00 B2009-05-24 16:46
TransMission01Sales.xml426.00 B2009-04-05 15:43
SpaceKnight.aps20.78 kB2010-03-06 11:50
SpaceKnight.bmp12.05 kB2008-12-02 21:34
SpaceKnight.ico3.19 kB2009-03-18 16:47
SpaceKnight.rc1.54 kB2008-12-02 21:38
Space_Knight.vcproj15.00 kB2009-08-27 18:43
Space_Knight.vcproj.8.00.old14.90 kB2009-08-01 17:27
Space_Knight.vcproj.L-6CDDBB2CB5294.Administrator.user1.39 kB2012-10-18 19:22
Space_Knight.vcproj.Loki's1.40 kB2009-08-04 14:33
Space_Knight.vcproj.Loki-PC.Loki.user1.38 kB2010-03-21 21:45
Space_Knight.vcproj.lxdfigo-PC.lxdfigo.user1.38 kB2010-07-27 11:48
stadfx.h611.00 B2009-08-27 19:38
Chest01.cpp3.65 kB2009-05-05 10:17
Chest01.h880.00 B2009-04-07 16:41
Desk01.cpp1.10 kB2009-04-07 16:09
Desk01.h465.00 B2009-04-07 16:08
Door01.cpp1.21 kB2009-04-07 16:09
Door01.h483.00 B2009-04-07 16:08
StaticThing.cpp1.04 kB2009-04-07 17:14
StaticThing.h942.00 B2009-04-07 16:53
Status.xml86.00 B2009-03-29 16:24
CurrentTasks.xml246.00 B2009-03-03 17:17
Tasks.xml537.00 B2009-03-03 17:48
tinystr.cpp2.54 kB2006-09-19 19:04
tinystr.h8.58 kB2006-09-19 19:04
tinyxml.cpp35.52 kB2008-11-24 22:26
tinyxml.h62.17 kB2006-09-19 19:04
tinyxmlerror.cpp1.77 kB2006-09-19 19:04
tinyxmlparser.cpp35.30 kB2006-09-19 19:04
AllFullMedica.cpp321.00 B2009-03-25 16:25
AllFullMedica.h266.00 B2009-03-25 16:25
AllToolsIntru.xml915.00 B2009-04-05 15:47
AttackUpMedica.cpp434.00 B2009-03-25 16:29
AttackUpMedica.h312.00 B2009-03-25 16:24
BloodMedica.cpp375.00 B2009-03-25 16:29
BloodMedica.h306.00 B2009-03-25 16:25
Crystal.cpp417.00 B2009-03-24 13:52
Crystal.h293.00 B2009-03-24 13:43
CurrentTools.xml472.00 B2009-07-05 17:25
MagicMedica.cpp373.00 B2009-03-25 16:34
MagicMedica.h314.00 B2009-03-25 16:22
RecoveryUpMedica.cpp462.00 B2009-03-25 16:28
RecoveryUpMedica.h315.00 B2009-03-25 16:29
SpeedUpMedica.cpp423.00 B2009-03-25 16:34
SpeedUpMedica.h294.00 B2009-03-25 16:21
Tool.h202.00 B2009-03-24 13:21
ToolFactory.cpp887.00 B2009-03-25 14:19
ToolFactory.h671.00 B2009-03-25 14:16
Space_Knight.sln902.00 B2009-08-27 17:49
Space_Knight.sln.old901.00 B2008-11-21 13:16
UpgradeLog.XML2.20 kB2009-08-27 17:49
...

Comments

(Add your comment, get 0.1 Point)
Minimum:15 words, Maximum:160 words
  • 1
  • Page 1
  • Total 1

A 3D RPG Based on Ogre and ODE (270.28 kB)

Need 1 Point(s)
Your Point (s)

Your Point isn't enough.

Get 22 Point immediately by PayPal

Point will be added to your account automatically after the transaction.

More(Debit card / Credit card / PayPal Credit / Online Banking)

Submit your source codes. Get more Points

LOGIN

Don't have an account? Register now
Need any help?
Mail to: support@codeforge.com

切换到中文版?

CodeForge Chinese Version
CodeForge English Version

Where are you going?

^_^"Oops ...

Sorry!This guy is mysterious, its blog hasn't been opened, try another, please!
OK

Warm tip!

CodeForge to FavoriteFavorite by Ctrl+D