|
||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||
|
Announcements
Chapters
Services
Feature Zones
|
IntroductionAfter reading the article of Michael Birken, one has to admit that it is again proven that there is only one ingredient that makes a good game: the gameplay. Not the looks, not the sound. As a huge fan of the Introversion Software games, which all have a special 'old' look, I thought why not add this simple retro look to this game. Like James Curran stated, Michael Birken's article covers the game from top to bottom, there isn't much light I can shed over this. So, I will focus more on the differences of building a 2D game (which isn't a console) that looks like a console game. BackgroundThe first question I needed to solve was, which technique I would use for the game. DirectX or OpenGL? The second was even more important: Since this is my first project on graphics, would I be able to master the chosen technique and write all the needed code for this on time? After looking for a while on the web, I stumbled upon the following site: IrrLicht. This is a free Graphics Engine that supports both DirectX and OpenGL, which also solved my first question. This engine provides both 2D and 3D modes, which is perfect. I could start in 2D, and move on to 3D without the need to change the engine. One of the largest differences when not using a console is the way we process inputs. A console program is an input-driven program. After analysing the input, we perform the required logic and then redraw the screen. A Windows (non console) program is an event-driven program. This means that I would need to analyse the events and create my own input to drive the game logic. And, because it's a window, I would need to draw the screen myself and keep on updating the screen while waiting for input. Before Using the CodeIf you want to use and compile this code, you also need the IrrLicht SDK, this can be downloaded here. It contains everything you need to start, including an already built DLL and lib. After placing the SDK on your disk, you need to add the location of the include files and the library files to Visual Studio. Open the Options menu under the Tools menu. Select the option Project and Solution and the sub option VC++ directories.
Using the CodeYou are know ready to use and compile this code. I have started from a console project template; this gives the advantage that the console will be used as the output and trace window, which makes it easier to debug the engine. In the main, I create a int _tmain(int argc, _TCHAR* argv[])
{
Game* pTheGame = Game::getInstance();
if(pTheGame)
{
pTheGame->setupGame();
pTheGame->createData();
pTheGame->runGame();
pTheGame->endGame();
}
return 0;
}
The In order to send the KeyPress events to the acts, I could have used a simple callback function, but I like the delegate concept of C#. In C++, this can be done by a Functor. The boost library provides several classes to do this, but I didn't want to use boost (at least not for this article). So, I created my own hardcoded Functor for this job. struct FKeyPressed { virtual ~FKeyPressed() {}; virtual bool operator()(EKEY_CODE) = 0; }; template class KeyPressed : public FKeyPressed { public: typedef bool (ACTOR::*FunctionType)(EKEY_CODE); public: KeyPressed(ACTOR* pActor, FunctionType pFunctor) { m_pActor = pActor; m_pFunctor = pFunctor; } virtual ~KeyPressed() {}; virtual bool operator()(EKEY_CODE keyCode) { return (m_pActor->*m_pFunctor)(keyCode); } protected: ACTOR* m_pActor; FunctionType m_pFunctor; }; The bool OnKeyPressed(EKEY_CODE keyCode);
In the function I have used two types of void Phaser::updateInfo(Info& rInfo) { if(rInfo.Alpha >= 0) { rInfo.Alpha += rInfo.Fade; } if(rInfo.Alpha >= 255) { rInfo.Alpha = 255; rInfo.Fade = - rInfo.Fade; } } When the lifecycle of the void Phaser::endAnimator() { if (m_pVessel) { m_pVessel->hitPhaser(m_iEnergy); } } One of the most difficult parts was to implement the console interface. The enum Mode
{
WaitForCommand,
NavigateWaitForCourse,
NavigateWaitForDistance,
LaunchWaitForEnergy,
LaunchWaitForHit,
LaunchWaitForCourse,
LaunchWaitForCoordinates,
TransferWaitForEnergy,
ComputerWaitForCommand,
WaitForAnimation
};
The Points of InterestFirst, I would like to apologize for using a great library like IrrLicht to just draw a simple console look. But, it is fairly easy to change the characters <E> to a 2D image of the Enterprise. Or, you could go even further and make it full 3D. It should also be easy to change the References
History
|
|||||||||||||||||||||||||||||||||||||||||||||||