-Peter
Code: Select all
#ifndef CTitleScreen_H_
#define CTitleScreen_H_
//Include the CGameState class, since CTitleScreen is being derived from it
#include "CGameState.h"
//This class will control the title screen. It will contain all the resources needed for
//the title screen.
//It inherites the engine pointers from the CGameState class, as well as the Update,
//Render, and OnEvent functions, and redefines them to suit its own needs.
class CTitleScreen : public CGameState
{
public:
//Constuctor sets engine pointers in the ->CGameState<- class
CTitleScreen( IrrlichtDevice* dev, ISceneManager* mgr, IVideoDriver* driv, IGUIEnvironment* guienv );
//Will clean up after title screen is destroyed.
~CTitleScreen();
//Will return true if the device is running, and the driver points to something
bool Update();
//Draws the stuff
void Render();
//Handles the events for the title screen
bool OnEvent( SEvent event );
private:
static ITexture* titleBMP;
};
#endif
Code: Select all
#include "CTitleScreen.h"
ITexture* CTitleScreen::titleBMP = 0;
//Constructor passes the engine pointers to the CGameState class!
CTitleScreen::CTitleScreen( IrrlichtDevice* dev, ISceneManager* mgr, IVideoDriver* driv, IGUIEnvironment* guienv ) : CGameState( dev, mgr, driv, guienv )
{
titleBMP = GS_driver->getTexture( "titleBMP.bmp" );
}
//Cleans up its inherited engine pointers.
CTitleScreen::~CTitleScreen()
{
GS_device = 0;
GS_sceneMgr = 0;
GS_driver = 0;
GS_guiEnv = 0;
}
//Its own update function, if the device is running, and the driver points to
//something, return true, otherwise return false.
bool CTitleScreen::Update()
{
if( GS_device->run() && GS_driver )
{
return true;
}
else
{
return false;
}
}
//Its own render function, draws the stuff.
void CTitleScreen::Render()
{
//Looking for quality, not speed.
GS_driver->setTextureCreationFlag( ETCF_OPTIMIZED_FOR_QUALITY, true );
////////////////BEGIN RENDERING////////////////
GS_driver->beginScene(true, true, SColor(0,100,100,100));
//Displays background.
GS_driver->draw2DImage( titleBMP, position2d<s32>(0,0) );
GS_guiEnv->addButton( rect<s32>( 300, 300, 350, 325 ), 0, 101, L"Quit" );
GS_guiEnv->addButton( rect<s32>( 275, 250, 325, 275 ), 0, 103, L"2 Player" );
GS_guiEnv->drawAll();
GS_sceneMgr->drawAll();
GS_driver->endScene();
}
//Its own OnEvent function, handles the events that occur during the title screen gamestate
bool CTitleScreen::OnEvent( SEvent event )
{
if( event.EventType == EET_KEY_INPUT_EVENT && !event.KeyInput.PressedDown )
{
switch( event.KeyInput.Key )
{
case KEY_ESCAPE:
{
GS_device->closeDevice();
break;
}
}
}
if (event.EventType == EET_GUI_EVENT)
{
s32 id = event.GUIEvent.Caller->getID();
switch(event.GUIEvent.EventType)
{
case EGET_BUTTON_CLICKED:
{
if (id == 101)
{
GS_device->closeDevice();
return true;
}
if( id == 103)
{
//CGame.setToTwoPlayer();
GS_device->closeDevice();
}
}
}
}
return false;
}