if you have characters in your game, and a player. Hence lets trow in some animals to just wandering around.
Then you can have something like:
Code: Select all
class Actor{}; // maybe descending from ISceneNode
class Character : public Actor{};
class Player : public Character{};
class Animal : public Actor{};
class Bird: public Animal{};
class Cow: public Animal{};
Pretty recognizable I guess.
Code: Select all
class Level
{
// base class
}
class GameLevel : public Level
{
private:
int initCharacters();
int initCharacters( file );
int initAnimals();
public:
int initialize(){ initCharacters(); initAnimals(); }
int load( file ){ /* or get it out of a file */ initCharacters( "cruelties.txt" ); }
}
Code: Select all
// cruelties.txt
[char]
mesh:char1.ms3d
tex:ohlala.png
pos:0,0,0
[char]
idem
// animalfile.txt
etc
Actually it doesn't matter how you do it as long as you understand what is done where. In my practise I have set up a basic framework in a static lib for tests and starting point for a new project. Then descent from Level to TestLevel which contains a function that is called from the mainloop. The descended class I set as a pointer in the 'mainloop'-class.
Code: Select all
int main()
{
IrrlichtClass engine;
TestLevel level;
engine.setLevel( level );
if( !engine.run() )
return 1;
return 0;
}
This is my base class, a pretty simple thing:
Code: Select all
class Level
: public IEventReceiver
{
friend class cScript;
private:
video::SColor m_backgroundColour = video::SColor( 255, 4, 6, 12 );
public:
virtual bool create();
virtual void destroy();
virtual bool load();
virtual bool save();
virtual void update( const f32& deltaTime );
video::SColor getBackgroundColour();
void setBackgroundColour( video::SColor color );
/// I E v e n t R e c e i v e r
/// --------------------------------------------------------------------------------
virtual bool OnEvent( const SEvent& event );
};
Also to note: Within that IrrlichtClass, is the mainloop called run()
Code: Select all
bool IrrlichtClass::run()
{
if( !m_level ) return false;
m_level->initialize();
while( m_device->run() )
{
...
level->update( deltatime );
...
}
}
The level gets called withing the .run(), giving you the abillity to create a progress bar or other nice scenery while initializing.
Code: Select all
void GameLevel::keepItReadableCleanAndNotRepetitive()
{
m_videodriver ->beginScene( true, true, m_backgroundColour );
m_sceneManager ->drawAll();
m_videodriver ->endScene();
}
int GameLevel::initialize()
{
core::array<core::stringc> files;
files.push_back( "player.txt" );
files.push_back( "npc.txt" );
files.push_back( "animal.txt" );
m_progressBarThingy = m_sceneManager->addProgressBarThingy( or something );
m_progressBarThingy->max = 3;
for(u32 i = 0; i < files.size();++i)
{
createCharacter( files[i] );
m_progressBarThingy.value++;
keepItReadableCleanAndNotRepetitive();
}
core::array<core::stringc> buildings;
buildings.push_back( "house.ms3d" );
buildings.push_back( "house.png" );
buildings.push_back( "woodcutter.ms3d" );
buildings.push_back( "woodcutter.png" );
for(u32 i = 0; i < buildings.size(); i += 2)
{
scene::ISceneNode* node;
scene::SMesh* mesh;
mesh = m_sceneManager->getMesh( buildings[i] );
node = m_sceneManager->addMeshSceneNode( mesh );
node->setMaterialType(0, buildings[i+1]);
keepItReadableCleanAndNotRepetitive();
}
initAnimals();
// done so we return to start the actual loop
// don't forget to clean up m_progressBarThingy and other thing you've created here or they keep sticking around
}
int GameLevel::initAnimals()
{
// when loaded, draw them onto the screen and load the next
m_sceneManager->addMeshSceneNode( m_sceneManager->getMesh( "cow.ms3d" ) );
keepItReadableCleanAndNotRepetitive();
m_sceneManager->addMeshSceneNode( m_sceneManager->getMesh( "dear.ms3d" ) );
keepItReadableCleanAndNotRepetitive();
}
hope this helps