it's supposed that when you press down one key( W,A,D or S) the esphere has to move to that direction without holding the key..
my code just move one tap at the time...
and another question...
how can i do in order to make other spheres appear at a random place and follow the " head of the snake "
Code: Select all
#include <irrlicht.h>
#include <iostream>
using namespace irr;
#pragma comment(lib, "Irrlicht.lib")
scene::ISceneNode* node = 0;
IrrlichtDevice* device = 0;
bool teclas[256]={false};
class MyEventReceiver : public IEventReceiver{
public:
virtual bool OnEvent(const SEvent& event) {
if (node != 0 && event.EventType == irr::EET_KEY_INPUT_EVENT&& !event.KeyInput.PressedDown){
switch(event.KeyInput.Key)
{
case KEY_KEY_A:
case KEY_KEY_D:
{
core::vector3df v = node->getPosition();
v.X += event.KeyInput.Key == KEY_KEY_A ? 2.0f : -2.0f;
node->setPosition(v);
}
return true;
case KEY_KEY_W:
case KEY_KEY_S:
{
core::vector3df v = node->getPosition();
v.Y += event.KeyInput.Key == KEY_KEY_W ? 2.0f : -2.0f;
node->setPosition(v);
}
return true;
}
}
return false;
}
};
int main()
{ MyEventReceiver receiver;
// create device
IrrlichtDevice* device = createDevice(irr::video::EDT_DIRECT3D9,irr::core::dimension2d<irr::s32>(640,480),32,false,false,false,&receiver);
video::IVideoDriver* driver = device->getVideoDriver();
scene::ISceneManager* smgr = device->getSceneManager();
node = smgr->addSphereSceneNode();
node->setPosition(core::vector3df(0,0,0));
node->setMaterialTexture(0, driver->getTexture("../../media/wall.bmp"));
node->setMaterialFlag(video::EMF_LIGHTING, false);
scene::ICameraSceneNode * cam = smgr->addCameraSceneNode(0,core::vector3df(0,0,200));
int lastFPS = -1;
while(device->run())
{
driver->beginScene(true, true, video::SColor(0,0,100,200));
smgr->drawAll(); // draw the 3d scene
device->getGUIEnvironment()->drawAll(); // draw the gui environment (the logo)
driver->endScene();
int fps = driver->getFPS();
if (lastFPS != fps)
{
core::stringw tmp(L"Movement Example - Irrlicht Engine [");
tmp += driver->getName();
tmp += L"] fps: ";
tmp += fps;
device->setWindowCaption(tmp.c_str());
lastFPS = fps;
}
//node->setPosition(node->getPosition() + core::vector3df(0.01f,0,0) );
}
device->drop();
return 0;
}