Event receiver problem

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
Quantum1982
Posts: 45
Joined: Mon Apr 23, 2012 9:31 am

Event receiver problem

Post by Quantum1982 »

Hi

I am busy making a small maze game, but I am having problems again with the event receiver. I get the following error :
error LNK2001: unresolved external symbol "class MyEventReceiver _cdecl receiver(void)" (receiver@@YA?AVMyEventReceiver@@XZ)

Here is the code :

Code: Select all

 
#include <irrlicht.h>
#include "driverChoice.h"
 
using namespace irr;
 
#ifdef _MSC_VER
#pragma comment(lib, "Irrlicht.lib")
#endif
 
enum
{
        MAZE_X1 = 40,
        MAZE_Y1 = 40,
        XBlocks = 8,
        YBlocks = 8,
        BlockWidth = (480-MAZE_Y1)/XBlocks
};
 
class CMazeItem
{
public:
        CMazeItem(void);
        
 
        bool bLeft, bRight, bUp, bDown;
};
 
CMazeItem::CMazeItem(void)
{
        bLeft = false;
        bRight = false;
        bUp = false;
        bDown = false;
}
 
class CMaze
{
public:
        CMaze(void);
        CMazeItem TheMaze[XBlocks][YBlocks];
        void GenerateMaze(void);
        void DrawMaze(video::IVideoDriver* driver,irr::video::SColor color = irr::video::SColor(255,255,255,255));
};
 
CMaze::CMaze(void)
{
 
}
void CMaze::GenerateMaze(void)
{
        int iDir;
        srand(5);
        for (int i=0;i<XBlocks;i++)
                for (int j=0;j<YBlocks;j++)
                {
                        iDir = rand()%4;
                        if (iDir==0)
                        {
                                TheMaze[i][j].bLeft=true;
                                if (i>0) TheMaze[i-1][j].bRight=true;
                        }
                        else if (iDir==1)
                        {
                                TheMaze[i][j].bRight=true;
                                if (i<XBlocks-1) TheMaze[i+1][j].bLeft=true;
                        }
                        else if (iDir==2)
                        {
                                TheMaze[i][j].bUp=true;
                                if (j>0) TheMaze[i][j-1].bDown=true;
                        }
                        else if (iDir==3)
                        {
                                TheMaze[i][j].bDown=true;
                                if (j<YBlocks-1) TheMaze[i][j+1].bRight=true;
                        }
 
                }
}
void CMaze::DrawMaze(video::IVideoDriver* driver,irr::video::SColor color)
{
        /*
        for (int i=0;i<XBlocks;i++)
                driver->draw2DLine(irr::core::vector2d<irr::s32>(i*BlockWidth,0),
                                                   irr::core::vector2d<irr::s32>(i*BlockWidth,YBlocks*BlockWidth),
                                                   irr::video::SColor(255,255,255,0));
 
        for (int j=0;j<YBlocks;j++)
                driver->draw2DLine(irr::core::vector2d<irr::s32>(0,j*BlockWidth),
                                                   irr::core::vector2d<irr::s32>(XBlocks*BlockWidth,j*BlockWidth),
                                                   irr::video::SColor(255,255,255,0));
        */
        for (int i=0;i<XBlocks;i++)
                for (int j=0;j<YBlocks;j++)
                {
                        
                        if (TheMaze[i][j].bLeft==true)
                                driver->draw2DLine(irr::core::vector2d<irr::s32>(MAZE_X1+i*BlockWidth,MAZE_Y1+j*BlockWidth),
                                                                   irr::core::vector2d<irr::s32>(MAZE_X1+i*BlockWidth,MAZE_Y1+j*BlockWidth+BlockWidth),
                                                                   irr::video::SColor(255,255,0,255));
                        if (TheMaze[i][j].bRight==true)
                                driver->draw2DLine(irr::core::vector2d<irr::s32>(MAZE_X1+i*BlockWidth+BlockWidth,MAZE_Y1+j*BlockWidth),
                                                                   irr::core::vector2d<irr::s32>(MAZE_X1+i*BlockWidth+BlockWidth,MAZE_Y1+j*BlockWidth+BlockWidth),
                                                                   irr::video::SColor(255,255,0,255));
                        if (TheMaze[i][j].bUp==true)
                                driver->draw2DLine(irr::core::vector2d<irr::s32>(MAZE_X1+i*BlockWidth,MAZE_Y1+j*BlockWidth),
                                                                   irr::core::vector2d<irr::s32>(MAZE_X1+i*BlockWidth+BlockWidth,MAZE_Y1+j*BlockWidth),
                                                                   irr::video::SColor(255,255,0,255));
                        if (TheMaze[i][j].bDown==true)
                                driver->draw2DLine(irr::core::vector2d<irr::s32>(MAZE_X1+i*BlockWidth,MAZE_Y1+j*BlockWidth+BlockWidth),
                                                                   irr::core::vector2d<irr::s32>(MAZE_X1+i*BlockWidth+BlockWidth,MAZE_Y1+j*BlockWidth+BlockWidth),
                                                                   irr::video::SColor(255,255,0,255));
                } // for j
}
class CHuman
{
public:
        CHuman(void);
        int iX, iY;
 
