基于Ogre和ODE的3D RPG(译文)
By robot-v1.0
本文链接 https://www.kyfws.com/games/a-3d-rpg-based-on-ogre-and-ode-zh/
版权声明 本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!
- 5 分钟阅读 - 2406 个词 阅读量 0基于Ogre和ODE的3D RPG(译文)
原文地址:https://www.codeproject.com/Articles/479054/A-3D-RPG-Based-on-Ogre-and-ODE
原文作者:lxdfigo
译文由本站 robot-v1.0 翻译
前言
A 3D Game Based on Ogre, ODE, 3D Max, CEGUI and so on
基于Ogre,ODE,3D Max,CEGUI等的3D游戏
介绍(Introduction)
在本文中,我将介绍基于Ogre图形引擎,ODE物理引擎,CEGUI和其他工具的3D RPG解决方案.描述了框架,并且完整的资源和源代码都在上面(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/太空骑士(https://github.com/lxdfigo/Space-Knight) .(.)
背景(Background)
<太空骑士>是我小时候看过的动画片,也是游戏迷.因此,我使用了之前学到的知识,将卡通开发为RPG.在这里,显示我在游戏中使用的lib:(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):我使用Ogre作为图形引擎.它可以选择DirectX或OpenGL渲染场景.(: I use Ogre as the Graphics Engine. It can choose DirectX or OpenGL to render the scene.)
- OED(OED):我使用OgreOde,它将Ogre与ODE相结合,以在游戏中建立物理世界.(: I use OgreOde which combines the Ogre with the ODE to build the physical world in my game.)
- 电子图形用户界面(CEGUI):用于在游戏中构造UI,例如主菜单,交易菜单,功能菜单等.(: It is used to construct the UI in the game such as main menu, trade menu, function menu, etc.)
- 3D Max(3D Max):我们游戏中的模型由3D Max构建,并由插件导出.(: The models in our game is built by 3D Max and is exported by a plugin.)
- DirectShow和Fmod(DirectShow and Fmod):它们用于播放视频和音频.(: They are used to play the video and the audio.)
使用代码(Using the Code)
如前所述,该应用程序基于多个库.这是我的游戏框架的UML图.(As mentioned before, the application bases on several libs. Here is the UML figure of my game framework.)
应用程序中有几个模块.有任务模块,角色模块,AI模块,UI模块,工具模块和媒体模块.(There are several modules 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,) FirstMission
类等.每个类代表游戏中的任务.基类还控制着大多数模块.(class, etc. Each class represents a mission in the game. The base class also controls the most modules.)
角色模块控制游戏中的玩家,例如主要玩家,太空骑士,怪物拉达,NPC等.这些实体由实体管理器管理,并检查每个帧中是否存在碰撞.角色模块的一部分也由AI模块控制.(The Role Module controls the players in the game such as the main player, space knight, the monster Lada, the NPC, 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.)
AI模块使用状态机来模拟角色的AI.具有AI的每个角色都有其自己的状态类,并且该类定义其行为.它可以轻松更改和扩展.(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.)
UI模块使用CEGUI来显示游戏的UI.它接收来自用户的输入,并将消息发布到其他模块.它使用OIS接收键盘消息和鼠标消息.屏幕上的每个菜单都是CEGUI渲染的脚本文件.(The UI Module using CEGUI to display the UI of the game. It receives the input from the user and posts 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.)
工具模块控制游戏中的工具,药品和其他对象,例如道路上的箱子或开门.大多数工具都是根据XML文件中的状态构建的.(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.)
媒体模块是Fmod和DirectShow的简单适配器.它播放战斗声音或背景声音以及开场视频.(The Media Module is a simple adapter of Fmod and DirectShow. It plays the sound of the battle or the background and the video of the opening play.)
任务的基类包含许多成员和职能.它使用UI模块显示菜单,使用Media模块播放声音,使用Role模块更新实体.它还建立了图形世界和物理世界.它具有移动到下一个任务,加载已保存的任务或游戏的功能.(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 states - the previous state, the current state and the global state. The state has four behaviors -) Enter
,(,) Exit
,(,) Execute
和(, and) OnMessage
.如果角色收到一条消息并将其提供给状态机,它将使当前状态执行并转移到下一个状态.(. If a role receives a message and it gives to the state machine, it lets 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<AnimationState *> animationStates;
std::vector<Model *> mModels;
std::vector<OgreOde::Geometry*> mGeoms;
std::vector<SceneNode*> nodes;
std::vector<StaticThing*> staticThings;
std::vector<Role*> 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 entity_type>
class StateMachine
{
private:
entity_type *m_pOwner;
State<entity_type> *m_pCurrentState;
State<entity_type> *m_pPreviousState;
State<entity_type> *m_pGlobalState;
public:
StateMachine(entity_type *owner):m_pOwner(owner),
m_pCurrentState(NULL),m_pPreviousState(NULL),m_pGlobalState(NULL){}
void SetCurrentState(State<entity_type> *s){m_pCurrentState = s;}
void SetPreviousState(State<entity_type> *s){m_pPreviousState = s;}
void SetGlobalState(State<entity_type> *s){m_pGlobalState = s;}
...
};
template <class entity_type>
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(: W, A, S, D)
- 火(Fire):鼠标,Z,C,V(: mouse, Z, C, V)
- 任务通行证(Mission Pass):Y(: Y)
- 菜单(Menu):F1(: F1) 我们的游戏有七个任务,其中包括两个老板任务和一个转移任务.这里显示的是我的游戏的一些图片.(Our game has seven missions which include two boss mission and one transfer mission. Shown here are some pictures of my game.) 游戏的主菜单.(The main menu of the game.)
玩家击败了一个怪物.(The player beat a monster.)
历史(History)
- 18(18)日(th)2013年4月:初始版本(April, 2013: Initial version)
许可
本文以及所有相关的源代码和文件均已获得The Code Project Open License (CPOL)的许可。
C++ VC8.0 Windows DirectX OpenGL 新闻 翻译