Code: Select all
//I AM NEW TO THE GAME PROGRAMMING LANGUAGE I KNOW TURBO C++ BUT I DONT KNOW ANY GAME PROGRAMMING LANGUAGE
//PLZZ LET THE OBJECT BE SYDNEY.MD2 OR ANY BUILT IN OBJECT THAT COMES WITH IRRLICHT GAME ENGINE I DONT HAVE ANY DOWNLOADED OBJECT
//PLZ HELP THE NEW BIES IT WONT BE A TOUGH JOB FOR YOU GUYS I WOULD BE VERY THANKS TO U
//USE OF MASTEVENT RECEIVER CLASS OR YOUR OWN ANY CLASS IS APPRECIATED
//SUGGESTION ARE APPRECIATED
// THANKS A LOT IN ADVANCE
// I AM VERY WEAK IN THIS RECEIVER CLASS PLZZZ HELP OUT
#include <iostream.h>
#include "Irrlicht.h"
using namespace irr;
using namespace core;
using namespace gui;
using namespace video;
using namespace scene;
using namespace io;
#pragma comment(lib,"Irrlicht.lib")
ISceneNode *node = 0;
IrrlichtDevice *device = 0;
// some change required here problem in this class require "W" to move forward and "S" to move backwarnd and "A" to move right and "D" to move left
class MyReceiver:public IEventReceiver
{
public: virtual bool OnEvent(SEvent event)
{
if (node != 0 && event.EventType == irr::EET_KEY_INPUT_EVENT&&
event.KeyInput.PressedDown)
{
switch(event.KeyInput.Key)
{
case KEY_KEY_S:
{
core::vector3df v = node->getPosition();
v.X += event.KeyInput.Key == KEY_KEY_W ? -2.0f : 2.0f;
node->setPosition(v);
}
return true;
case KEY_KEY_W:
{
core::vector3df v = node->getPosition();
v.X += event.KeyInput.Key == KEY_KEY_S ? -2.0f : 2.0f;
node->setPosition(v);
break;
}
return true;
case KEY_KEY_A:
{
//code required here to move LEFT
}
case KEY_KEY_D:
{
//CODE REQUIRED TO MOVE SYDNEY.MD2 RIGHT
}
return false;
}
}
}
};
int main()
{
class MyReceiver receiver;
IrrlichtDevice *device = createDevice(video::EDT_DIRECT3D9,core::dimension2d<s32>(640,480),16,false,false,false,&receiver);
video::IVideoDriver* driver = device->getVideoDriver();
scene::ISceneManager* smgr = device->getSceneManager();
gui::IGUIEnvironment* guienv = device->getGUIEnvironment();
// load map
device->getFileSystem()->addZipFileArchive("../../media/map-20kdm2.pk3");
scene::IAnimatedMesh* mesh = smgr->getMesh("20kdm2.bsp");
ISceneNode *node = 0;
if(mesh)
{
node= smgr->addOctTreeSceneNode(mesh->getMesh(0));
}
if(node)
//I AM NEW TO THE GAME PROGRAMMING LANGUAGE I KNOW TURBO C++ BUT I DONT KNOW ANY GAME PROGRAMMING LANGUAGE
//PLZZ LET THE OBJECT BE SYDNEY.MD2 OR ANY BUILT IN OBJECT THAT COMES WITH IRRLICHT GAME ENGINE I DONT HAVE ANY DOWNLOADED OBJECT
//PLZ HELP THE NEW BIES IT WONT BE A TOUGH JOB FOR YOU GUYS I WOULD BE VERY THANKS TO U
//USE OF MASTEVENT RECEIVER CLASS OR YOUR OWN ANY CLASS IS APPRECIATED
//SUGGESTION ARE APPRECIATED
// THANKS A LOT IN ADVANCE
// I AM VERY WEAK IN THIS RECEIVER CLASS PLZZZ HELP OUT
#include <iostream.h>
#include "Irrlicht.h"
using namespace irr;
using namespace core;
using namespace gui;
using namespace video;
using namespace scene;
using namespace io;
#pragma comment(lib,"Irrlicht.lib")
ISceneNode *node = 0;
IrrlichtDevice *device = 0;
// some change required here problem in this class require "W" to move forward and "S" to move backwarnd and "A" to move right and "D" to move left
class MyReceiver:public IEventReceiver
{
public: virtual bool OnEvent(SEvent event)
{
if (node != 0 && event.EventType == irr::EET_KEY_INPUT_EVENT&&
event.KeyInput.PressedDown)
{
switch(event.KeyInput.Key)
{
case KEY_KEY_S:
{
core::vector3df v = node->getPosition();
v.X += event.KeyInput.Key == KEY_KEY_W ? -2.0f : 2.0f;
node->setPosition(v);
}
return true;
case KEY_KEY_W:
{
core::vector3df v = node->getPosition();
v.X += event.KeyInput.Key == KEY_KEY_S ? -2.0f : 2.0f;
node->setPosition(v);
break;
}
return true;
case KEY_KEY_A:
{
//code required here to move LEFT
}
case KEY_KEY_D:
{
//CODE REQUIRED TO MOVE SYDNEY.MD2 RIGHT
}
return false;
}
}
}
};
int main()
{
class MyReceiver receiver;
IrrlichtDevice *device = createDevice(video::EDT_DIRECT3D9,core::dimension2d<s32>(640,480),16,false,false,false,&receiver);
video::IVideoDriver* driver = device->getVideoDriver();
scene::ISceneManager* smgr = device->getSceneManager();
gui::IGUIEnvironment* guienv = device->getGUIEnvironment();
// load map
device->getFileSystem()->addZipFileArchive("../../media/map-20kdm2.pk3");
scene::IAnimatedMesh* mesh = smgr->getMesh("20kdm2.bsp");
ISceneNode *node = 0;
if(mesh)
{
node= smgr->addOctTreeSceneNode(mesh->getMesh(0));
}
if(node)
{
node->setPosition(core::vector3df(-1300,-144,-1249));
}
//loadobjects
scene::IAnimatedMeshSceneNode* anms = smgr->addAnimatedMeshSceneNode(
smgr->getMesh("../../media/sydney.md2"));
// GOT PROBLEM IN IF LOOP PLZZZZZ HELP
if (anms)
{
anms->setAnimationSpeed(30);
anms->setRotation(core::vector3df(0,180.0f,0));
anms->setMaterialTexture(0, driver->getTexture("../../media/sydney.bmp"));
}
smgr->addCameraSceneNodeFPS(0, 1);
device->getCursorControl()->setVisible(false);
while(device->run())
{
driver->beginScene(true, true, video::SColor(255,90,90,156));
smgr->drawAll();
driver->endScene();
}
return 0;
}
//AT THE LAST AGAIN THANKS FOR ANY HELP GIVERN
{
node->setPosition(core::vector3df(-1300,-144,-1249));
}
//loadobjects
scene::IAnimatedMeshSceneNode* ansmgr>addAnimatedMeshSceneNode(
smgr->getMesh("../../media/sydney.md2"));
// GOT PROBLEM IN IF LOOP PLZZZZZ HELP
if (anms)
{
anms->setAnimationSpeed(30);
anms->setRotation(core::vector3df(0,180.0f,0));
anms->setMaterialTexture(0, driver->getText("../../media/sydney.bmp"));
}
smgr->addCameraSceneNodeFPS(0, 1);
device->getCursorControl()->setVisible(false);
while(device->run())
{
driver->beginScene(true, true, video::SColor(255,90,90,156));
smgr->drawAll();
driver->endScene();
}
return 0;
}
//AT THE LAST AGAIN THANKS FOR ANY HELP GIVERN
plzz explain me some thing about event reciver class i dont understand even after reading 4th tuitorial
what are the following lines for
core::vector3df v = node->getPosition();
v.X += event.KeyInput.Key == KEY_KEY_W ? -2.0f : 2.0f;
plz explain me about that a bit and about this lines especially that 2.0f and v.x
and following lines in main and tell me how to connect and initialize that node
if (anms)
{
anms->setAnimationSpeed(30);
anms->setRotation(core::vector3df(0,180.0f,0));
anms->setMaterialTexture(0, driver->getTexture("../../media/sydney.bmp"));
}
smgr->addCameraSceneNodeFPS(0, 1);
device->getCursorControl()->setVisible(false);
And again in advance thanks a lot for any help granted