        void Draw(video::IVideoDriver* driver,irr::video::SColor color = irr::video::SColor(255,255,255,255));
        
        void Update(CMaze& Maze,SEvent& event);
};
 
CHuman::CHuman(void)
{
        iX = 5;
        iY = 5;
}
void CHuman::Draw(video::IVideoDriver* driver,irr::video::SColor color)
{
        driver->draw2DRectangle(color,irr::core::rect<irr::s32>(MAZE_X1+iX*BlockWidth+2,MAZE_Y1+iY*BlockWidth+2,
                MAZE_X1+(iX+1)*BlockWidth-2,MAZE_Y1+(iY+1)*BlockWidth-2));
}
void CHuman::Update(CMaze& Maze,SEvent& event)
{
        if ((event.EventType==irr::KEY_LEFT)&&(iX>0)&&(Maze.TheMaze[iX][iY].bLeft==false))
                iX--;
        else if ((event.EventType==irr::KEY_RIGHT)&&(iX<XBlocks-1)&&(Maze.TheMaze[iX][iY].bRight==false))
                iX++;
        else if ((event.EventType==irr::KEY_UP)&&(iY>0)&&(Maze.TheMaze[iX][iY].bUp==false))
                iY--;
        else if ((event.EventType==irr::KEY_DOWN)&&(iY<YBlocks-1)&&(Maze.TheMaze[iX][iY].bDown==false))
                iY++;
}
class CAlien
{
public:
        CAlien(void);
        int iX, iY;
 
        void Update(CMaze& Maze,int iHumanX,int iHumanY);
        void Draw(video::IVideoDriver* driver,irr::video::SColor color = irr::video::SColor(255,255,255,255));
        
};
CAlien::CAlien(void)
{
        iX = 0;
        iY = 0;
}
void Update(CMaze& Maze,int iHumanX,int iHumanY)
{
 
}
void CAlien::Draw(video::IVideoDriver* driver,irr::video::SColor color)
{
        driver->draw2DRectangle(color,irr::core::rect<irr::s32>(MAZE_X1+iX*BlockWidth+2,MAZE_Y1+iY*BlockWidth+2,
                MAZE_X1+(iX+1)*BlockWidth-2,MAZE_Y1+(iY+1)*BlockWidth-2));
}
 
CMaze Maze; // global maze
CHuman Human; // global player
CAlien Alien; // global alien
 
class MyEventReceiver : public IEventReceiver
{
public:
 
        MyEventReceiver()               
        {
                ;
        }
 
