Well i'm working on a FPS myself so i implemented a basic continuously shooting system - when the left mouse button is pressed my gun keeps shoting plasma balls , when the right button is pressed the camera zooms giving a sniper view just like in Quake III
btw i'm using the Techdemo code for my base
so here is the code for my OnEvent function
Code: Select all
bool CDemo::OnEvent(SEvent event)
{
if (event.EventType == EET_KEY_INPUT_EVENT &&
event.KeyInput.Key == KEY_ESCAPE &&
event.KeyInput.PressedDown == false)
{
// user wants to quit.
device->closeDevice();
}
else
if ((event.EventType == EET_KEY_INPUT_EVENT &&
event.KeyInput.Key == KEY_SPACE &&
event.KeyInput.PressedDown == false) ||
(event.EventType == EET_MOUSE_INPUT_EVENT &&
event.MouseInput.Event == EMIE_LMOUSE_PRESSED_DOWN))
{
shootPlasma = true;
//This calls the shoot function from the main loop
}
else
if (event.EventType == EET_MOUSE_INPUT_EVENT &&
event.MouseInput.Event == EMIE_LMOUSE_LEFT_UP)
{
shootPlasma = false;
}
else
if (event.EventType == EET_MOUSE_INPUT_EVENT &&
event.MouseInput.Event == EMIE_RMOUSE_PRESSED_DOWN)
{
device->getSceneManager()->getActiveCamera()->setFOV(1.8f);
}
else
if (event.EventType == EET_MOUSE_INPUT_EVENT &&
event.MouseInput.Event == EMIE_RMOUSE_LEFT_UP)
{
device->getSceneManager()->getActiveCamera()->setFOV(0.8f);
}
else
if (device->getSceneManager()->getActiveCamera())
{
device->getSceneManager()->getActiveCamera()->OnEvent(event);
return true;
}
return false;
}
and here is what my Run function looks like
Code: Select all
while(device->run() && driver)
{
if (device->isWindowActive())
{
// load next scene if necessary
u32 now = device->getTimer()->getTime();
if (now - sceneStartTime > timeForThisScene && timeForThisScene!=-1)
switchToNextScene();
if (shootPlasma == true && GetTickCount() - LastTick > 100)
{
shoot();
LastTick = GetTickCount();
}
createParticleImpacts();
// draw everything
driver->beginScene(true, true, backColor);
smgr->drawAll();
guienv->drawAll();
driver->endScene();
// write statistics
swprintf(tmp, 255, L"%s fps:%d polys:%d", driver->getName(),
driver->getFPS(), driver->getPrimitiveCountDrawn());
statusText->setText(tmp);
}
}
device->drop();
}
Hope this will help...
Edit :
Ohh i forgot to mention these new variables , they are declared in the CDemo.h in the private section
bool shootPlasma ;
DWORD LastTick ;