        virtual bool OnEvent(const SEvent& event)
        {
                // check if user presses the key 'W' or 'D'
                if (event.EventType == irr::EET_KEY_INPUT_EVENT && !event.KeyInput.PressedDown)
                {
                        switch (event.KeyInput.Key)
                        {
                        
                        case irr::KEY_LEFT || irr::KEY_RIGHT || irr::KEY_UP || irr::KEY_DOWN :
                                Human.Update(Maze,irr::SEvent(event));
 
                        default: ;
                                break;
                        }
                }
 
                return false;
        }
};
 
 
/*
The start of the main function starts like in most other example. We ask the
user for the desired renderer and start it up. This time with the advanced
parameter handling.
*/
int main()
{
        // ask user for driver
        video::E_DRIVER_TYPE driverType=driverChoiceConsole();
        if (driverType==video::EDT_COUNT)
                return 1;
 
        // create device with full flexibility over creation parameters
        // you can add more parameters if desired, check irr::SIrrlichtCreationParameters
        
        //IrrlichtDevice* device = createDeviceEx(params);
        
        
        // disable mouse cursor
        //device->getCursorControl()->setVisible(false);
 
        // create event receiver
        MyEventReceiver receiver();
 
        IrrlichtDevice* device = createDevice(driverType,
                        core::dimension2d<u32>(640, 480), 16, true, false, false, (irr::IEventReceiver*)&receiver);
        //device->setEventReceiver((irr::IEventReceiver*)receiver);
 
 
        if (device == 0)
                return 1; // could not create selected driver.
 
        video::IVideoDriver* driver = device->getVideoDriver();
        scene::ISceneManager* smgr = device->getSceneManager();
        gui::IGUIEnvironment* env = device->getGUIEnvironment();
 
        Maze.GenerateMaze();
 
        
        int lastFPS = -1;
 
        while(device->run())
        if (device->isWindowActive())
        {
                driver->beginScene(true, true, 0 );
 
                //smgr->drawAll();
            //env->drawAll();
 
                Maze.DrawMaze(driver);
                Human.Draw(driver,irr::video::SColor(255,255,0,255));
                Alien.Draw(driver,irr::video::SColor(255,255,255,0));
 
                driver->endScene();
        }
 
        device->drop();
        
        return 0;
}
 
/*
Now you know how to use terrain in Irrlicht.
**/
 
 
 
Any help would be appreciated, thanks
DJLinux
Posts: 19
Joined: Fri Dec 02, 2011 4:39 am
Location: germany
Contact:

Re: Event receiver problem

Post by DJLinux »

this is wrong:
event.EventType==irr::KEY_LEFT

should be:

Code: Select all

if (event.eventType == EET_KEY_INPUT_EVENT) {
  if (event.SKeyInput.Key == KEY_LEFT){
    ...
  }
  ...
}
or use a switch statement for the different keys

DJ.
(Sorry about my bad English)
Quantum1982
Posts: 45
Joined: Mon Apr 23, 2012 9:31 am

Re: Event receiver problem

Post by Quantum1982 »

Ok thanks for the reply, but I still get that error even after making that change.
Quantum1982
Posts: 45
Joined: Mon Apr 23, 2012 9:31 am

Re: Event receiver problem

Post by Quantum1982 »

Ok wait now it works all of a sudden, but the blocks don't move when I press the arrow keys ?
Quantum1982
Posts: 45
Joined: Mon Apr 23, 2012 9:31 am

Re: Event receiver problem

Post by Quantum1982 »

In the mean time I am using the mouse to move the block around until I figure out why it's not accepting keys.
CuteAlien
Admin
Posts: 9933
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Event receiver problem

Post by CuteAlien »

That line does not do what you think it does:

Code: Select all

 
// this is probably identical to case irr::KEY_LEFT:
case irr::KEY_LEFT || irr::KEY_RIGHT || irr::KEY_UP || irr::KEY_DOWN :
 
If you want to simulate OR you have to work with case-switches which have a fallthrough (no break).
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Post Reply